Skip to content
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

chore: add generate release pr scripts #289

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.
fi3ework marked this conversation as resolved.
Show resolved Hide resolved
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 |
1 change: 1 addition & 0 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": "npx zx scripts/generateReleasePr.mjs",
fi3ework marked this conversation as resolved.
Show resolved Hide resolved
"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
96 changes: 96 additions & 0 deletions scripts/generateReleasePr.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env zx

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

// Exit when error
$.verbose = false;

const args = process.argv.slice(2);
const bumpTypeArgs = args.find((arg) => arg.startsWith('--type='));

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
const bumpType = bumpTypeArgs ? bumpTypeArgs.split('=')[1] : 'patch';
fi3ework marked this conversation as resolved.
Show resolved Hide resolved

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

const nextVersion = await getNextVersion(currentVersion, bumpType);
const branchName = `release-v${nextVersion}`;

console.log(chalk.blue(`Creating branch: ${branchName}`));

// 3. Create and switch to new branch
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