Skip to content

chore: add generate release pr scripts #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ Repository maintainers can publish a new version of all packages to npm.

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

1. [Create release pull request](https://github.com/web-infra-dev/rslib/actions/workflows/release-pull-request.yml).
<!-- 1. [Create release pull request](https://github.com/web-infra-dev/rslib/actions/workflows/release-pull-request.yml). -->

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

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:

| Package | Link |
| ------------ | ------------------------------------------------- |
| @rspack/core | https://github.com/web-infra-dev/rspack/pull/7939 |
| Package | Link |
| ------------ | ------------------------------------------------------------ |
| @rspack/core | https://github.com/web-infra-dev/rspack/releases/tag/v1.0.10 |
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"changeset": "changeset",
"check-dependency-version": "check-dependency-version-consistency .",
"check-spell": "pnpx cspell",
"generate-release-pr": "zx scripts/generateReleasePr.mjs",
"lint": "biome check . --diagnostic-level=warn && pnpm run check-spell",
"prebundle": "nx run-many -t prebundle",
"prepare": "pnpm run build && simple-git-hooks",
Expand Down Expand Up @@ -54,11 +55,17 @@
"prettier-plugin-packagejson": "^2.5.3",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.6.3",
"vitest": "^2.1.2"
"vitest": "^2.1.2",
"zx": "^8.1.9"
},
"packageManager": "pnpm@9.9.0",
"packageManager": "pnpm@9.12.1",
"engines": {
"node": ">=18.0.0",
"pnpm": ">=9.0.0"
},
"pnpm": {
"overrides": {
"zx>@types/node": "-"
}
}
}
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions scripts/generateReleasePr.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env zx

import fs from 'node:fs/promises';
import path from 'node:path';
import { parseArgs } from 'node:util';
import { $, chalk } from 'zx';

$.verbose = false;

async function getCurrentVersion() {
const packageJsonPath = path.join(
process.cwd(),
'packages/core/package.json',
);
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
return packageJson.version;
}

async function getNextVersion(currentVersion, type) {
const [major, minor, patch] = currentVersion.split('.').map(Number);
switch (type) {
case 'patch':
return `${major}.${minor}.${patch + 1}`;
case 'minor':
return `${major}.${minor + 1}.0`;
case 'major':
return `${major + 1}.0.0`;
default:
throw new Error('Invalid version type');
}
}

async function generateChangesetFile(bumpType, nextVersion) {
const changesetDir = path.join(process.cwd(), '.changeset');
const timestamp = Date.now();
const filename = `${timestamp}-${bumpType}-release.md`;
const content = `---
"@rslib/core": ${bumpType}
---

Release version ${nextVersion}
`;

await fs.mkdir(changesetDir, { recursive: true });
await fs.writeFile(path.join(changesetDir, filename), content);

console.log(chalk.blue(`Generated changeset file: ${filename}`));
}

async function main() {
try {
// 1. Read the current version
const currentVersion = await getCurrentVersion();
console.log(chalk.blue(`Current version: ${currentVersion}`));

// 2. Determine bump type and next release version
const options = {
type: {
type: 'string',
short: 't',
default: 'patch',
},
};
const args = process.argv.slice(3);
const { values } = parseArgs({ args, options });

const bumpType = values.type;

if (!['major', 'minor', 'patch'].includes(bumpType)) {
console.error('Invalid bump type. Please select major, minor, or patch.');
process.exit(1);
}

console.log(chalk.blue(`Bump type: ${bumpType}`));

const nextVersion = await getNextVersion(currentVersion, bumpType);
console.log(chalk.blue(`Next version: ${nextVersion}`));

// 3. Create and switch to new branch
const branchName = `release-v${nextVersion}`;
console.log(chalk.blue(`Creating branch: ${branchName}`));

await $`git checkout -b ${branchName}`;

// 4. Generate changeset file
await generateChangesetFile(bumpType, nextVersion);

// 5. Run changeset version and pnpm install
await $`pnpm run changeset version`;
await $`pnpm install --ignore-scripts`;

// 6. Commit changes
await $`git add .`;
await $`git commit -m "Release v${nextVersion}"`;

// 7. Push to remote repo
await $`git push -u origin ${branchName}`;

console.log(chalk.green(`Successfully created and pushed ${branchName}`));
} catch (error) {
console.error(chalk.red(`Error: ${error.message}`));
process.exit(1);
}
}

main();
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Rslib will try to cover the common scenarios in the [integration test cases of M
| sourceDir | 🟢 | |
| sourceMap | 🟢 | |
| splitting | ⚪️ | |
| style | ⚪️ | |
| style | 🟡 | asset svgr in CSS / css banner and footer |
| target | 🟢 | |
| transformImport | 🟢 | |
| transformLodash | 🟢 | |
Expand Down
Loading