- job:
    name: u-boot-upstream
    project-type: freestyle
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-read
                - job-extended-read
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 30
    disabled: true
    node: docker-xenial-amd64
    display-name: 'DELETE ME'
    scm:
        - git:
            url: git://git.denx.de/u-boot.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:
        - linaro-publish-token
        - shell: |
            #!/bin/bash

            env |grep GIT

            set -ex

            trap cleanup_exit INT TERM EXIT

            cleanup_exit()
            {
              cd ${WORKSPACE}
              rm -rf build out
              git clean -fdx
              git reset --hard
            }

            sudo apt-get update
            sudo apt-get install -y libssl-dev python-requests rsync \
                swig libpython-dev

            cat > buildman.conf << EOF
            [toolchain]
            arm: ${HOME}/srv/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin
            aarch64: ${HOME}/srv/toolchain/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin
            x86_64: /usr/bin
            EOF

            git config --global user.email "ci_notify@linaro.org"
            git config --global user.name "Linaro CI"
            git checkout -b u-boot-ci origin/master
            git add buildman.conf
            git commit -m "dummy commit"

            set +e
            ./tools/buildman/buildman --config-file=buildman.conf --list-tool-chains
            ./tools/buildman/buildman \
              --config-file=buildman.conf \
              --keep-outputs \
              --output-dir=build \
              --branch=origin/master..u-boot-ci \
              --step=1 \
              'armv7|armv8|x86' \
              --show-sizes \
              --force-reconfig \
              --detail \
              --verbose \
              --show_errors \
              --list-error-boards
            set -e

            # Publish
            mv $(find build -type d -name vexpress_aemv8a_juno | xargs dirname)/* build/
            rm -rf build/origin_master_u-boot-ci
            find build -type f -name '.config' -exec rename 's/.config/u-boot.config/' {} +
            rsync -avm \
              --include=u-boot \
              --include=u-boot-spl \
              --include=u-boot.img \
              --include=u-boot.rom \
              --include=u-boot.config \
              --include=MLO \
              --include='*/' \
              --exclude='*' \
              build/ out/

            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 components/kernel/u-boot/${BUILD_NUMBER}
    publishers:
        - email:
            recipients: 'fathi.boudra@linaro.org'
