From b19b7580375375145908b11680834ed8524da9a8 Mon Sep 17 00:00:00 2001 From: vinamra28 Date: Wed, 17 Feb 2021 15:57:33 +0530 Subject: [PATCH] Add Catlin to Catalog CI - Adds a Tekton Task and Pipeline which will run catlin on catalog tasks. - Add corresponding TriggerTemplate. - Modify EventListener to add catlin jobs. Signed-off-by: vinamra28 --- tekton/ci/eventlistener.yaml | 59 ++++++++++++++++- tekton/ci/jobs/kustomization.yaml | 3 +- tekton/ci/jobs/tekton-catlin-lint.yaml | 78 +++++++++++++++++++++++ tekton/ci/templates/catalog-template.yaml | 69 ++++++++++++++++++++ tekton/ci/templates/kustomization.yaml | 3 +- 5 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 tekton/ci/jobs/tekton-catlin-lint.yaml create mode 100644 tekton/ci/templates/catalog-template.yaml diff --git a/tekton/ci/eventlistener.yaml b/tekton/ci/eventlistener.yaml index a76aafc18..e3b56d35c 100644 --- a/tekton/ci/eventlistener.yaml +++ b/tekton/ci/eventlistener.yaml @@ -270,4 +270,61 @@ spec: - ref: tekton-ci-clone-depth - ref: tekton-ci-webhook-issue-labels template: - ref: tekton-community-ci-pipeline \ No newline at end of file + ref: tekton-community-ci-pipeline + - name: catalog-pull-request-ci + interceptors: + - github: + secretRef: + secretName: ci-webhook + secretKey: secret + eventTypes: + - pull_request + - cel: + filter: >- + body.repository.full_name == 'tektoncd/catalog' && + body.action in ['opened','synchronize'] + overlays: + - key: git_clone_depth + expression: "string(body.pull_request.commits + 1.0)" + bindings: + - ref: tekton-ci-github-base + - ref: tekton-ci-webhook-pull-request + - ref: tekton-ci-clone-depth + - ref: tekton-ci-webhook-pr-labels + template: + ref: tekton-catalog-ci-pipeline + - name: catalog-comment-ci + interceptors: + - github: + secretRef: + secretName: ci-webhook + secretKey: secret + eventTypes: + - issue_comment + - cel: + filter: >- + body.repository.full_name == 'tektoncd/catalog' && + body.action == 'created' && + 'pull_request' in body.issue && + body.issue.state == 'open' && + body.comment.body.matches('^/test($| [^ ]*[ ]*$)') + overlays: + - key: add_pr_body.pull_request_url + expression: "body.issue.pull_request.url" + - webhook: + objectRef: + kind: Service + name: add-pr-body + apiVersion: v1 + namespace: tektonci + - cel: + overlays: + - key: git_clone_depth + expression: "string(body.extensions.add_pr_body.pull_request_body.commits + 1.0)" + bindings: + - ref: tekton-ci-github-base + - ref: tekton-ci-webhook-comment + - ref: tekton-ci-clone-depth + - ref: tekton-ci-webhook-issue-labels + template: + ref: tekton-catalog-ci-pipeline \ No newline at end of file diff --git a/tekton/ci/jobs/kustomization.yaml b/tekton/ci/jobs/kustomization.yaml index dd39048f3..736db881a 100644 --- a/tekton/ci/jobs/kustomization.yaml +++ b/tekton/ci/jobs/kustomization.yaml @@ -6,4 +6,5 @@ resources: - tekton-kind-label.yaml - tekton-yamllint.yaml - tekton-python-test.yaml -- tekton-teps-validation.yaml \ No newline at end of file +- tekton-teps-validation.yaml +- tekton-catlin-lint.yaml diff --git a/tekton/ci/jobs/tekton-catlin-lint.yaml b/tekton/ci/jobs/tekton-catlin-lint.yaml new file mode 100644 index 000000000..891b10014 --- /dev/null +++ b/tekton/ci/jobs/tekton-catlin-lint.yaml @@ -0,0 +1,78 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: catlin-lint + namespace: tektonci +spec: + description: >- + This task detects changes in the pull request using git diff + and stores the changed tasks names in a workspace and passes + that to the catlin so that catlin can validate only changed + files. + workspaces: + - name: store-changed-files + description: Stores list of changed tasks + params: + - name: gitCloneDepth + description: Number of commits in the change + 1 + resources: + inputs: + - name: source + type: git + steps: + - name: find-changed-tasks + image: docker.io/alpine/git:v2.26.2@sha256:23618034b0be9205d9cc0846eb711b12ba4c9b468efdd8a59aac1d7b1a23363f + workingDir: $(resources.inputs.source.path) + script: | + function detect_new_changed_tasks() { + # detect for changes in the task manifest + git --no-pager diff --name-only HEAD~$(( $(params.gitCloneDepth) - 1 ))|grep 'task/[^\/]*/[^\/]*/*[^/]*.yaml'|xargs -I {} dirname {} + } + all_tests=$(detect_new_changed_tasks |sort -u || true) + echo -n $all_tests > $(workspaces.store-changed-files.path)/changed-files.txt + - name: lint-catalog + image: gcr.io/tekton-releases/dogfooding/catlin:latest + workingDir: $(resources.inputs.source.path) + script: | + catlin validate $(cat $(workspaces.store-changed-files.path)/changed-files.txt) +--- +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: catlin-linter + namespace: tektonci +spec: + workspaces: + - name: store-changed-files + description: Stores list of changed tasks + resources: + - name: source + type: git + params: + - name: gitCloneDepth + description: Number of commits in the change + 1 + - name: gitHubCommand + description: The command that was used to trigger testing + - name: checkName + description: The name of the GitHub check that this pipeline is used for + tasks: + - name: lint-catalog + conditions: + - conditionRef: "check-name-matches" + params: + - name: gitHubCommand + value: $(params.gitHubCommand) + - name: checkName + value: $(params.checkName) + taskRef: + name: catlin-lint + workspaces: + - name: store-changed-files + workspace: store-changed-files + resources: + inputs: + - name: source + resource: source + params: + - name: gitCloneDepth + value: $(params.gitCloneDepth) diff --git a/tekton/ci/templates/catalog-template.yaml b/tekton/ci/templates/catalog-template.yaml new file mode 100644 index 000000000..7f986e65e --- /dev/null +++ b/tekton/ci/templates/catalog-template.yaml @@ -0,0 +1,69 @@ +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerTemplate +metadata: + name: tekton-catalog-ci-pipeline + namespace: tektonci + annotations: + triggers.tekton.dev/old-escape-quotes: "true" +spec: + params: + - name: buildUUID + description: UUID used to track a CI Pipeline Run in logs + - name: package + description: org/repo + - name: pullRequestNumber + description: The pullRequestNumber + - name: pullRequestUrl + description: The HTML URL for the pull request + - name: gitRepository + description: The git repository that hosts context and Dockerfile + - name: gitRevision + description: The Git revision to be used. + - name: gitCloneDepth + description: Number of commits in the change + 1 + - name: gitHubCommand + description: | + The GitHub command that was used a trigger. This is only available when + this template is triggered by a comment. The default value is for the + case of a pull_request event. + default: "" + - name: labels + description: List of labels currently on the Pull Request + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: catalog-catlin-run- + labels: + prow.k8s.io/build-id: $(tt.params.buildUUID) + tekton.dev/check-name: pull-catalog-catlin-lint + tekton.dev/kind: ci + tekton.dev/pr-number: $(tt.params.pullRequestNumber) + annotations: + tekton.dev/gitRevision: "$(tt.params.gitRevision)" + tekton.dev/gitURL: "$(tt.params.gitRepository)" + spec: + serviceAccountName: tekton-ci-jobs + pipelineRef: + name: catlin-linter + workspaces: + - name: store-changed-files + emptyDir: {} + params: + - name: gitCloneDepth + value: $(tt.params.gitCloneDepth) + - name: gitHubCommand + value: $(tt.params.gitHubCommand) + - name: checkName + value: pull-catalog-catlin-lint + resources: + - name: source + resourceSpec: + type: git + params: + - name: revision + value: $(tt.params.gitRevision) + - name: url + value: $(tt.params.gitRepository) + - name: depth + value: $(tt.params.gitCloneDepth) diff --git a/tekton/ci/templates/kustomization.yaml b/tekton/ci/templates/kustomization.yaml index a8750f47c..ebef1b855 100644 --- a/tekton/ci/templates/kustomization.yaml +++ b/tekton/ci/templates/kustomization.yaml @@ -4,4 +4,5 @@ resources: - tekton-cd-template.yaml - bindings.yaml - website-template.yaml -- community-template.yaml \ No newline at end of file +- community-template.yaml +- catalog-template.yaml