diff --git a/prow-jobs/kustomization.yaml b/prow-jobs/kustomization.yaml index 91c73b9432..2fd96d5d4a 100644 --- a/prow-jobs/kustomization.yaml +++ b/prow-jobs/kustomization.yaml @@ -123,6 +123,7 @@ configMapGenerator: - tikv_community_presubmits.yaml=tikv/community/presubmits.yaml - tikv_copr-test_latest-presubmits.yaml=tikv/copr-test/latest-presubmits.yaml - tikv_migration_latest-presubmits.yaml=tikv/migration/latest-presubmits.yaml + - tikv_pd_common-postsubmits.yaml=tikv/pd/common-postsubmits.yaml - tikv_pd_common-presubmits.yaml=tikv/pd/common-presubmits.yaml - tikv_pd_latest-presubmits-next-gen.yaml=tikv/pd/latest-presubmits-next-gen.yaml - tikv_pd_latest-presubmits.yaml=tikv/pd/latest-presubmits.yaml diff --git a/prow-jobs/tikv/pd/common-postsubmits.yaml b/prow-jobs/tikv/pd/common-postsubmits.yaml new file mode 100644 index 0000000000..aef23b4170 --- /dev/null +++ b/prow-jobs/tikv/pd/common-postsubmits.yaml @@ -0,0 +1,111 @@ +global_definitions: + branches: &branches + - ^master$ + - ^release-[0-9]+[.][0-9]+$ + skip_if_only_changed: &skip_if_only_changed "(\\.(md|png|jpeg|jpg|gif|svg|pdf)|Dockerfile|OWNERS|OWNERS_ALIASES)$" + +# struct ref: https://pkg.go.dev/sigs.k8s.io/prow/pkg/config#Postsubmit +postsubmits: + tikv/pd: + - name: auto-update-pd-gomod + decorate: true + decorate_config: + skip_cloning: true + run_if_changed: "^client/.*$" + branches: *branches + spec: + containers: + - name: build + image: golang:1.23 + command: [bash, -ceo, pipefail] + args: + - | + # clone tidb repo + git clone https://github.com/pingcap/tidb.git --branch "${PULL_BASE_REF}" ../tidb && cd ../tidb + + ###### update mods that comes from pd repo ##### + new_pd="$(go list -m github.com/tikv/pd/client@${PULL_BASE_REF} | awk '{print $1 "@" $2}')" + echo "new pd: $new_pd" + go mod edit --require "$new_pd" go.mod + + # fast exit if no change on go.mod file + git add go.mod + if git diff --cached --exit-code --name-status go.mod; then + echo "🤷 No changes happened." + exit 0 + fi + + # update go.sum + go mod tidy + git add go.mod go.sum + + # install `gh` tool + type -p curl >/dev/null || ( apt update && apt install curl -y) + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ + && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ + && apt update \ + && apt install gh -y + + # setup git + git config user.email "ti-community-prow-bot@tidb.io" + git config user.name "ti-chi-bot" + gh auth setup-git + + # commit and push the changes. + head_branch="fix/${PULL_BASE_REF}/update-dep-pd" + git checkout -b "$head_branch" + commit_msg="chore(deps): bump go mod github.com/tikv/pd/client" + git commit -m "$commit_msg" + git push -f --set-upstream origin "$head_branch" + + # create pull request + pr_desc=" + ### What problem does this PR solve? + + Auto generated by bot. + Issue Number: ref #${REF_ISSUE_NUM} + + ### Check List + + Tests + + - [x] Unit test + - [ ] Integration test + - [ ] Manual test (add detailed scripts or steps below) + - [ ] No need to test + > - [ ] I checked and no code files have been changed. + > + + ### Release note + + \`\`\`release-note + None + \`\`\` + " + gh pr create \ + --base $PULL_BASE_REF \ + --head "$head_branch" \ + --title "$commit_msg" \ + --body "$pr_desc" \ + --reviewer "$REVIEWER" \ + --assignee "$ASSIGNEE" + env: + - name: REVIEWER + value: "rleungx" + - name: ASSIGNEE + value: "rleungx" + - name: REF_ISSUE_NUM + value: "63997" + - name: GH_TOKEN + valueFrom: + secretKeyRef: + key: token + name: github-token + resources: + requests: + memory: 1Gi + cpu: "500m" + limits: + memory: 2Gi + cpu: "1"