- job:
    name: openembedded-armv8-pre-built-images-lt-vexpress64
    project-type: freestyle
    defaults: global
    logrotate:
        daysToKeep: 30
        numToKeep: 30
        artifactNumToKeep: 1
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
                - job-workspace
    parameters:
        - password:
            name: LAVA_USER
            default: ${LAVA_USER}
        - password:
            name: LAVA_TOKEN
            default: ${LAVA_TOKEN}
        - string:
            name: hwpack
            default: 'lt-vexpress64'
        - string:
            name: gcc_version
            default: '5.2'
    disabled: true
    node: docker-stretch-amd64
    child-workspace: .
    display-name: 'DELETE ME'
    wrappers:
        - timestamps
    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

            export BOOTLOADER="uefi"
            DELETEDIR=1 ./daily-prebuilt-images/build-images -w ${hwpack} -b minimal-armv8-gcc-${gcc_version} -p openembedded -f
            REUSE=1 ./daily-prebuilt-images/build-images -w ${hwpack} -b lamp-armv8-gcc-${gcc_version} -p openembedded -f

            export HWPACK_JOB_NAME=${JOB_NAME}
            export BUNDLE_STREAM_NAME="/private/team/wg/wg-private/"

            export HWPACK_FILE_NAME=`find out/pre-built -type f -name "*_minimal-armv8-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

            cat << EOF > ${WORKSPACE}/deploy_image_parameters.json
            {
                "bootloadertype": "uefi"
            }
            EOF

            cat << EOF > ${WORKSPACE}/metadata.json
            {
              "hwpack.type": "${hwpack}"
            }
            EOF
        - shell: |
            #!/bin/bash

            set -ex

            export DEVICE_TYPE=juno

            export ROOTFS_TYPE=lamp-armv8-gcc-${gcc_version}
            export HWPACK_FILE_NAME=`find out/pre-built -type f -name "*_lamp-armv8-gcc-${gcc_version}_*.img.gz" |xargs basename`

            cat << EOF > ${WORKSPACE}/post_build_lava_parameters
            DEVICE_TYPE=${DEVICE_TYPE}
            BUNDLE_STREAM_NAME=${BUNDLE_STREAM_NAME}
            HWPACK_JOB_NAME=${HWPACK_JOB_NAME}
            HWPACK_FILE_NAME=${HWPACK_FILE_NAME}
            HWPACK_BUILD_NUMBER=${HWPACK_BUILD_NUMBER}
            LAVA_TEST_PLAN='busybox device-tree ethernet kernel-version ltp pwrmgmt toolchain libhugetlbfs pointer-tagging-tests'
            IMAGE_URL=http://snapshots.linaro.org/openembedded/pre-built/${hwpack}/${HWPACK_BUILD_NUMBER}/${HWPACK_FILE_NAME}
            METADATA_URL=${JOB_URL}/ws/metadata.json
            EOF
        - trigger-builds:
            - project: 'post-build-lava'
              property-file: post_build_lava_parameters
              block: true
    publishers:
        - archive:
            artifacts: '*.json'
        - email:
            recipients: 'fathi.boudra@linaro.org riku.voipio@linaro.org'

