---
# CORD lint and static code validation job templates
# These are invoked by the per-git-repo jobs stored in verify/

# Verify that there is valid license/copyright on files
- job-template:
    id: verify-licensed
    name: 'verify_{project}_licensed'
    description: |
      Created by verify-licensed job-template from ci-management/jjb/lint.yaml

    triggers:
      - cord-infra-gerrit-trigger-patchset:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          file-include-regexp: '{all-files-regexp}'
          dependency-jobs: '{dependency-jobs}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: '{build-timeout}'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - lf-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: '$GERRIT_REFSPEC'
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: gerrit
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    node: '{build-node}'
    project-type: freestyle
    concurrent: true

    builders:
      - shell: !include-raw-escape: shell/licensecheck.sh


# run `ansible-lint` to validate ansible playbooks/roles
- job-template:
    id: verify-ansible-lint
    name: 'verify_{project}_ansible-lint'
    description: |
      Created by verify-ansible-lint job-template from ci-management/jjb/lint.yaml

    triggers:
      - cord-infra-gerrit-trigger-patchset:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          file-include-regexp: '{all-files-regexp}'
          dependency-jobs: '{dependency-jobs}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: '{build-timeout}'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - lf-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: '$GERRIT_REFSPEC'
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: gerrit
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    node: '{build-node}'
    project-type: freestyle
    concurrent: true

    builders:
      - shell: !include-raw-escape: shell/ansiblelint.sh


# check helm charts with `helm lint --strict` and that charts version is
# updated when the contents of a chart is modified.
- job-template:
    id: verify-helm-lint
    name: 'verify_{project}_helm-lint'
    description: |
      Created by verify-helm-lint job-template from ci-management/jjb/lint.yaml

    triggers:
      - cord-infra-gerrit-trigger-patchset:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          file-include-regexp: '{all-files-regexp}'
          dependency-jobs: '{dependency-jobs}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: '{build-timeout}'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - lf-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: '$GERRIT_REFSPEC'
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: gerrit
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    node: '{build-node}'
    project-type: freestyle
    concurrent: true

    builders:
      - shell: |
          #!/usr/bin/env bash
          set -eu -o pipefail

          helm init --client-only
          helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
          helm repo add rook-beta https://charts.rook.io/beta
          helm repo add cord https://charts.opencord.org

          git clone https://gerrit.opencord.org/helm-repo-tools
          ./helm-repo-tools/helmlint.sh clean

          # Specify the remote branch to compare against
          export COMPARISON_BRANCH="origin/$GERRIT_BRANCH"
          ./helm-repo-tools/chart_version_check.sh


# run `shellcheck` to validate shell scripts charts
- job-template:
    id: verify-shellcheck
    name: 'verify_{project}_shellcheck'
    description: |
      Created by {id} job-template from ci-management/jjb/lint.yaml

    triggers:
      - cord-infra-gerrit-trigger-patchset:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          file-include-regexp: '{all-files-regexp}'
          dependency-jobs: '{dependency-jobs}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: '{build-timeout}'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - lf-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: '$GERRIT_REFSPEC'
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: gerrit
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    node: '{build-node}'
    project-type: freestyle
    concurrent: true

    builders:
      - shell: !include-raw-escape: shell/shcheck.sh
