- job:
    name: tcwg-make-gcc-release-tag
    project-type: freestyle
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 10
            num-to-keep: 10
    parameters:
        - choice:
            name: tag_kind
            choices:
                - snapshot
                - candidate
                - release
            description: 'Type of release to do.'
        - string:
            name: spin
            default: ''
            description: 'Spin number'
        - string:
            name: gcc_ref
            default: ''
            description: 'GCC tag or branch name (like linaro-6.3-2017.03, linaro/gcc-6-branch)'
        - string:
            name: date
            default: ''
            description: 'Snapshot or Release date (YYYY.MM)'
    disabled: true
    node: tcwg-x86_64-dev-01-short
    retry-count: 3
    concurrent: true
    display-name: 'TCWG Tag GCC Sources'
    scm:
        - git:
            url: https://git.linaro.org/toolchain/gcc.git
            refspec: +refs/heads/*:refs/remotes/origin/*
            branches:
                - refs/heads/master
            basedir: gcc_src
            scm-name: GCC
            per-build-tag: false
            wipe-workspace: false
            reference-repo: /home/tcwg-buildslave/snapshots-ref/gcc.git
            clean:
                before: true
    execution-strategy:
        sequential: true
    wrappers:
        - timeout:
            timeout: 300
        - timestamps
        - ssh-agent-credentials:
            # tcwg-buildslave user id
            users:
                - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
        - build-name:
            name: '#${BUILD_NUMBER}-${gcc_ref}'
    builders:
        - shell: |
            #!/bin/bash
            set -ex

            rm -rf release
            rm -rf tcwg-release-tools
            git clone -b automation --depth 1 https://git.linaro.org/toolchain/tcwg-release-tools

            pushd gcc_src

            git config --local user.name "TCWG Automation"
            git config --local user.email linaro-toolchain@lists.linaro.org
            if git remote | grep -q gerrit; then
              git remote rm gerrit
            fi
            git remote add gerrit ssh://tcwg-buildslave@review.linaro.org:29418/toolchain/gcc

            FLAGS="-t $gcc_ref -e gerrit"
            
            case "$tag_kind" in
                snapshot) FLAGS="$FLAGS -R" ;;
                candidate) FLAGS="$FLAGS -r" ;;
                release) FLAGS="$FLAGS -R";;
                *) echo "ERROR: tag_king is missing"; exit 1 ;;
            esac

            if [ x"$spin" != x ]; then
                FLAGS="$FLAGS $spin"
            fi

            if [ x"$date" != x ]; then
                FLAGS="$FLAGS -d $date"
            fi

            ${WORKSPACE}/tcwg-release-tools/tcwg-release-tag.sh $FLAGS

            popd 1>/dev/null

