- job:
    name: zephyr-upstream-arm
    project-type: matrix
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
                - job-workspace
            everyone-flat:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 30
            artifact-num-to-keep: 30
        - throttle:
            option: category
            categories: [lite-zephyr]
            matrix-builds: false
            matrix-configs: true
    parameters:
        - string:
            name: BRANCH
            default: 'arm'
        - string:
            name: LAVA_SERVER
            default: 'validation.linaro.org/RPC2/'
        - string:
            name: QA_SERVER
            default: 'https://qa-reports.linaro.org'
        - string:
            name: GIT_COMMIT
            default: 'master'
    disabled: true
    node: master
    child-workspace: .
    display-name: 'DELETE ME'
    axes:
        - axis:
            type: slave
            name: label
            values:
                - docker-xenial-amd64-13
        - axis:
            type: user-defined
            name: ZEPHYR_TOOLCHAIN_VARIANT
            values:
                - gnuarmemb
                - zephyr
        - axis:
            type: user-defined
            name: PLATFORM
            values:
                # - 96b_carbon
                # - 96b_nitrogen
                # - arduino_101
                # - arduino_101_ble
                # - arduino_due
                # - bbc_microbit
                # - cc3200_launchxl
                - cc3220sf_launchxl
                - disco_l475_iot1
                - frdm_k64f
                - frdm_kw41z
                # - hexiwear_k64
                # - mps2_an385
                # - nrf51_blenano
                # - nrf51_pca10028
                # - nrf52_pca10040
                - nucleo_f103rb
                - nucleo_f401re
                # - nucleo_l476rg
                # - olimexino_stm32
                - qemu_cortex_m3
                # - qemu_x86
                # - quark_se_c1000_ble
                # - stm32_mini_a15
                # - v2m_beetle
    execution-strategy:
        combination-filter: |
             ZEPHYR_TOOLCHAIN_VARIANT=="zephyr" || (ZEPHYR_TOOLCHAIN_VARIANT=="gnuarmemb" && !(PLATFORM=="arduino_101" || PLATFORM=="qemu_x86"))
    wrappers:
        - timestamps
        - credentials-binding:
            - text:
                credential-id: LAVA_USER
                variable: LAVA_USER
        - credentials-binding:
            - text:
                credential-id: LAVA_TOKEN
                variable: LAVA_TOKEN
        - credentials-binding:
            - text:
                credential-id: QA_REPORTS_TOKEN
                variable: QA_REPORTS_TOKEN
    builders:
        - shell:
            !include-raw: zephyr-upstream/builders.sh
        - inject:
            properties-file: env_var_parameters
        - build-name-setter:
            template: '#${BUILD_NUMBER}-${GIT_COMMIT}'
            macro: true
        - linaro-publish-token
        - shell: |
            #!/bin/bash

            # 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/${PLATFORM} components/kernel/zephyr/${BRANCH}/${ZEPHYR_TOOLCHAIN_VARIANT}/${PLATFORM}/${BUILD_NUMBER}

        - shell: |
            #!/bin/bash -ex

            case "${PLATFORM}" in
              frdm_k64f)
                export DEVICE_TYPE=frdm-k64f
                ;;
              frdm_kw41z)
                export DEVICE_TYPE=frdm-kw41z
                ;;
              disco_l475_iot1)
                export DEVICE_TYPE=disco-l475-iot1
                ;;
              qemu_cortex_m3)
                export DEVICE_TYPE=qemu
                ;;
              *)
                echo "Skip DEVICE_TYPE for ${PLATFORM}"
                ;;
            esac

            rm -rf configs
            git clone --depth 1 http://git.linaro.org/ci/job/configs.git

            [ "${GIT_COMMIT}" = "master" ] && unset DEVICE_TYPE
            [ -z "${DEVICE_TYPE}" ] || \
            python configs/zephyr-upstream/submit_for_testing.py \
                --board-name ${PLATFORM} \
                --device-type ${DEVICE_TYPE} \
                --build-number ${BUILD_NUMBER} \
                --build-url ${BUILD_URL} \
                --branch-name ${BRANCH} \
                --lava-server ${LAVA_SERVER} \
                --qa-server ${QA_SERVER} \
                --qa-server-team lite \
                --qa-server-project zephyr-upstream-arm \
                --gcc-variant ${ZEPHYR_TOOLCHAIN_VARIANT} \
                --git-commit ${GIT_COMMIT}

    publishers:
        - archive:
            artifacts: 'scripts/sanity_chk/last_sanity.csv'
        - email:
            recipients: 'fathi.boudra@linaro.org kumar.gala@linaro.org gpitney@ti.com vincent.wan@linaro.org'
