Skip to content

Commit

Permalink
feat(pingcap/ng-monitoring): auto update submodule in monitoring (#2823)
Browse files Browse the repository at this point in the history
When ng-monitoring updated.

Signed-off-by: wuhuizuo <[email protected]>

Signed-off-by: wuhuizuo <[email protected]>
  • Loading branch information
wuhuizuo authored Feb 27, 2024
1 parent 8ffd694 commit 4101faf
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 31 deletions.
3 changes: 2 additions & 1 deletion prow-jobs/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ configMapGenerator:
disableNameSuffixHash: true
files:
- pingcap-community-postsubmits.yaml
- pingcap-docs-latest-presubmits.yaml
- pingcap-docs-cn-latest-presubmits.yaml
- pingcap-docs-latest-presubmits.yaml
- pingcap-inc-enterprise-extensions-postsubmits.yaml
- pingcap-inc-enterprise-extensions-presubmits.yaml
- pingcap-monitoring-periodics.yaml
- pingcap-ng-monitoring-postsubmits.yaml
- pingcap-qe-ci-presubmits.yaml
- pingcap-tidb-engine-ext-latest-presubmits.yaml
- pingcap-tidb-engine-release-6.1-latest-presubmits.yaml
Expand Down
2 changes: 1 addition & 1 deletion prow-jobs/pingcap-community-postsubmits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ postsubmits:
spec:
containers:
- name: main
image: denoland/deno:1.37.2
image: denoland/deno:1.41.0
command: [deno, run, --allow-all, https://github.com/PingCAP-QE/ci/raw/main/scripts/pingcap/community/update-prow-owners.ts]
args:
- --owner=pingcap
Expand Down
8 changes: 4 additions & 4 deletions prow-jobs/pingcap-inc-enterprise-extensions-postsubmits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ postsubmits:
spec:
containers:
- name: main
image: denoland/deno:1.38.4
command: [deno, run, --allow-all, https://github.com/PingCAP-QE/ci/raw/main/scripts/pingcap-inc/enterprise-extensions/update-submodule-in-tidb.ts]
image: denoland/deno:1.41.0
command: [deno, run, --allow-all, https://github.com/PingCAP-QE/ci/raw/main/scripts/plugins/update-submodule.ts]
args:
- --github_private_token=$(GITHUB_API_TOKEN)
- --owner=pingcap
Expand Down Expand Up @@ -49,8 +49,8 @@ postsubmits:
spec:
containers:
- name: main
image: denoland/deno:1.38.4
command: [deno, run, --allow-all, https://github.com/PingCAP-QE/ci/raw/main/scripts/pingcap-inc/enterprise-extensions/update-submodule-in-tidb.ts]
image: denoland/deno:1.41.0
command: [deno, run, --allow-all, https://github.com/PingCAP-QE/ci/raw/main/scripts/plugins/update-submodule.ts]
args:
- --github_private_token=$(GITHUB_API_TOKEN)
- --owner=pingcap
Expand Down
73 changes: 73 additions & 0 deletions prow-jobs/pingcap-ng-monitoring-postsubmits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# struct ref: https://pkg.go.dev/k8s.io/test-infra/prow/config#Postsubmit
postsubmits:
pingcap/ng-monitoring:
- name: update-submodule-main-branch
decorate: true
decoration_config:
skip_cloning: true
skip_report: true
max_concurrency: 1
branches:
- ^main$
spec:
containers:
- name: main
image: denoland/deno:1.41.0
command: [deno, run, --allow-all, https://github.com/PingCAP-QE/ci/raw/main/scripts/plugins/update-submodule.ts]
args:
- --github_private_token=$(GITHUB_API_TOKEN)
- --owner=pingcap
- --repository=monitoring
- --base_ref=main
- --sub_owner=$(REPO_OWNER)
- --sub_repository=$(REPO_NAME)
- --base_ref=$(PULL_BASE_REF)
- --path=ng-monitoring
env:
- name: GITHUB_API_TOKEN
valueFrom:
secretKeyRef:
key: token
name: github-token
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: "1"
memory: 1Gi
- name: update-submodule-release-branches
decorate: true
decoration_config:
skip_cloning: true
skip_report: true
max_concurrency: 1
branches:
- ^release-[0-9]+[.][0-9]+$
spec:
containers:
- name: main
image: denoland/deno:1.41.0
command: [deno, run, --allow-all, https://github.com/PingCAP-QE/ci/raw/main/scripts/plugins/update-submodule.ts]
args:
- --github_private_token=$(GITHUB_API_TOKEN)
- --owner=pingcap
- --repository=monitoring
- --sub_owner=$(REPO_OWNER)
- --sub_repository=$(REPO_NAME)
- --base_ref=$(PULL_BASE_REF)
- --sub_ref=$(PULL_BASE_REF)
- --path=ng-monitoring
env:
- name: GITHUB_API_TOKEN
valueFrom:
secretKeyRef:
key: token
name: github-token
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: "1"
memory: 1Gi
2 changes: 1 addition & 1 deletion prow-jobs/pingcap-tidb-latest-presubmits-canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ presubmits:
kubernetes.io/arch: amd64
containers:
- name: check
image: denoland/deno:1.35.1
image: denoland/deno:1.41.0
command: [bash, -exec]
args:
- |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@ import * as flags from "https://deno.land/[email protected]/flags/mod.ts";
import { Octokit } from "npm:/[email protected]";

const HEAD_REF = `bot/update-submodule-${Date.now()}`;
const COMMIT_MESSAGE = `[SKIP-CI] update submodule exterprise-extensions
const DELAY_SECONDS_BEFORE_CREATE_PR = 5;
const DELAY_SECONDS_BEFORE_DEAL_PR = 5;

interface cliArgs {
owner: string;
repository: string;

base_ref: string;
sub_owner: string;
sub_repository: string;
sub_ref: string;
path: string;
github_private_token: string;
draft: boolean;
}

function newCommitMsg(submodulePath: string) {
return `[SKIP-CI] update submodule ${submodulePath}
skip-checks: true
`;
const PR_DESCRIPTION = `
}

function newPRDescription(submodulePath: string) {
return `
### What problem does this PR solve?
Problem Summary: update submodule exterprise-extensions
Problem Summary: update submodule ${submodulePath}
### What changed and how does it work?
Expand Down Expand Up @@ -51,20 +71,6 @@ None
\`\`\`
`;
const DELAY_SECONDS_BEFORE_CREATE_PR = 5;
const DELAY_SECONDS_BEFORE_DEAL_PR = 5;

interface cliArgs {
owner: string;
repository: string;

base_ref: string;
sub_owner: string;
sub_repository: string;
sub_ref: string;
path: string;
github_private_token: string;
draft: boolean;
}

async function createUpdateSubModulePR(
Expand Down Expand Up @@ -126,7 +132,7 @@ async function createUpdateSubModulePR(
const { data: newCommitData } = await octokit.rest.git.createCommit({
owner,
repo: repository,
message: COMMIT_MESSAGE,
message: newCommitMsg(path),
tree: treeData.sha,
parents: [headData.object.sha],
});
Expand All @@ -151,7 +157,7 @@ async function createUpdateSubModulePR(
owner,
repo: repository,
title: `${path}: update submodule`,
body: PR_DESCRIPTION,
body: newPRDescription(path),
head: HEAD_REF,
base: baseRef,
draft,
Expand All @@ -163,11 +169,6 @@ async function createUpdateSubModulePR(
return pr;
}

// Wait a moment, let's other plugins run firstly.
await new Promise((resolve) =>
setTimeout(resolve, DELAY_SECONDS_BEFORE_DEAL_PR * 1000)
);

async function postDealPR(
octokit: Octokit,
owner: string,
Expand Down Expand Up @@ -227,6 +228,12 @@ async function main(args: cliArgs) {
console.info(
`🫧 Post dealing for pull request: ${owner}/${repository}/${pullRequest.number} ...`,
);

// Wait a moment, let's other plugins run firstly.
await new Promise((resolve) =>
setTimeout(resolve, DELAY_SECONDS_BEFORE_DEAL_PR * 1000)
);

await postDealPR(
octokit,
owner,
Expand Down

0 comments on commit 4101faf

Please sign in to comment.