- job:
    name: optee-build
    project-type: matrix
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
                - job-workspace
            op-tee:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
                - job-configure
            everyone-flat:
                - job-build
        - build-discarder:
            days-to-keep: 90
            num-to-keep: 90
    parameters:
        - string:
            name: PUB_DEST
            default: 'components/optee/build/${repo_proj}/${BUILD_NUMBER}'
        - string:
            name: LAVA_SERVER
            default: 'validation.linaro.org/RPC2/'
        - matrix-combinations:
            name: MATRIX_COMBINATIONS
    disabled: false
    node: master
    child-workspace: .
    display-name: 'OP-TEE Makefiles for various platforms'
    axes:
        - axis:
            type: slave
            name: label
            values:
                - docker-xenial-amd64
        - axis:
            type: user-defined
            name: repo_proj
            values:
                - default
                - fvp
                - hikey
                - juno
                - mt8173-evb
                - qemu_v8
                - rpi3
    scm:
        - git:
            url: https://github.com/OP-TEE/build.git
            refspec: +refs/heads/master:refs/remotes/origin/master
            name: origin
            branches:
                - refs/heads/master
            skip-tag: true
            shallow-clone: true
            wipe-workspace: false
    wrappers:
        - timestamps
        - build-name:
            name: '#${BUILD_NUMBER}-${GIT_REVISION,length=8}'
    builders:
        - shell:
            !include-raw: optee/build/builders.sh
        - linaro-publish-token
        - conditional-step:
            condition-kind: strings-match
            condition-string1: '${ENV,var="repo_proj"}'
            condition-string2: 'juno'
            steps:
                - shell:
                    !include-raw: optee/build/publishers.sh
                - shell:  |
                    #!/bin/bash

                    set -e

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

                    DEVICE_TYPE=juno

                    sed -e "s|\${BUILD_NUMBER}|${BUILD_NUMBER}|" \
                        -e "s|\${BUILD_URL}|${BUILD_URL}|" \
                        -e "s|\${GIT_BRANCH}|${GIT_BRANCH}|" \
                        -e "s|\${GIT_COMMIT}|${GIT_COMMIT}|" \
                        -e "s|\${GIT_URL}|${GIT_URL}|" \
                        -e "s|\${PUBLISH_SERVER}|${PUBLISH_SERVER}|" \
                        -e "s|\${PUB_DEST}|${PUB_DEST}|" \
                        < configs/optee/build/lava-job-definitions/${DEVICE_TYPE}/template-optee-xtest.yaml \
                        > custom_lava_job_definition.yaml

                    cat << EOF > post_build_lava_parameters
                    DEVICE_TYPE=${DEVICE_TYPE}
                    CUSTOM_YAML_URL=${JOB_URL}/ws/custom_lava_job_definition.yaml
                    LAVA_SERVER=${LAVA_SERVER}
                    EOF
                - trigger-builds:
                    - project: 'post-build-lava'
                      property-file: post_build_lava_parameters
                      block: true
