From a0085b91dd63ed26db459845cd80a649f2992872 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Thu, 19 Oct 2023 01:40:48 +0800 Subject: [PATCH] feat(apps/prod/tekton/config/triggers): add triggers for `pingcap-qe/artifacts` - branch pushing. - branch creating. - tag creating. Signed-off-by: wuhuizuo --- .../bindings/github-branch-create.yaml | 10 +++ .../triggers/bindings/github-branch-push.yaml | 12 +++ .../configs/triggers/bindings/github-pr.yaml | 8 +- .../triggers/bindings/github-tag-create.yaml | 12 +++ .../triggers/bindings/kustomization.yaml | 3 + .../event-listeners/event-listener.yaml | 68 ++++++++++++++-- .../branch-create-pingcap-qe-artifacts.yaml | 80 +++++++++++++++++++ .../triggers/templates/kustomization.yaml | 3 + .../templates/push-pingcap-qe-artifacts.yaml | 80 +++++++++++++++++++ .../tag-create-pingcap-qe-artifacts.yaml | 80 +++++++++++++++++++ .../create-branch-pingcap-qe-artifacts.yaml | 22 +++++ .../create-tag-pingcap-qe-artifacts.yaml | 22 +++++ .../triggers/triggers/kustomization.yaml | 3 + .../triggers/pull-pingcap-qe-artifacts.yaml | 14 ---- .../triggers/push-pingcap-qe-artifacts.yaml | 22 +++++ 15 files changed, 418 insertions(+), 21 deletions(-) create mode 100644 apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml create mode 100644 apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml create mode 100644 apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml create mode 100644 apps/prod/tekton/configs/triggers/templates/branch-create-pingcap-qe-artifacts.yaml create mode 100644 apps/prod/tekton/configs/triggers/templates/push-pingcap-qe-artifacts.yaml create mode 100644 apps/prod/tekton/configs/triggers/templates/tag-create-pingcap-qe-artifacts.yaml create mode 100644 apps/prod/tekton/configs/triggers/triggers/create-branch-pingcap-qe-artifacts.yaml create mode 100644 apps/prod/tekton/configs/triggers/triggers/create-tag-pingcap-qe-artifacts.yaml create mode 100644 apps/prod/tekton/configs/triggers/triggers/push-pingcap-qe-artifacts.yaml diff --git a/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml b/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml new file mode 100644 index 000000000..329b35a75 --- /dev/null +++ b/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml @@ -0,0 +1,10 @@ +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + name: github-branch-create +spec: + params: + - name: git-url + value: $(body.repository.url) + - name: git-ref + value: $(body.ref) diff --git a/apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml b/apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml new file mode 100644 index 000000000..5050159df --- /dev/null +++ b/apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml @@ -0,0 +1,12 @@ +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + name: github-branch-push +spec: + params: + - name: git-url + value: $(body.repository.url) + - name: git-revision + value: $(body.head_commit.id) + - name: git-ref + value: $(body.ref) diff --git a/apps/prod/tekton/configs/triggers/bindings/github-pr.yaml b/apps/prod/tekton/configs/triggers/bindings/github-pr.yaml index 747fa59f5..0489e1e35 100644 --- a/apps/prod/tekton/configs/triggers/bindings/github-pr.yaml +++ b/apps/prod/tekton/configs/triggers/bindings/github-pr.yaml @@ -4,12 +4,16 @@ metadata: name: github-pr spec: params: - - name: git-revision - value: $(body.pull_request.head.sha) - name: git-url value: $(body.pull_request.head.repo.clone_url) + - name: git-revision + value: $(body.pull_request.head.sha) - name: pr-number value: $(body.pull_request.number) + - name: pr-title + value: $(body.pull_request.title) + - name: pr-body + value: $(body.pull_request.body) - name: pr-user value: $(body.pull_request.user.login) - name: pr-head-owner diff --git a/apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml b/apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml new file mode 100644 index 000000000..493d470ea --- /dev/null +++ b/apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml @@ -0,0 +1,12 @@ +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + name: github-tag-create +spec: + params: + - name: git-url + value: $(body.repository.url) + - name: git-ref + value: $(body.ref) + - name: git-tag + value: $(body.ref) diff --git a/apps/prod/tekton/configs/triggers/bindings/kustomization.yaml b/apps/prod/tekton/configs/triggers/bindings/kustomization.yaml index 85278134c..b7a6eb027 100644 --- a/apps/prod/tekton/configs/triggers/bindings/kustomization.yaml +++ b/apps/prod/tekton/configs/triggers/bindings/kustomization.yaml @@ -2,3 +2,6 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - github-pr.yaml + - github-branch-create.yaml + - github-branch-push.yaml + - github-tag-create.yaml diff --git a/apps/prod/tekton/configs/triggers/event-listeners/event-listener.yaml b/apps/prod/tekton/configs/triggers/event-listeners/event-listener.yaml index c5753a4b3..267a22b55 100644 --- a/apps/prod/tekton/configs/triggers/event-listeners/event-listener.yaml +++ b/apps/prod/tekton/configs/triggers/event-listeners/event-listener.yaml @@ -10,13 +10,8 @@ spec: interceptors: - name: "filter on eventType" ref: - # name of the clusterinterceptor name: github params: - # - name: secretRef - # value: - # secretName: github-secret - # secretKey: secretToken - name: eventTypes value: ["pull_request"] - name: "validate PR state and add field" @@ -32,3 +27,66 @@ spec: labelSelector: matchLabels: type: github-pr + - name: github-branch-push + interceptors: + - name: "filter on eventType" + ref: + name: github + params: + - name: eventTypes + value: ["push"] + - name: "validate branch push" + ref: + name: cel + params: + - name: filter + value: body.ref_type == 'branch' + triggerSelector: + namespaceSelector: + matchNames: + - ee-cd + labelSelector: + matchLabels: + type: github-branch-push + - name: github-branch-create + interceptors: + - name: "filter on eventType" + ref: + name: github + params: + - name: eventTypes + value: ["create"] + - name: "validate branch create" + ref: + name: cel + params: + - name: filter + value: body.ref_type == 'branch' + triggerSelector: + namespaceSelector: + matchNames: + - ee-cd + labelSelector: + matchLabels: + type: github-branch-create + - name: github-tag-create + interceptors: + - name: "filter on eventType" + ref: + name: github + params: + - name: eventTypes + value: ["create"] + - name: "validate tag create" + ref: + name: cel + params: + - name: filter + value: body.ref_type == 'tag' + triggerSelector: + namespaceSelector: + matchNames: + - ee-cd + labelSelector: + matchLabels: + type: github-tag-create diff --git a/apps/prod/tekton/configs/triggers/templates/branch-create-pingcap-qe-artifacts.yaml b/apps/prod/tekton/configs/triggers/templates/branch-create-pingcap-qe-artifacts.yaml new file mode 100644 index 000000000..aed9c66f6 --- /dev/null +++ b/apps/prod/tekton/configs/triggers/templates/branch-create-pingcap-qe-artifacts.yaml @@ -0,0 +1,80 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: branch-create-pingcap-qe-artifacts +spec: + params: + - name: git-url + description: The git repository full url + - name: git-revision + description: The git revision + default: main + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: post-pingcap-qe-artifacts-run- + annotations: + "tekton.dev/git-status": "true" + "tekton.dev/status-context": "demo-pipeline1" + "tekton.dev/status-description": "demo pipeline forwarded by prow" + "tekton.dev/status-target-url": "https://do.pingcap.net/tekton/#/namespaces/{{ .Namespace }}/pipelineruns/{{ .Name }}" + "tekton.dev/git-repo": $(tt.params.git-url) + "tekton.dev/git-revision": $(tt.params.git-revision) + spec: + pipelineSpec: + params: + - name: git-url + type: string + - name: git-revision + default: main + type: string + tasks: + - name: echo-good-morning + taskSpec: + metadata: {} + spec: null + steps: + - image: ubuntu + name: echo + resources: {} + script: | + #!/usr/bin/env bash + echo "Good Morning!" + - name: checkout + params: + - name: url + value: $(params.git-url) + - name: revision + value: $(params.git-revision) + taskRef: + kind: Task + name: git-clone + workspaces: + - name: output + workspace: git-source + - name: echo-good-afternoon + taskSpec: + metadata: {} + spec: null + steps: + - image: ubuntu + name: echo + resources: {} + script: | + #!/usr/bin/env bash + echo "Good Afternoon!" + params: + - name: git-url + value: $(tt.params.git-url) + - name: git-revision + value: $(tt.params.git-revision) + workspaces: + - name: git-source + volumeClaimTemplate: + spec: + storageClassName: nfs + accessModes: [ReadWriteMany] + resources: + requests: + storage: 1Gi diff --git a/apps/prod/tekton/configs/triggers/templates/kustomization.yaml b/apps/prod/tekton/configs/triggers/templates/kustomization.yaml index 55aa6a1de..a7bb07f00 100644 --- a/apps/prod/tekton/configs/triggers/templates/kustomization.yaml +++ b/apps/prod/tekton/configs/triggers/templates/kustomization.yaml @@ -1,4 +1,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: + - branch-create-pingcap-qe-artifacts.yaml - pull-pingcap-qe-artifacts.yaml + - push-pingcap-qe-artifacts.yaml + - tag-create-pingcap-qe-artifacts.yaml diff --git a/apps/prod/tekton/configs/triggers/templates/push-pingcap-qe-artifacts.yaml b/apps/prod/tekton/configs/triggers/templates/push-pingcap-qe-artifacts.yaml new file mode 100644 index 000000000..89daed6db --- /dev/null +++ b/apps/prod/tekton/configs/triggers/templates/push-pingcap-qe-artifacts.yaml @@ -0,0 +1,80 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: push-pingcap-qe-artifacts +spec: + params: + - name: git-url + description: The git repository full url + - name: git-revision + description: The git revision + default: main + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: post-pingcap-qe-artifacts-run- + annotations: + "tekton.dev/git-status": "true" + "tekton.dev/status-context": "demo-pipeline1" + "tekton.dev/status-description": "demo pipeline forwarded by prow" + "tekton.dev/status-target-url": "https://do.pingcap.net/tekton/#/namespaces/{{ .Namespace }}/pipelineruns/{{ .Name }}" + "tekton.dev/git-repo": $(tt.params.git-url) + "tekton.dev/git-revision": $(tt.params.git-revision) + spec: + pipelineSpec: + params: + - name: git-url + type: string + - name: git-revision + default: main + type: string + tasks: + - name: echo-good-morning + taskSpec: + metadata: {} + spec: null + steps: + - image: ubuntu + name: echo + resources: {} + script: | + #!/usr/bin/env bash + echo "Good Morning!" + - name: checkout + params: + - name: url + value: $(params.git-url) + - name: revision + value: $(params.git-revision) + taskRef: + kind: Task + name: git-clone + workspaces: + - name: output + workspace: git-source + - name: echo-good-afternoon + taskSpec: + metadata: {} + spec: null + steps: + - image: ubuntu + name: echo + resources: {} + script: | + #!/usr/bin/env bash + echo "Good Afternoon!" + params: + - name: git-url + value: $(tt.params.git-url) + - name: git-revision + value: $(tt.params.git-revision) + workspaces: + - name: git-source + volumeClaimTemplate: + spec: + storageClassName: nfs + accessModes: [ReadWriteMany] + resources: + requests: + storage: 1Gi diff --git a/apps/prod/tekton/configs/triggers/templates/tag-create-pingcap-qe-artifacts.yaml b/apps/prod/tekton/configs/triggers/templates/tag-create-pingcap-qe-artifacts.yaml new file mode 100644 index 000000000..6d87e55a7 --- /dev/null +++ b/apps/prod/tekton/configs/triggers/templates/tag-create-pingcap-qe-artifacts.yaml @@ -0,0 +1,80 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: tag-create-pingcap-qe-artifacts +spec: + params: + - name: git-url + description: The git repository full url + - name: git-revision + description: The git revision + default: main + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: PipelineRun + metadata: + generateName: post-pingcap-qe-artifacts-run- + annotations: + "tekton.dev/git-status": "true" + "tekton.dev/status-context": "demo-pipeline1" + "tekton.dev/status-description": "demo pipeline forwarded by prow" + "tekton.dev/status-target-url": "https://do.pingcap.net/tekton/#/namespaces/{{ .Namespace }}/pipelineruns/{{ .Name }}" + "tekton.dev/git-repo": $(tt.params.git-url) + "tekton.dev/git-revision": $(tt.params.git-revision) + spec: + pipelineSpec: + params: + - name: git-url + type: string + - name: git-revision + default: main + type: string + tasks: + - name: echo-good-morning + taskSpec: + metadata: {} + spec: null + steps: + - image: ubuntu + name: echo + resources: {} + script: | + #!/usr/bin/env bash + echo "Good Morning!" + - name: checkout + params: + - name: url + value: $(params.git-url) + - name: revision + value: $(params.git-revision) + taskRef: + kind: Task + name: git-clone + workspaces: + - name: output + workspace: git-source + - name: echo-good-afternoon + taskSpec: + metadata: {} + spec: null + steps: + - image: ubuntu + name: echo + resources: {} + script: | + #!/usr/bin/env bash + echo "Good Afternoon!" + params: + - name: git-url + value: $(tt.params.git-url) + - name: git-revision + value: $(tt.params.git-revision) + workspaces: + - name: git-source + volumeClaimTemplate: + spec: + storageClassName: nfs + accessModes: [ReadWriteMany] + resources: + requests: + storage: 1Gi diff --git a/apps/prod/tekton/configs/triggers/triggers/create-branch-pingcap-qe-artifacts.yaml b/apps/prod/tekton/configs/triggers/triggers/create-branch-pingcap-qe-artifacts.yaml new file mode 100644 index 000000000..aa18aacad --- /dev/null +++ b/apps/prod/tekton/configs/triggers/triggers/create-branch-pingcap-qe-artifacts.yaml @@ -0,0 +1,22 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: Trigger +metadata: + name: branch-create-pingcap-qe-artifacts + labels: + type: github-branch-create + github-owner: PingCAP-QE + github-repo: artifacts +spec: + interceptors: + - name: filter on repo owner and name + ref: + name: cel + params: + - name: filter + value: >- + body.repository.owner.login == 'PingCAP-QE' && body.repository.name == + 'artifacts' + bindings: + - ref: github-branch-create + template: + ref: branch-create-pingcap-qe-artifacts diff --git a/apps/prod/tekton/configs/triggers/triggers/create-tag-pingcap-qe-artifacts.yaml b/apps/prod/tekton/configs/triggers/triggers/create-tag-pingcap-qe-artifacts.yaml new file mode 100644 index 000000000..c53830030 --- /dev/null +++ b/apps/prod/tekton/configs/triggers/triggers/create-tag-pingcap-qe-artifacts.yaml @@ -0,0 +1,22 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: Trigger +metadata: + name: tag-create-pingcap-qe-artifacts + labels: + type: github-tag-create + github-owner: PingCAP-QE + github-repo: artifacts +spec: + interceptors: + - name: filter on repo owner and name + ref: + name: cel + params: + - name: filter + value: >- + body.repository.owner.login == 'PingCAP-QE' && body.repository.name == + 'artifacts' + bindings: + - ref: github-tag-create + template: + ref: tag-create-pingcap-qe-artifacts diff --git a/apps/prod/tekton/configs/triggers/triggers/kustomization.yaml b/apps/prod/tekton/configs/triggers/triggers/kustomization.yaml index 55aa6a1de..d470365bd 100644 --- a/apps/prod/tekton/configs/triggers/triggers/kustomization.yaml +++ b/apps/prod/tekton/configs/triggers/triggers/kustomization.yaml @@ -1,4 +1,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: + - create-branch-pingcap-qe-artifacts.yaml + - create-tag-pingcap-qe-artifacts.yaml - pull-pingcap-qe-artifacts.yaml + - push-pingcap-qe-artifacts.yaml diff --git a/apps/prod/tekton/configs/triggers/triggers/pull-pingcap-qe-artifacts.yaml b/apps/prod/tekton/configs/triggers/triggers/pull-pingcap-qe-artifacts.yaml index 60be8e797..cd79aa70b 100644 --- a/apps/prod/tekton/configs/triggers/triggers/pull-pingcap-qe-artifacts.yaml +++ b/apps/prod/tekton/configs/triggers/triggers/pull-pingcap-qe-artifacts.yaml @@ -13,23 +13,9 @@ spec: name: cel params: - name: filter - # value: body.repository.name == 'artifacts' value: >- body.organization.login == 'PingCAP-QE' && body.repository.name == 'artifacts' - # - name: add change files to extensions - # ref: - # name: github - # params: - # - name: "addChangedFiles" # TODO: upgrade tekton - # value: - # enabled: true - # - name: execute only when Dockerfile changed - # ref: - # name: cel - # params: - # - name: filter - # value: extensions.changed_files.matches('Dockerfile') bindings: - ref: github-pr template: diff --git a/apps/prod/tekton/configs/triggers/triggers/push-pingcap-qe-artifacts.yaml b/apps/prod/tekton/configs/triggers/triggers/push-pingcap-qe-artifacts.yaml new file mode 100644 index 000000000..048b7f1bb --- /dev/null +++ b/apps/prod/tekton/configs/triggers/triggers/push-pingcap-qe-artifacts.yaml @@ -0,0 +1,22 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: Trigger +metadata: + name: push-pingcap-qe-artifacts + labels: + type: github-branch-push + github-owner: PingCAP-QE + github-repo: artifacts +spec: + interceptors: + - name: filter on repo owner and name + ref: + name: cel + params: + - name: filter + value: >- + body.repository.owner.login == 'PingCAP-QE' && body.repository.name == + 'artifacts' + bindings: + - ref: github-branch-push + template: + ref: push-pingcap-qe-artifacts