Skip to content

Commit 00ea944

Browse files
authored
chore: add generate release pr scripts (#289)
1 parent 9f1551f commit 00ea944

File tree

5 files changed

+137
-7
lines changed

5 files changed

+137
-7
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ Repository maintainers can publish a new version of all packages to npm.
129129

130130
Here are the steps to publish (we generally use CI for releases and avoid publishing npm packages locally):
131131

132-
1. [Create release pull request](https://github.com/web-infra-dev/rslib/actions/workflows/release-pull-request.yml).
132+
<!-- 1. [Create release pull request](https://github.com/web-infra-dev/rslib/actions/workflows/release-pull-request.yml). -->
133+
134+
1. Run `pnpm generate-release-pr` to create a release pull request.
133135
2. [Run the release action](https://github.com/web-infra-dev/rslib/actions/workflows/release.yml).
134136
3. [Generate the release notes](https://github.com/web-infra-dev/rslib/releases).
135137
4. Merge the release pull request.
@@ -138,6 +140,6 @@ Here are the steps to publish (we generally use CI for releases and avoid publis
138140

139141
The project is still in its early stages and under active development, so it possible dependents on Rsbuild or Rspack canary versions to test the latest features. The current versions are:
140142

141-
| Package | Link |
142-
| ------------ | ------------------------------------------------- |
143-
| @rspack/core | https://github.com/web-infra-dev/rspack/pull/7939 |
143+
| Package | Link |
144+
| ------------ | ------------------------------------------------------------ |
145+
| @rspack/core | https://github.com/web-infra-dev/rspack/releases/tag/v1.0.10 |

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"changeset": "changeset",
1414
"check-dependency-version": "check-dependency-version-consistency .",
1515
"check-spell": "pnpx cspell",
16+
"generate-release-pr": "zx scripts/generateReleasePr.mjs",
1617
"lint": "biome check . --diagnostic-level=warn && pnpm run check-spell",
1718
"prebundle": "nx run-many -t prebundle",
1819
"prepare": "pnpm run build && simple-git-hooks",
@@ -54,11 +55,17 @@
5455
"prettier-plugin-packagejson": "^2.5.3",
5556
"simple-git-hooks": "^2.11.1",
5657
"typescript": "^5.6.3",
57-
"vitest": "^2.1.2"
58+
"vitest": "^2.1.2",
59+
"zx": "^8.1.9"
5860
},
59-
"packageManager": "pnpm@9.9.0",
61+
"packageManager": "pnpm@9.12.1",
6062
"engines": {
6163
"node": ">=18.0.0",
6264
"pnpm": ">=9.0.0"
65+
},
66+
"pnpm": {
67+
"overrides": {
68+
"zx>@types/node": "-"
69+
}
6370
}
6471
}

pnpm-lock.yaml

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

scripts/generateReleasePr.mjs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env zx
2+
3+
import fs from 'node:fs/promises';
4+
import path from 'node:path';
5+
import { parseArgs } from 'node:util';
6+
import { $, chalk } from 'zx';
7+
8+
$.verbose = false;
9+
10+
async function getCurrentVersion() {
11+
const packageJsonPath = path.join(
12+
process.cwd(),
13+
'packages/core/package.json',
14+
);
15+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
16+
return packageJson.version;
17+
}
18+
19+
async function getNextVersion(currentVersion, type) {
20+
const [major, minor, patch] = currentVersion.split('.').map(Number);
21+
switch (type) {
22+
case 'patch':
23+
return `${major}.${minor}.${patch + 1}`;
24+
case 'minor':
25+
return `${major}.${minor + 1}.0`;
26+
case 'major':
27+
return `${major + 1}.0.0`;
28+
default:
29+
throw new Error('Invalid version type');
30+
}
31+
}
32+
33+
async function generateChangesetFile(bumpType, nextVersion) {
34+
const changesetDir = path.join(process.cwd(), '.changeset');
35+
const timestamp = Date.now();
36+
const filename = `${timestamp}-${bumpType}-release.md`;
37+
const content = `---
38+
"@rslib/core": ${bumpType}
39+
---
40+
41+
Release version ${nextVersion}
42+
`;
43+
44+
await fs.mkdir(changesetDir, { recursive: true });
45+
await fs.writeFile(path.join(changesetDir, filename), content);
46+
47+
console.log(chalk.blue(`Generated changeset file: ${filename}`));
48+
}
49+
50+
async function main() {
51+
try {
52+
// 1. Read the current version
53+
const currentVersion = await getCurrentVersion();
54+
console.log(chalk.blue(`Current version: ${currentVersion}`));
55+
56+
// 2. Determine bump type and next release version
57+
const options = {
58+
type: {
59+
type: 'string',
60+
short: 't',
61+
default: 'patch',
62+
},
63+
};
64+
const args = process.argv.slice(3);
65+
const { values } = parseArgs({ args, options });
66+
67+
const bumpType = values.type;
68+
69+
if (!['major', 'minor', 'patch'].includes(bumpType)) {
70+
console.error('Invalid bump type. Please select major, minor, or patch.');
71+
process.exit(1);
72+
}
73+
74+
console.log(chalk.blue(`Bump type: ${bumpType}`));
75+
76+
const nextVersion = await getNextVersion(currentVersion, bumpType);
77+
console.log(chalk.blue(`Next version: ${nextVersion}`));
78+
79+
// 3. Create and switch to new branch
80+
const branchName = `release-v${nextVersion}`;
81+
console.log(chalk.blue(`Creating branch: ${branchName}`));
82+
83+
await $`git checkout -b ${branchName}`;
84+
85+
// 4. Generate changeset file
86+
await generateChangesetFile(bumpType, nextVersion);
87+
88+
// 5. Run changeset version and pnpm install
89+
await $`pnpm run changeset version`;
90+
await $`pnpm install --ignore-scripts`;
91+
92+
// 6. Commit changes
93+
await $`git add .`;
94+
await $`git commit -m "Release v${nextVersion}"`;
95+
96+
// 7. Push to remote repo
97+
await $`git push -u origin ${branchName}`;
98+
99+
console.log(chalk.green(`Successfully created and pushed ${branchName}`));
100+
} catch (error) {
101+
console.error(chalk.red(`Error: ${error.message}`));
102+
process.exit(1);
103+
}
104+
}
105+
106+
main();

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Rslib will try to cover the common scenarios in the [integration test cases of M
3636
| sourceDir | 🟢 | |
3737
| sourceMap | 🟢 | |
3838
| splitting | ⚪️ | |
39-
| style | ⚪️ | |
39+
| style | 🟡 | asset svgr in CSS / css banner and footer |
4040
| target | 🟢 | |
4141
| transformImport | 🟢 | |
4242
| transformLodash | 🟢 | |

0 commit comments

Comments
 (0)