Skip to content

Commit dafc21a

Browse files
authored
Adds script to list version bump details (#528)
* Adds list-pr-labels script * More doc * Adds cumulus repo * Adds print version bump script + action * Adds github token * Fixes list pr labels link to repos * Better logs for list pr script
1 parent 54e8e09 commit dafc21a

File tree

7 files changed

+759
-7
lines changed

7 files changed

+759
-7
lines changed

.github/workflows/version-bump.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Create version bump ticket
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
from:
6+
description: "Polkadot version to bump from"
7+
required: true
8+
to:
9+
description: "Polkadot version to bump to"
10+
required: true
11+
12+
jobs:
13+
create_bump_ticket:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
- name: Use Node.js 14.x
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: 14.x
22+
- name: Generate version bump issue
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
run: |
26+
cd tools
27+
yarn install
28+
yarn --silent run print-version-bump-info --from ${{ github.event.inputs.from }} --to ${{ github.event.inputs.to }} | tee ../version-bump.md
29+
- name: Create version bump issue
30+
uses: peter-evans/create-issue-from-file@v3
31+
with:
32+
title: Update substrate/polkadot/cumulus from ${{ github.event.inputs.from }} to ${{ github.event.inputs.to }}
33+
content-filepath: ./version-bump.md
34+
labels: |
35+
automated issue

tools/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,41 @@ For the default configuration, you can access through polkadotjs:
177177
178178
2021-06-06 04:28:52 Building chain spec
179179
```
180+
181+
## Listing dependency pull request by labels
182+
183+
Using script [github/list-pr-labels.ts]:
184+
185+
```
186+
npm run list-pull-request-labels -- --from polkadot-v0.9.4 --to polkadot-v0.9.5 --repo paritytech/substrate
187+
```
188+
189+
### Parameters
190+
191+
```
192+
Options:
193+
--version Show version number [boolean]
194+
--from commit-sha/tag of range start [string] [required]
195+
--to commit-sha/tag of range end [string] [required]
196+
--repo which repository to read [string] [required]
197+
[choices: "paritytech/substrate", "paritytech/polkadot"]
198+
--only-label filter specific labels (using grep) [array]
199+
--help Show help [boolean]
200+
```
201+
202+
### Expected output
203+
204+
```
205+
> npm run list-pr-labels -- --from polkadot-v0.9.4 --to polkadot-v0.9.5 --repo paritytech/substrate --only-label runtime
206+
207+
found 55 total commits in https://github.com/paritytech/substrate/compare/polkadot-v0.9.4...polkadot-v0.9.5
208+
===== E1-runtimemigration
209+
(paritytech/substrate#9061) Migrate pallet-randomness-collective-flip to pallet attribute macro
210+
===== B7-runtimenoteworthy
211+
(paritytech/substrate#7778) Named reserve
212+
(paritytech/substrate#8955) update ss58 type to u16
213+
(paritytech/substrate#8909) contracts: Add new `seal_call` that offers new features
214+
(paritytech/substrate#9083) Migrate pallet-staking to pallet attribute macro
215+
(paritytech/substrate#9085) Enforce pub calls in pallets
216+
(paritytech/substrate#8912) staking/election: prolonged era and emergency mode for governance submission.
217+
```

tools/github/github-utils.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Octokit } from "octokit";
2+
3+
// Typescript 4 will support it natively, but not yet :(
4+
type Await<T> = T extends PromiseLike<infer U> ? U : T;
5+
type Commits = Await<ReturnType<Octokit["rest"]["repos"]["compareCommits"]>>["data"]["commits"];
6+
7+
export async function getCommitAndLabels(
8+
octokit: Octokit,
9+
owner: string,
10+
repo: string,
11+
previousTag: string,
12+
newTag: string
13+
) {
14+
let commits: Commits = [];
15+
let more = true;
16+
let page = 0;
17+
while (more) {
18+
const compare = await octokit.rest.repos.compareCommits({
19+
owner,
20+
repo,
21+
base: previousTag,
22+
head: newTag,
23+
per_page: 200,
24+
page,
25+
});
26+
commits = commits.concat(compare.data.commits);
27+
more = compare.data.commits.length == 200;
28+
page++;
29+
}
30+
31+
const prByLabels = {};
32+
for (const commit of commits) {
33+
const prs = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
34+
owner,
35+
repo,
36+
commit_sha: commit.sha,
37+
});
38+
for (const pr of prs.data) {
39+
if (pr.labels && pr.labels.length > 0) {
40+
for (const label of pr.labels) {
41+
prByLabels[label.name] = prByLabels[label.name] || [];
42+
prByLabels[label.name].push(pr);
43+
}
44+
} else {
45+
prByLabels[""] = prByLabels[""] || [];
46+
prByLabels[""].push(pr);
47+
}
48+
}
49+
}
50+
return {
51+
prByLabels,
52+
commits,
53+
};
54+
}

tools/github/list-pr-labels.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Octokit } from "octokit";
2+
import yargs from "yargs";
3+
import { getCommitAndLabels } from "./github-utils";
4+
5+
async function listPrByLabels(
6+
octokit: Octokit,
7+
owner: string,
8+
repo: string,
9+
previousTag: string,
10+
newTag: string,
11+
filters: string[],
12+
excludeList: string[]
13+
) {
14+
const { commits, prByLabels } = await getCommitAndLabels(
15+
octokit,
16+
owner,
17+
repo,
18+
previousTag,
19+
newTag
20+
);
21+
const filterRegs = filters && filters.map((f) => new RegExp(f));
22+
const excludeRegs = excludeList && excludeList.map((f) => new RegExp(f));
23+
24+
console.log(
25+
`found ${commits.length} total commits in ` +
26+
`https://github.com/${owner}/${repo}/compare/${previousTag}...${newTag}`
27+
);
28+
29+
for (const labelName of Object.keys(prByLabels).sort().reverse()) {
30+
if (filterRegs && !filterRegs.some((f) => f.test(labelName))) {
31+
continue;
32+
}
33+
if (excludeRegs && excludeRegs.some((f) => f.test(labelName))) {
34+
continue;
35+
}
36+
console.log(`===== ${labelName}`);
37+
for (const pr of prByLabels[labelName]) {
38+
console.log(` ${`(${owner}/${repo}#${pr.number}) ${pr.title}`}`);
39+
}
40+
}
41+
}
42+
43+
async function main() {
44+
const argv = yargs(process.argv.slice(2))
45+
.usage("Usage: npm run list-pr-labels [args]")
46+
.version("1.0.0")
47+
.options({
48+
from: {
49+
type: "string",
50+
describe: "commit-sha/tag of range start",
51+
},
52+
to: {
53+
type: "string",
54+
describe: "commit-sha/tag of range end",
55+
},
56+
repo: {
57+
type: "string",
58+
choices: ["paritytech/substrate", "paritytech/polkadot", "paritytech/cumulus"],
59+
describe: "which repository to read",
60+
},
61+
"only-label": {
62+
type: "array",
63+
describe: "keep only specific labels (using grep)",
64+
},
65+
"exclude-label": {
66+
type: "array",
67+
alias: "e",
68+
describe: "exclude specific labels (using grep)",
69+
},
70+
})
71+
.demandOption(["from", "to", "repo"])
72+
.help().argv;
73+
74+
const octokit = new Octokit({
75+
auth: process.env.GITHUB_TOKEN || undefined,
76+
});
77+
78+
listPrByLabels(
79+
octokit,
80+
argv.repo.split("/")[0],
81+
argv.repo.split("/")[1],
82+
argv.from,
83+
argv.to,
84+
argv["only-label"] as string[],
85+
argv["exclude-label"] as string[]
86+
);
87+
}
88+
89+
main();
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { Octokit } from "octokit";
2+
import yargs from "yargs";
3+
import { getCommitAndLabels } from "./github-utils";
4+
5+
async function printInfo(octokit: Octokit, previousVersion: string, nextVersion: string) {
6+
const owner = "paritytech";
7+
const prefixes = {
8+
substrate: "polkadot-",
9+
polkadot: "release-",
10+
cumulus: "polkadot-",
11+
};
12+
console.log(`# Description\n`);
13+
console.log(`This ticket is automatically generated using\n`);
14+
console.log("```");
15+
console.log(`$ yarn run print-version-bump-info --from ${previousVersion} --to ${nextVersion}`);
16+
console.log("```");
17+
18+
const prInfoByLabels = {};
19+
for (const repo of Object.keys(prefixes)) {
20+
const previousTag = `${prefixes[repo]}${previousVersion}`;
21+
const nextTag = `${prefixes[repo]}${nextVersion}`;
22+
23+
const previousCommit = await octokit.rest.git.getCommit({
24+
owner,
25+
repo,
26+
commit_sha: (
27+
await octokit.rest.git.getTree({
28+
owner,
29+
repo,
30+
tree_sha: previousTag,
31+
})
32+
).data.sha,
33+
});
34+
const nextCommit = await octokit.rest.git.getCommit({
35+
owner,
36+
repo,
37+
commit_sha: (
38+
await octokit.rest.git.getTree({
39+
owner,
40+
repo,
41+
tree_sha: nextTag,
42+
})
43+
).data.sha,
44+
});
45+
console.log(
46+
`\n## ${repo} (${previousCommit.data.author.date.slice(
47+
0,
48+
10
49+
)} -> ${nextCommit.data.author.date.slice(0, 10)})\n`
50+
);
51+
const { commits, prByLabels } = await getCommitAndLabels(
52+
octokit,
53+
owner,
54+
repo,
55+
previousTag,
56+
nextTag
57+
);
58+
console.log(`https://github.com/${owner}/${repo}/compare/${previousTag}...${nextTag}`);
59+
console.log("```");
60+
console.log(` from: ${previousCommit.data.sha}`);
61+
console.log(` to: ${nextCommit.data.sha}`);
62+
console.log(` commits: ${commits.length}`);
63+
console.log("```");
64+
65+
for (const label of Object.keys(prByLabels)) {
66+
prInfoByLabels[label] = (prInfoByLabels[label] || []).concat(
67+
prByLabels[label].map((pr) => {
68+
return ` ${`(${owner}/${repo}#${pr.number}) ${pr.title}`}`;
69+
})
70+
);
71+
}
72+
}
73+
74+
console.log(`\n# Important commits by label\n`);
75+
const excludeRegs = [
76+
/D5-nicetohaveaudit/,
77+
/D3-trivia/,
78+
/D2-notlive/,
79+
/D1-audited/,
80+
/C[01234]-/,
81+
/B0-silent/,
82+
/A[0-9]-/,
83+
];
84+
for (const labelName of Object.keys(prInfoByLabels).sort().reverse()) {
85+
if (excludeRegs.some((f) => f.test(labelName))) {
86+
continue;
87+
}
88+
console.log(`\n### ${labelName || "N/A"}\n`);
89+
for (const prInfo of prInfoByLabels[labelName]) {
90+
console.log(prInfo);
91+
}
92+
}
93+
}
94+
95+
async function main() {
96+
const argv = yargs(process.argv.slice(2))
97+
.usage("Usage: npm run print-version-deps [args]")
98+
.version("1.0.0")
99+
.options({
100+
from: {
101+
type: "string",
102+
describe: "commit-sha/tag of range start",
103+
},
104+
to: {
105+
type: "string",
106+
describe: "commit-sha/tag of range end",
107+
},
108+
})
109+
.demandOption(["from", "to"])
110+
.help().argv;
111+
112+
const octokit = new Octokit({
113+
auth: process.env.GITHUB_TOKEN || undefined,
114+
});
115+
116+
printInfo(octokit, argv.from, argv.to);
117+
}
118+
119+
main();

tools/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
{
22
"name": "moonbeam-tools",
33
"version": "0.0.1",
4+
"license": "GPL-3.0",
45
"dependencies": {
56
"@polkadot/api": "^4.12.1",
67
"@polkadot/util-crypto": "^6.6.1",
78
"bip39": "^3.0.3",
89
"eth-block-tracker": "^4.4.3",
910
"ethereumjs-wallet": "^1.0.0",
1011
"ethjs-provider-http": "^0.1.6",
12+
"octokit": "^1.0.6",
1113
"pkg": "^4.4.9",
1214
"polkadot-launch": "^1.6.1",
1315
"rlp": "^2.2.6",
1416
"solc": "^0.8.0",
1517
"truffle-privatekey-provider": "^1.5.0",
1618
"ts-node": "^8.10.1",
17-
"typescript": "^3.9.5",
19+
"typescript": "^3.9.10",
1820
"web3": "^1.2.9",
1921
"web3x": "^4.0.6",
2022
"yargs": "^17.0.1"
@@ -24,6 +26,8 @@
2426
},
2527
"scripts": {
2628
"package-moon-key": "node_modules/.bin/tsc moon-key.ts; node_modules/.bin/pkg -t node14 moon-key.js; rm moon-key.js",
27-
"launch": "ts-node launch"
29+
"launch": "ts-node launch",
30+
"list-pr-labels": "ts-node github/list-pr-labels.ts",
31+
"print-version-bump-info": "ts-node github/print-version-bump-info.ts"
2832
}
2933
}

0 commit comments

Comments
 (0)