---
- project:
    name: 'apex-verify-jobs'
    project: 'apex'
    jobs:
      - 'apex-verify-{stream}'
      - 'apex-verify-gate-{stream}'
      - 'apex-verify-unit-tests-{stream}'
    stream:
      - master: &master
          branch: '{stream}'
          gs-pathname: ''
          verify-scenario: 'os-nosdn-nofeature-noha'
          disabled: false
      - gambia: &gambia
          branch: 'stable/{stream}'
          gs-pathname: '/{stream}'
          verify-scenario: 'os-nosdn-nofeature-ha'
          disabled: false
      - fraser: &fraser
          branch: 'stable/{stream}'
          gs-pathname: '/{stream}'
          verify-scenario: 'os-nosdn-nofeature-ha'
          disabled: false
      - danube: &danube
          branch: 'stable/{stream}'
          gs-pathname: '/{stream}'
          verify-scenario: 'os-odl_l3-nofeature-ha'
          disabled: true
      - euphrates: &euphrates
          branch: 'stable/{stream}'
          gs-pathname: '/{stream}'
          verify-scenario: 'os-odl-nofeature-ha'
          disabled: false

# Unit Test
- job-template:
    name: 'apex-verify-unit-tests-{stream}'

    node: 'apex-build-master'

    concurrent: true

    disabled: '{obj:disabled}'

    parameters:
      - apex-parameter:
          gs-pathname: '{gs-pathname}'
      - project-parameter:
          project: '{project}'
          branch: '{branch}'

    scm:
      - git-scm-gerrit

    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - patchset-created-event:
                exclude-drafts: 'false'
                exclude-trivial-rebase: 'false'
                exclude-no-code-change: 'true'
            - draft-published-event
            - comment-added-contains-event:
                comment-contains-value: 'recheck'
            - comment-added-contains-event:
                comment-contains-value: 'reverify'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: 'apex'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              disable-strict-forbidden-file-verification: 'false'
              file-paths:
                - compare-type: ANT
                  pattern: 'apex/tests/**'
              forbidden-file-paths:
                - compare-type: ANT
                  pattern: '*'
                - compare-type: ANT
                  pattern: 'apex/*'
                - compare-type: ANT
                  pattern: 'build/**'
                - compare-type: ANT
                  pattern: 'lib/**'
                - compare-type: ANT
                  pattern: 'config/**'
                - compare-type: ANT
                  pattern: 'apex/build/**'
                - compare-type: ANT
                  pattern: 'apex/common/**'
                - compare-type: ANT
                  pattern: 'apex/inventory/**'
                - compare-type: ANT
                  pattern: 'apex/network/**'
                - compare-type: ANT
                  pattern: 'apex/overcloud/**'
                - compare-type: ANT
                  pattern: 'apex/settings/**'
                - compare-type: ANT
                  pattern: 'apex/undercloud/**'
                - compare-type: ANT
                  pattern: 'apex/virtual/**'

    properties:
      - logrotate-default
      - throttle:
          max-per-node: 1
          max-total: 10
          option: 'project'

    builders:
      - apex-unit-test

# Verify
- job-template:
    name: 'apex-verify-{stream}'

    concurrent: true

    disabled: '{obj:disabled}'

    project-type: 'multijob'

    parameters:
      - '{project}-virtual-{stream}-defaults'
      - apex-parameter:
          gs-pathname: '{gs-pathname}/dev'
      - project-parameter:
          project: '{project}'
          branch: '{branch}'
      - string:
          name: ARTIFACT_VERSION
          default: dev
          description: "Used for overriding the ARTIFACT_VERSION"
    scm:
      - git-scm-gerrit

    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - patchset-created-event:
                exclude-drafts: 'false'
                exclude-trivial-rebase: 'false'
                exclude-no-code-change: 'true'
            - draft-published-event
            - comment-added-contains-event:
                comment-contains-value: 'recheck'
            - comment-added-contains-event:
                comment-contains-value: 'reverify'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: 'apex'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              disable-strict-forbidden-file-verification: 'true'
              file-paths:
                - compare-type: ANT
                  pattern: '*'
                - compare-type: ANT
                  pattern: 'apex/*'
                - compare-type: ANT
                  pattern: 'build/**'
                - compare-type: ANT
                  pattern: 'ci/**'
                - compare-type: ANT
                  pattern: 'lib/**'
                - compare-type: ANT
                  pattern: 'config/**'
                - compare-type: ANT
                  pattern: 'apex/build/**'
                - compare-type: ANT
                  pattern: 'apex/common/**'
                - compare-type: ANT
                  pattern: 'apex/inventory/**'
                - compare-type: ANT
                  pattern: 'apex/network/**'
                - compare-type: ANT
                  pattern: 'apex/overcloud/**'
                - compare-type: ANT
                  pattern: 'apex/settings/**'
                - compare-type: ANT
                  pattern: 'apex/undercloud/**'
                - compare-type: ANT
                  pattern: 'apex/virtual/**'
              forbidden-file-paths:
                - compare-type: ANT
                  pattern: 'apex/tests/**'
                - compare-type: ANT
                  pattern: 'docs/**'

    properties:
      - logrotate-default
      - throttle:
          max-per-node: 3
          max-total: 10
          option: 'project'
      - build-blocker:
          use-build-blocker: true
          blocking-level: 'NODE'
          blocking-jobs:
            - 'apex-.*-promote.*'
    builders:
      - description-setter:
          description: "Built on $NODE_NAME"
      - multijob:
          name: basic
          condition: SUCCESSFUL
          projects:
            - name: 'apex-verify-unit-tests-{stream}'
              current-parameters: false
              predefined-parameters: |
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
                GERRIT_CHANGE_COMMIT_MESSAGE=$GERRIT_CHANGE_COMMIT_MESSAGE
              node-parameters: false
              kill-phase-on: FAILURE
              abort-all-job: true
              git-revision: true
      - multijob:
          name: build
          condition: SUCCESSFUL
          projects:
            - name: 'apex-build-{stream}'
              current-parameters: false
              predefined-parameters: |
                ARTIFACT_VERSION=$ARTIFACT_VERSION
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
                GERRIT_CHANGE_COMMIT_MESSAGE=$GERRIT_CHANGE_COMMIT_MESSAGE
              node-parameters: false
              kill-phase-on: FAILURE
              abort-all-job: true
              git-revision: true
      - multijob:
          name: deploy-virtual
          condition: SUCCESSFUL
          projects:
            - name: 'apex-virtual-{stream}'
              current-parameters: false
              predefined-parameters: |
                ARTIFACT_VERSION=$ARTIFACT_VERSION
                DEPLOY_SCENARIO={verify-scenario}
                OPNFV_CLEAN=yes
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
                GERRIT_CHANGE_COMMIT_MESSAGE=$GERRIT_CHANGE_COMMIT_MESSAGE
                FUNCTEST_SUITE_NAME=tempest_smoke
                FUNCTEST_MODE=testcase
              node-parameters: true
              kill-phase-on: FAILURE
              abort-all-job: true
              git-revision: true

# Verify Scenario Gate
- job-template:
    name: 'apex-verify-gate-{stream}'

    concurrent: true

    disabled: '{obj:disabled}'

    project-type: 'multijob'

    parameters:
      - '{project}-virtual-{stream}-defaults'
      - apex-parameter:
          gs-pathname: '{gs-pathname}/dev'
      - project-parameter:
          project: '{project}'
          branch: '{branch}'
      - string:
          name: GIT_BASE
          default: https://gerrit.opnfv.org/gerrit/$PROJECT
          description: "Used for overriding the GIT URL coming from parameters macro."
      - string:
          name: ARTIFACT_VERSION
          default: dev
          description: "Used for overriding the ARTIFACT_VERSION"

    scm:
      - git-scm-gerrit

    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - comment-added-contains-event:
                comment-contains-value: '^Patch Set [0-9]+: Code-Review\+2.*start-gate-scenario:.*'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: 'apex'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              file-paths:
                - compare-type: ANT
                  pattern: 'ci/**'
                - compare-type: ANT
                  pattern: 'build/**'
                - compare-type: ANT
                  pattern: 'lib/**'
                - compare-type: ANT
                  pattern: 'config/**'
                - compare-type: ANT
                  pattern: 'apex/**'

    properties:
      - logrotate-default
      - build-blocker:
          use-build-blocker: true
          blocking-level: 'NODE'
          blocking-jobs:
            - 'apex-verify.*'
            - 'apex-virtual.*'
            - 'apex-.*-promote.*'
            - 'odl-netvirt.*'
      - throttle:
          max-per-node: 1
          max-total: 10
          option: 'project'

    builders:
      # yamllint disable rule:line-length
      - shell: |
          echo DEPLOY_SCENARIO=$(echo $GERRIT_EVENT_COMMENT_TEXT | grep start-gate-scenario | grep -Eo '(os|k8s)-.*$') > detected_scenario
      # yamllint enable rule:line-length
      - inject:
          properties-file: detected_scenario
      - multijob:
          name: deploy-virtual
          condition: SUCCESSFUL
          projects:
            - name: 'apex-deploy-virtual-{stream}'
              current-parameters: false
              predefined-parameters: |
                ARTIFACT_VERSION=$ARTIFACT_VERSION
                DEPLOY_SCENARIO=$DEPLOY_SCENARIO
                OPNFV_CLEAN=yes
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
                GERRIT_CHANGE_COMMIT_MESSAGE=$GERRIT_CHANGE_COMMIT_MESSAGE
                GERRIT_EVENT_COMMENT_TEXT=$GERRIT_EVENT_COMMENT_TEXT
              node-parameters: true
              kill-phase-on: FAILURE
              abort-all-job: true
              git-revision: true
      - shell: |
          features=$(echo $DEPLOY_SCENARIO | sed -r -n 's/os-.+-(.+)-(noha|ha)/\1/p')
          if [ "$features" == 'rocky' ]; then
            echo "DOCKER_TAG=hunter" > functest_tag
          elif [[ "$features" =~ 'rocky' ]]; then
            echo "DOCKER_TAG=hunter" > functest_tag
          else
            echo "DOCKER_TAG=''" > functest_tag
          fi
      - inject:
          properties-file: functest_tag
          override-build-parameters: true
      - multijob:
          name: functest-smoke
          condition: ALWAYS
          projects:
            - name: 'functest-apex-virtual-suite-{stream}'
              current-parameters: false
              predefined-parameters: |
                DEPLOY_SCENARIO=$DEPLOY_SCENARIO
                DOCKER_TAG=""
                FUNCTEST_SUITE_NAME=tempest_smoke
                FUNCTEST_MODE=testcase
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
                GERRIT_CHANGE_COMMIT_MESSAGE=$GERRIT_CHANGE_COMMIT_MESSAGE
              node-parameters: true
              kill-phase-on: NEVER
              enable-condition: "def m = '$DEPLOY_SCENARIO' != 'k8s-nosdn-nofeature-noha'"
              abort-all-job: true
              git-revision: false
      - multijob:
          name: apex-fetch-logs
          projects:
            - name: 'apex-fetch-logs-{stream}'
              current-parameters: true
              predefined-parameters: |
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
              node-parameters: true
              kill-phase-on: NEVER
              abort-all-job: true
              git-revision: false

########################
# builder macros
########################
- builder:
    name: apex-unit-test
    builders:
      - shell:
          !include-raw: ./apex-unit-test.sh