From d8d202413926c58035de435f69e506f98015306f Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Tue, 24 Oct 2023 15:20:55 +0800 Subject: [PATCH 1/6] fix(apps/prod/tekton/configs/triggers/bindings): fix branch and tag bindings - tag creating event - branch creating event - branch pushing event Signed-off-by: wuhuizuo --- .../configs/triggers/bindings/github-branch-create.yaml | 2 +- .../configs/triggers/bindings/github-branch-push.yaml | 6 +++--- .../tekton/configs/triggers/bindings/github-tag-create.yaml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml b/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml index 329b35a75..a120f04a2 100644 --- a/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml +++ b/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml @@ -7,4 +7,4 @@ spec: - name: git-url value: $(body.repository.url) - name: git-ref - value: $(body.ref) + value: $(body.ref.substringAfter('refs/heads/')) # "refs/heads/xxx" => "xxx" diff --git a/apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml b/apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml index 5050159df..9cc188547 100644 --- a/apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml +++ b/apps/prod/tekton/configs/triggers/bindings/github-branch-push.yaml @@ -5,8 +5,8 @@ metadata: spec: params: - name: git-url - value: $(body.repository.url) + value: $(body.repository.clone_url) - name: git-revision - value: $(body.head_commit.id) + value: $(body.after) - name: git-ref - value: $(body.ref) + value: $(body.ref.substringAfter('refs/heads/')) # "refs/heads/main" => "main" diff --git a/apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml b/apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml index 493d470ea..f818e9276 100644 --- a/apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml +++ b/apps/prod/tekton/configs/triggers/bindings/github-tag-create.yaml @@ -5,8 +5,8 @@ metadata: spec: params: - name: git-url - value: $(body.repository.url) + value: $(body.repository.clone_url) - name: git-ref value: $(body.ref) - name: git-tag - value: $(body.ref) + value: $(body.ref.substringAfter('refs/tags/')) # "refs/tags/vX.Y.Z" => "vX.Y.Z" From bd325c56f171b43942a6bd987fe7e6d00eeb1ec4 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Tue, 24 Oct 2023 17:57:51 +0800 Subject: [PATCH 2/6] Update apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml --- .../tekton/configs/triggers/bindings/github-branch-create.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml b/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml index a120f04a2..1a5f74b3e 100644 --- a/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml +++ b/apps/prod/tekton/configs/triggers/bindings/github-branch-create.yaml @@ -7,4 +7,4 @@ spec: - name: git-url value: $(body.repository.url) - name: git-ref - value: $(body.ref.substringAfter('refs/heads/')) # "refs/heads/xxx" => "xxx" + value: $(body.ref.substringAfter('refs/heads/')) # "refs/heads/xxx" => "xxx" From 01333006077ba5919ea4eca19bd96bcb024585e8 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Tue, 24 Oct 2023 17:53:47 +0800 Subject: [PATCH 3/6] feat(apps/prod/tekton/configs): add task and triggers for auto sync OWNERS for hotfix branches Automatically create pull requests when hot fix branch is created. Signed-off-by: wuhuizuo --- .../tasks/create-pr-to-sync-owners.yaml | 59 +++++++++++++++++++ .../tekton/configs/tasks/kustomization.yaml | 11 ++-- ...anch-create-product-components-hotfix.yaml | 38 ++++++++++++ ...eate-branch-product-components-hotfix.yaml | 36 +++++++++++ 4 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 apps/prod/tekton/configs/tasks/create-pr-to-sync-owners.yaml create mode 100644 apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml create mode 100644 apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml diff --git a/apps/prod/tekton/configs/tasks/create-pr-to-sync-owners.yaml b/apps/prod/tekton/configs/tasks/create-pr-to-sync-owners.yaml new file mode 100644 index 000000000..18c9f63fc --- /dev/null +++ b/apps/prod/tekton/configs/tasks/create-pr-to-sync-owners.yaml @@ -0,0 +1,59 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: create-pr-to-sync-owners + labels: + app.kubernetes.io/version: "0.1" + annotations: + tekton.dev/pipelines.minVersion: "0.29.0" + tekton.dev/categories: Deno + tekton.dev/tags: deno + tekton.dev/displayName: "sync owners" + tekton.dev/platforms: "linux/amd64" +spec: + description: >- + Create pull request to sync `OWNERS`` file to github repository branch. + params: + - name: git-url + description: repository clone url + type: string + - name: branch + description: branch name + type: string + steps: + - name: clone-community-repo + image: bitnami/git:latest + workingDir: /workspace + script: | + git clone https://github.com/pingcap/community.git --branch master + - name: create-pull-request + image: denoland/deno:1.37.2 + workingDir: /workspace/community + script: | + owner=$(basename $(dirname $(params.git-url))) + repo=$(basename $(params.git-url) .git) + + echo "url=$(params.git-url)" + echo "branch=$(params.branch)" + echo "owner=${owner}" + echo "repo=${repo}" + + deno run --allow-all https://github.com/PingCAP-QE/ci/raw/main/scripts/pingcap/community/update-prow-owners.ts \ + --force \ + --owner=${owner} \ + --github_private_token=$(cat /etc/github/token) \ + --only_repo.repo=${repo} \ + --only_repo.branch=$(params.branch) \ + --inputs=teams/diagnostic/membership.json \ + --inputs=teams/docs/membership.json \ + --inputs=teams/tiunimanager/membership.json \ + --inputs=teams/tidb/membership.json \ + --inputs=teams/tiflash/membership.json \ + --inputs=teams/tiup/membership.json \ + --inputs=teams/kubernetes/membership.json \ + --inputs=teams/migration/membership.json \ + --inputs=teams/bigdata/membership.json + workspaces: + - name: github + description: Must includes a key `token` + mountPath: /etc/github diff --git a/apps/prod/tekton/configs/tasks/kustomization.yaml b/apps/prod/tekton/configs/tasks/kustomization.yaml index 8b768c803..4fad5cb7a 100644 --- a/apps/prod/tekton/configs/tasks/kustomization.yaml +++ b/apps/prod/tekton/configs/tasks/kustomization.yaml @@ -2,14 +2,15 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: ee-cd resources: + - create-pr-to-sync-owners.yaml + - echo.yaml - git-clone.yaml - github-set-status.yaml - golang-build.yaml - golang-test.yaml - - kubernetes-actions.yaml - - echo.yaml - - ko-test-infra.yaml - - multi-arch-image-push.yaml # multi-arch-image-push task - - https://raw.githubusercontent.com/tektoncd/catalog/main/task/ko/0.1/ko.yaml # ko task - https://raw.githubusercontent.com/tektoncd/catalog/main/task/kaniko/0.6/kaniko.yaml # kaniko task + - https://raw.githubusercontent.com/tektoncd/catalog/main/task/ko/0.1/ko.yaml # ko task - https://raw.githubusercontent.com/tektoncd/catalog/main/task/tkn/0.4/tkn.yaml + - ko-test-infra.yaml + - kubernetes-actions.yaml + - multi-arch-image-push.yaml # multi-arch-image-push task diff --git a/apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml b/apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml new file mode 100644 index 000000000..9adcb5ed1 --- /dev/null +++ b/apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml @@ -0,0 +1,38 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: TriggerTemplate +metadata: + name: branch-create-product-components-hotfix +spec: + params: + - name: git-url + description: The git repository full url + - name: git-ref + description: The git ref + default: main + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: TaskRun + metadata: + generateName: branch-create-product-components-hotfix-run- + annotations: + "tekton.dev/git-status": "true" + "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: + params: + - name: git-url + value: $(tt.params.git-url) + - name: branch + value: git-ref + taskRef: + kind: Task + name: create-pr-to-sync-owners + podTemplate: + nodeSelector: + kubernetes.io/arch: "amd64" + workspaces: + - name: github + secret: + secretName: github diff --git a/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml b/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml new file mode 100644 index 000000000..371ca210e --- /dev/null +++ b/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml @@ -0,0 +1,36 @@ +apiVersion: triggers.tekton.dev/v1beta1 +kind: Trigger +metadata: + name: branch-create-product-components-hotfix + labels: + type: github-branch-create +spec: + interceptors: + - name: filter on repo owner and name + ref: + name: cel + params: + - name: filter + value: >- + body.repository.owner.login == 'pingcap' && body.repository.name in [ + 'tidb', + 'tiflash', + 'tiflow', + 'tidb-binlog', + 'tidb-dashboard', + 'tidb-tools' + ] + # filter git refs that match regexp: ^refs/heads/release-\d+\.\d+-\d+-v\d+\.\d+\.\d+$ + # example values of `body.ref`: + # refs/heads/release-6.5-20231020-v6.5.5 + - name: filter on branch names + ref: + name: cel + params: + - name: filter + value: >- + body.ref.matches('^refs/heads/release-\\d+\\.\\d+-\\d+-v\\d+\\.\\d+\\.\\d+$') + bindings: + - ref: github-branch-create + template: + ref: branch-create-product-components-hotfix From 302186d1c72c298493528cd91332ea06652af5fc Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Wed, 25 Oct 2023 10:50:37 +0800 Subject: [PATCH 4/6] Update apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml --- .../templates/branch-create-product-components-hotfix.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml b/apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml index 9adcb5ed1..264049fac 100644 --- a/apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml +++ b/apps/prod/tekton/configs/triggers/templates/branch-create-product-components-hotfix.yaml @@ -25,7 +25,7 @@ spec: - name: git-url value: $(tt.params.git-url) - name: branch - value: git-ref + value: $(tt.params.git-ref) taskRef: kind: Task name: create-pr-to-sync-owners From 74bb74fce3fe6839637457ee3608aab1ed994ca0 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Wed, 25 Oct 2023 10:56:45 +0800 Subject: [PATCH 5/6] Update apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml --- .../triggers/create-branch-product-components-hotfix.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml b/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml index 371ca210e..af403f5da 100644 --- a/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml +++ b/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml @@ -23,6 +23,7 @@ spec: # filter git refs that match regexp: ^refs/heads/release-\d+\.\d+-\d+-v\d+\.\d+\.\d+$ # example values of `body.ref`: # refs/heads/release-6.5-20231020-v6.5.5 + # refs/heads/release-6.5-20231020-v6.5.5-1 - name: filter on branch names ref: name: cel From 83f6e833c7d5c02fd1149a0f01f5c2e6d79410c1 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Wed, 25 Oct 2023 11:03:29 +0800 Subject: [PATCH 6/6] Update apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml --- .../triggers/create-branch-product-components-hotfix.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml b/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml index af403f5da..b9738b631 100644 --- a/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml +++ b/apps/prod/tekton/configs/triggers/triggers/create-branch-product-components-hotfix.yaml @@ -30,7 +30,8 @@ spec: params: - name: filter value: >- - body.ref.matches('^refs/heads/release-\\d+\\.\\d+-\\d+-v\\d+\\.\\d+\\.\\d+$') + body.ref.matches('^refs/heads/release-\\d+\\.\\d+-\\d+-v\\d+\\.\\d+\\.\\d+(-.+)?$') + bindings: - ref: github-branch-create template: