From 52f1d8cba973577a9c026a00c2fb14cc91a77679 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Mon, 14 Oct 2024 20:22:09 +0800 Subject: [PATCH 1/3] chore: add generate release pr scripts --- CONTRIBUTING.md | 10 ++-- package.json | 1 + scripts/generateReleasePr.mjs | 96 +++++++++++++++++++++++++++++++++++ tests/README.md | 2 +- 4 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 scripts/generateReleasePr.mjs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2265ffe9..a11ed1df5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. 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. @@ -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 | diff --git a/package.json b/package.json index cd53efb3c..7c8ce591b 100644 --- a/package.json +++ b/package.json @@ -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", "lint": "biome check . --diagnostic-level=warn && pnpm run check-spell", "prebundle": "nx run-many -t prebundle", "prepare": "pnpm run build && simple-git-hooks", diff --git a/scripts/generateReleasePr.mjs b/scripts/generateReleasePr.mjs new file mode 100644 index 000000000..c51993927 --- /dev/null +++ b/scripts/generateReleasePr.mjs @@ -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'; + + 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(); diff --git a/tests/README.md b/tests/README.md index 1fbcf687a..5aaaf4ecf 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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 | 🟢 | | From bf87a72c45b624082aee0f7641f773cb0e852700 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 15 Oct 2024 13:03:02 +0800 Subject: [PATCH 2/3] chore: update --- .pnpmfile.cjs | 11 +++++++++++ package.json | 5 +++-- pnpm-lock.yaml | 14 ++++++++++++++ scripts/generateReleasePr.mjs | 26 ++++++++++++++++++-------- 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 .pnpmfile.cjs diff --git a/.pnpmfile.cjs b/.pnpmfile.cjs new file mode 100644 index 000000000..26f21d8cc --- /dev/null +++ b/.pnpmfile.cjs @@ -0,0 +1,11 @@ +module.exports = { + hooks: { + readPackage: (pkg) => { + if (pkg.name === 'zx') { + // zx use "@types/node": ">=20" as optionalDependencies, which may bring some unexpected updates in other packages + delete pkg.optionalDependencies['@types/node']; + } + return pkg; + }, + }, +}; diff --git a/package.json b/package.json index 7c8ce591b..cd7776ac6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "changeset": "changeset", "check-dependency-version": "check-dependency-version-consistency .", "check-spell": "pnpx cspell", - "generate-release-pr": "npx zx scripts/generateReleasePr.mjs", + "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", @@ -55,7 +55,8 @@ "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", "engines": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a00f07fa4..ca3a04e8b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,8 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +pnpmfileChecksum: sirncs5aff6cpwccwwvtlwwvli + importers: .: @@ -53,6 +55,9 @@ importers: vitest: specifier: ^2.1.2 version: 2.1.2(@types/node@18.19.39)(terser@5.31.6) + zx: + specifier: ^8.1.9 + version: 8.1.9 examples/express-plugin: devDependencies: @@ -4809,6 +4814,11 @@ packages: zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} + zx@8.1.9: + resolution: {integrity: sha512-UHuLHphHmsBYKkAchkSrEN4nzDyagafqC9HUxtc1J7eopaScW6H9dsLJ1lmkAntnLtDTGoM8fa+jrJrXiIfKFA==} + engines: {node: '>= 12.17.0'} + hasBin: true + snapshots: '@alloc/quick-lru@5.2.0': {} @@ -9588,3 +9598,7 @@ snapshots: yocto-queue@1.1.1: {} zwitch@2.0.4: {} + + zx@8.1.9: + optionalDependencies: + '@types/fs-extra': 11.0.4 diff --git a/scripts/generateReleasePr.mjs b/scripts/generateReleasePr.mjs index c51993927..d30df2900 100644 --- a/scripts/generateReleasePr.mjs +++ b/scripts/generateReleasePr.mjs @@ -2,14 +2,11 @@ import fs from 'node:fs/promises'; import path from 'node:path'; +import { parseArgs } from 'node:util'; 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(), @@ -56,20 +53,33 @@ async function main() { const currentVersion = await getCurrentVersion(); console.log(chalk.blue(`Current version: ${currentVersion}`)); - // 2. Determine bump type - const bumpType = bumpTypeArgs ? bumpTypeArgs.split('=')[1] : 'patch'; + // 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); - const branchName = `release-v${nextVersion}`; + 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}`)); - // 3. Create and switch to new branch await $`git checkout -b ${branchName}`; // 4. Generate changeset file From 228141b8f0808ca8606652591ec9f644cd11927e Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 15 Oct 2024 13:34:52 +0800 Subject: [PATCH 3/3] chore: update --- .pnpmfile.cjs | 11 ----------- package.json | 7 ++++++- pnpm-lock.yaml | 3 ++- 3 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 .pnpmfile.cjs diff --git a/.pnpmfile.cjs b/.pnpmfile.cjs deleted file mode 100644 index 26f21d8cc..000000000 --- a/.pnpmfile.cjs +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - hooks: { - readPackage: (pkg) => { - if (pkg.name === 'zx') { - // zx use "@types/node": ">=20" as optionalDependencies, which may bring some unexpected updates in other packages - delete pkg.optionalDependencies['@types/node']; - } - return pkg; - }, - }, -}; diff --git a/package.json b/package.json index cd7776ac6..9119413be 100644 --- a/package.json +++ b/package.json @@ -58,9 +58,14 @@ "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": "-" + } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ca3a04e8b..b4c5692ef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,7 +4,8 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false -pnpmfileChecksum: sirncs5aff6cpwccwwvtlwwvli +overrides: + zx>@types/node: '-' importers: