- job:
#if CHECK_TYPE_shell_scripts_sanity
    name: tcwg-shell-scripts-sanity-check
#elif CHECK_TYPE_lnt
    name: tcwg-lnt-check
#endif
    project-type: freestyle
    defaults: global
    logrotate:
        daysToKeep: 30
        numToKeep: 30
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            everyone-flat:
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 100
    disabled: false
    node: tcwg-x86_64-build

#if CHECK_TYPE_shell_scripts_sanity
    display-name: 'TCWG shell scripts sanity check'
#elif CHECK_TYPE_lnt
    display-name: 'TCWG LNT check'
#endif
    scm:
        # Get a stable copy of the check script
        - git:
            url: https://gitlab.com/LinaroLtd/tcwg/jenkins-scripts.git
            branches:
                - origin/master
            basedir: jenkins-scripts-master
        # Then this is what we're actually checking
        # (which might also be jenkins-scripts, but Gerrit's version)
        - git:
            url: https://review.linaro.org/${GERRIT_PROJECT}
            refspec: ${GERRIT_REFSPEC}
            branches:
                - ${GERRIT_BRANCH}
            skip-tag: true
            clean:
                before: true
            choosing-strategy: gerrit
            basedir: ${GERRIT_PROJECT}
    triggers:
        - gerrit:
            server-name: 'review.linaro.org'
            trigger-on:
                - patchset-created-event:
                    exclude-drafts: true
            projects:
#if CHECK_TYPE_shell_scripts_sanity
                - project-compare-type: 'REG_EXP'
                  project-pattern: 'toolchain\/(jenkins-scripts|bmk-scripts)'
                  branches:
                    - branch-compare-type: 'PLAIN'
                      branch-pattern: 'master'
#elif CHECK_TYPE_lnt
                - project-compare-type: 'PLAIN'
                  project-pattern: 'toolchain/llvm-lnt'
                  branches:
                    - branch-compare-type: 'PLAIN'
                      branch-pattern: 'linaro-local/master'
#endif
    wrappers:
        - timeout:
            timeout: 10
        - timestamps
        - build-name:
            name: '#${BUILD_NUMBER}-${GERRIT_PROJECT}'
        - ssh-agent-credentials:
            # tcwg-buildslave user id
            users:
                - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
    builders:
        - shell:
            command: |
                #!/bin/bash
                set -ex

                # Shellcheck source= directives are relative to
                # the CWD, so run from inside the folder.
                # GERRIT_PROJECT is for example toolchain/jenkins-scripts
                cd ${GERRIT_PROJECT}
                git submodule update --init --remote
#if CHECK_TYPE_shell_scripts_sanity
                ../../jenkins-scripts-master/docker-run.sh -- ../../jenkins-scripts-master/sanity-check.sh
#elif CHECK_TYPE_lnt
                ../../jenkins-scripts-master/docker-run.sh -- ../../jenkins-scripts-master/tcwg-lnt/lnt-check.sh
#endif
            # Aka some files had issues
            # Any other non-zero means we called shellcheck incorrectly
            unstable-return: 1
