Skip to content

Commit d50cb70

Browse files
committed
Convert release-branches.py to TypeScript
1 parent 7dd76e6 commit d50cb70

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pr-checks/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** The oldest supported major version of the CodeQL Action. */
2+
export const OLDEST_SUPPORTED_MAJOR_VERSION = 3;

pr-checks/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"yaml": "^2.8.2"
66
},
77
"devDependencies": {
8+
"@actions/core": "*",
89
"@types/node": "^20.19.9",
910
"tsx": "^4.21.0",
1011
"typescript": "^5.9.3"

pr-checks/release-branches.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env npx tsx
2+
3+
import { parseArgs } from "node:util";
4+
5+
import * as core from "@actions/core";
6+
7+
import { OLDEST_SUPPORTED_MAJOR_VERSION } from "./config";
8+
9+
async function main() {
10+
const { values: options } = parseArgs({
11+
options: {
12+
// The major version of the release
13+
"major-version": {
14+
type: "string",
15+
},
16+
// The most recent tag published to the repository
17+
"latest-tag": {
18+
type: "string",
19+
},
20+
},
21+
strict: true,
22+
});
23+
24+
if (options["major-version"] === undefined) {
25+
throw Error("--major-version is required");
26+
}
27+
if (options["latest-tag"] === undefined) {
28+
throw Error("--latest-tag is required");
29+
}
30+
31+
const majorVersion = Number.parseInt(options["major-version"].substring(1));
32+
const latestTag = options["latest-tag"];
33+
34+
console.log(`major_version: v${majorVersion}`);
35+
console.log(`latest_tag: ${latestTag}`);
36+
37+
// If this is a primary release, we backport to all supported branches,
38+
// so we check whether the major_version taken from the package.json
39+
// is greater than or equal to the latest tag pulled from the repo.
40+
// For example...
41+
// 'v1' >= 'v2' is False # we're operating from an older release branch and should not backport
42+
// 'v2' >= 'v2' is True # the normal case where we're updating the current version
43+
// 'v3' >= 'v2' is True # in this case we are making the first release of a new major version
44+
const latestTagMajor = Number.parseInt(latestTag.split(".")[0].substring(1));
45+
const considerBackports = majorVersion >= latestTagMajor;
46+
47+
core.setOutput("backport_source_branch", `releases/v${majorVersion}`);
48+
49+
const backportTargetBranches: string[] = [];
50+
51+
if (considerBackports) {
52+
for (let i = latestTagMajor - 1; i > 0; i--) {
53+
const branch_name = `releases/v${i}`;
54+
if (i >= OLDEST_SUPPORTED_MAJOR_VERSION) {
55+
backportTargetBranches.push(branch_name);
56+
}
57+
}
58+
}
59+
60+
core.setOutput(
61+
"backport_target_branches",
62+
JSON.stringify(backportTargetBranches),
63+
);
64+
65+
process.exit(0);
66+
}
67+
68+
// Only call `main` if this script was run directly.
69+
if (require.main === module) {
70+
void main();
71+
}

0 commit comments

Comments
 (0)