Skip to content

Commit 5a4e898

Browse files
authored
Add release workflow (#2191)
1 parent ab65b20 commit 5a4e898

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Prepare web-features release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
semverLevel:
7+
description: "Bump to semver level"
8+
required: true
9+
type: choice
10+
default: "minor"
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
jobs:
17+
open_pr:
18+
name: Open PR
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- run: |
23+
git config user.name github-actions
24+
git config user.email [email protected]
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version-file: .node-version
28+
cache: npm
29+
- run: npm ci
30+
- name: ./scripts/release.ts init
31+
run: npx tsx ./scripts/release.ts init --target-repo=$REPO --reviewers=$ACTOR $SEMVER_LEVEL
32+
env:
33+
ACTOR: ${{ github.actor }}
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
REPO: ${{ github.repository }}
36+
SEMVER_LEVEL: ${{ inputs.semverLevel }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
⚠ Caution! Merging this PR triggers a release. Continue reading before merging. ⚠
1+
This is a generated release pull request. Don't merge if you're not ready to carry out the release.

scripts/release.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ yargs(process.argv.slice(2))
6262
choices: semverChoices,
6363
default: "patch",
6464
})
65+
.option("reviewers", {
66+
describe: "Comma-separated list of users to request reviews from",
67+
nargs: 1,
68+
})
6569
.demandOption("semverlevel", "You must provide a semver level");
6670
},
6771
handler: init,
@@ -87,6 +91,10 @@ function init(args) {
8791
logger.debug(checkoutCmd);
8892
execSync(checkoutCmd);
8993

94+
const { version: previousVersion } = readPackageJSON(
95+
packages["web-features"],
96+
);
97+
9098
// Bump version (no tag)
9199
const newVersion = bumpVersion(args.semverlevel);
92100

@@ -98,13 +106,13 @@ function init(args) {
98106
// Create PR
99107
const title = [pullTitleBase, newVersion].join("");
100108
logger.info(`Creating PR: ${title}`);
101-
const reviewer = "ddbeck";
102-
const body = makePullBody(diff);
109+
const reviewers = args.reviewers.split(",");
110+
const body = makePullBody(newVersion, previousVersion);
103111

104112
const pullRequestCmd = [
105113
"gh pr create",
106114
`--title="${title}"`,
107-
`--reviewer="${reviewer}"`,
115+
...reviewers.map((r) => `--reviewer=${r}`),
108116
`--body-file=-`,
109117
`--base="main"`,
110118
`--head="${releaseBranch}"`,
@@ -132,15 +140,31 @@ function bumpVersion(semverlevel: typeof semverChoices): string {
132140
return version;
133141
}
134142

135-
function makePullBody(diff: string) {
143+
function makePullBody(newVersion: string, previousVersion: string) {
144+
// https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#generate-release-notes-content-for-a-release
145+
const relnotesCmd = [
146+
"gh",
147+
"api",
148+
"--method POST",
149+
`-H "Accept: application/vnd.github+json"`,
150+
`-H "X-GitHub-Api-Version: 2022-11-28"`,
151+
"/repos/{owner}/{repo}/releases/generate-notes",
152+
`-f "tag_name=v${newVersion}"`,
153+
`-f "target_commitish=main"`,
154+
`-f "previous_tag_name=v${previousVersion}"`,
155+
].join(" ");
156+
const relNotes = execSync(relnotesCmd, {
157+
cwd: packages["web-features"],
158+
encoding: "utf-8",
159+
});
160+
const relNotesLines = JSON.parse(relNotes).body.split("\n");
161+
136162
const bodyFile = fileURLToPath(
137163
new URL("release-pull-description.md", import.meta.url),
138164
);
139165
const body = [
140166
readFileSync(bodyFile, { encoding: "utf-8" }),
141-
"```diff",
142-
diff,
143-
"```",
167+
...relNotesLines,
144168
].join("\n");
145169
return body;
146170
}

0 commit comments

Comments
 (0)