-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pingcap/ng-monitoring): auto update submodule in monitoring (#2823)
When ng-monitoring updated. Signed-off-by: wuhuizuo <[email protected]> Signed-off-by: wuhuizuo <[email protected]>
- Loading branch information
Showing
6 changed files
with
112 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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? | ||
|
@@ -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( | ||
|
@@ -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], | ||
}); | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|