- job:
    name: openembedded-armv7a-pre-built-images
    project-type: matrix
    defaults: global
    logrotate:
        daysToKeep: 30
        numToKeep: 30
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
    parameters:
        - password:
            name: LAVA_USER
            default: ${LAVA_USER}
        - password:
            name: LAVA_TOKEN
            default: ${LAVA_TOKEN}
        - string:
            name: gcc_version
            default: '5.2'
    disabled: true
    node: master
    child-workspace: .
    display-name: 'DELETE ME'
    axes:
        - axis:
            type: user-defined
            name: hwpack
            values:
                - lsk-vexpress
        - axis:
            type: slave
            name: label
            values:
                - docker-stretch-amd64
    execution-strategy:
        sequential: true
        touchstone:
            expr: 'hwpack=="lsk-vexpress"'
    wrappers:
        - timestamps
        - matrix-tie-parent:
            node: master
    builders:
        - linaro-publish-token
        - shell: |
            #!/bin/bash

            set -ex

            sudo apt-get update
            sudo apt-get install -y bzr

            rm -rf daily-prebuilt-images
            git clone git://git.linaro.org/ci/daily-prebuilt-images.git

            case "${hwpack}" in
              beaglebone)
                DELETEDIR=1 ./daily-prebuilt-images/build-images -w ${hwpack} -pw ubuntu -p openembedded -b alip-armv7a-gcc-${gcc_version}
                ;;
              lsk-vexpress)
                DELETEDIR=1 ./daily-prebuilt-images/build-images -w ${hwpack} -pw ubuntu -p openembedded -b alip-armv7a-gcc-${gcc_version}
                ;;
              panda)
                DELETEDIR=1 ./daily-prebuilt-images/build-images -w ${hwpack} -pw ubuntu -p openembedded -b alip-armv7a-gcc-${gcc_version}
                ;;
            esac

            export HWPACK_JOB_NAME=${JOB_NAME}

            export HWPACK_FILE_NAME=`find out/pre-built -type f -name "${hwpack}*_alip-armv7a-gcc-${gcc_version}_*.img.gz" |xargs basename`
            export HWPACK_BUILD_NUMBER=`echo ${HWPACK_FILE_NAME} |cut -d'_' -f3 |cut -d'-' -f2`
            export HWPACK_BUILD_NUMBER=${HWPACK_BUILD_NUMBER%%.img.gz}

            # Add md5sums for all build artefacts that don't have one yet.
            for f in $(find ${WORKSPACE}/out | grep -v md5) ; do
                if [ -f "$f" ] ; then
                    md5sum $f | awk -F/ '{print $1 $NF}' > ${f}.md5
                fi
            done

            # Publish
            test -d ${HOME}/bin || mkdir ${HOME}/bin
            wget -q https://git.linaro.org/ci/publishing-api.git/blob_plain/HEAD:/linaro-cp.py -O ${HOME}/bin/linaro-cp.py
            time python3 ${HOME}/bin/linaro-cp.py \
              --api_version 3 \
              --link-latest \
              out/pre-built/${hwpack}/${HWPACK_BUILD_NUMBER} openembedded/pre-built/${hwpack}/${HWPACK_BUILD_NUMBER}

            cat << EOF > env_var_parameters
            BUNDLE_STREAM_NAME=${BUNDLE_STREAM_NAME}
            HWPACK_JOB_NAME=${HWPACK_JOB_NAME}
            HWPACK_BUILD_NUMBER=${HWPACK_BUILD_NUMBER}
            EOF
        - inject:
            properties-file: env_var_parameters
        - shell: |
            #!/bin/bash

            set -ex

            case "${hwpack}" in
              beaglebone)
                export DEVICE_TYPE=beaglebone-black
                ;;
              lsk-vexpress)
                export DEVICE_TYPE=vexpress-a9
                export BUNDLE_STREAM_NAME="/public/team/linaro/pre-built-lsk-vexpress/"
                ;;
              panda)
                export DEVICE_TYPE=panda-es
                ;;
            esac

            export ROOTFS_TYPE=alip-armv7a-gcc-${gcc_version}
            export HWPACK_FILE_NAME=`find out/pre-built -type f -name "${hwpack}*_alip-armv7a-gcc-${gcc_version}_*.img.gz" |xargs basename`
            python daily-prebuilt-images/lava-submit.py
    publishers:
        - email-ext:
            recipients: 'fathi.boudra@linaro.org'
            attach-build-log: true
            matrix-trigger: both

