Skip to content

Commit c4c1a0d

Browse files
committed
chore: add generate release pr scripts
1 parent 1ca47fd commit c4c1a0d

File tree

4 files changed

+104
-5
lines changed

4 files changed

+104
-5
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: 1 addition & 0 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": "npx 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",

scripts/generateReleasePr.mjs

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