diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0193fd714..6e4b4be5f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -166,21 +166,26 @@ $ XCODE_PROFILE=1 OKAM=/PATH/TO/umijs/marko/packages/bundler-mako/index.js bigfi ## Release -You can release mako with ci or locally. +Before release, please make sure everything is ok. -### Release with CI +```bash +$ just ready +``` -> NOTICE: _canary_ and _dev_ tags are now supported to be released with CI. +Open https://github.com/umijs/mako/actions?query=branch%3Amaster+event%3Apush to checkout the latest master push action with name "node-bind-build", and download the artifacts to packages/mako directory. If the artifacts has no commit hash in the name, you should add the commit hash manually. ```bash -# Make sure everything is ok -$ just ready -# Release with CI +$ git rev-parse HEAD +``` + +Then you can release the new version. + +``` +# Release @umijs/mako and @umijs/bundler-mako $ npm run release -# After released successful, you need to release bundler-mako manually. -$ npm run release:bundler-mako ``` -### Release Locally +After release, you must do 2 things: -Refer to https://yuque.antfin.com/mako/vz2gn4/vkp4qs8u4zcuxqoc for details. +- Release the new version on github +- Update the changelog in CHANGELOG.md and CHANGELOG_zh-CN.md diff --git a/package.json b/package.json index 24c29a888..8e5651539 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "test:e2e": "node scripts/test-e2e.mjs", "test:umi": "node scripts/test-e2e.mjs --fixtures e2e/fixtures.umi --umi", "test:hmr": "node scripts/test-hmr.mjs", - "release": "esno scripts/release.ts", + "release": "npm run release:mako && npm run release:bundler-mako", "release:mako": "pnpm --filter @umijs/mako release", "release:bundler-mako": "esno scripts/release-bundler-mako.ts", "release:rsc": "esno scripts/release-rsc.ts", diff --git a/packages/mako/package.json b/packages/mako/package.json index 40e8f50a6..84b2b589a 100644 --- a/packages/mako/package.json +++ b/packages/mako/package.json @@ -71,8 +71,6 @@ "universal": "napi universal", "version": "napi version", "release": "esno scripts/release.ts", - "release:quick": "esno scripts/quick-release.ts", - "release:build": "esno scripts/release.ts --build", "src:dev": "father dev", "src:build": "father build" }, @@ -87,4 +85,4 @@ "@umijs/mako-linux-x64-musl": "0.8.15" }, "repository": "git@github.com:umijs/mako.git" -} \ No newline at end of file +} diff --git a/packages/mako/scripts/quick-release.ts b/packages/mako/scripts/quick-release.ts deleted file mode 100644 index ccd12ffe0..000000000 --- a/packages/mako/scripts/quick-release.ts +++ /dev/null @@ -1,58 +0,0 @@ -import assert from 'assert'; -import 'zx/globals'; -import { - ensureGitStatus, - loadPkg, - pushToGit, - queryNewVersion, - rootPkgPath, - setNewVersionToBundlerMako, -} from './utils'; - -(async () => { - await run(); -})().catch((e) => { - console.error(e); - process.exit(1); -}); - -async function run() { - await ensureGitStatus(); - - const commitId = (await $`git rev-parse HEAD`).stdout.trim(); - const artifactsFile = `artifacts-${commitId}.zip`; - const hasArtifacts = fs.existsSync(path.join(process.cwd(), artifactsFile)); - assert(hasArtifacts, `${artifactsFile} not found in cwd`); - - const nodePkgPath = rootPkgPath(); - const nodePkg = loadPkg(nodePkgPath); - const { newVersion, tag, branch } = await queryNewVersion(nodePkg); - - nodePkg.version = newVersion; - fs.writeFileSync(nodePkgPath, JSON.stringify(nodePkg, null, 2) + '\n'); - - await build(); - await artifacts(artifactsFile); - - await $`npm publish --tag ${tag} --access public`; - - setNewVersionToBundlerMako(nodePkg.version); - - await pushToGit(nodePkg, branch); -} - -async function build() { - await $`rm -rf ./*.node`; - await $`find ./npm -name '*.node' | xargs rm -f`; - await $`rm -rf ./dist`; - - await $`pnpm run build`; - await $`pnpm run src:build`; - await $`pnpm run format`; -} - -async function artifacts(artifactsFile: string) { - await $`rm -rf *.node`; - await $`unzip ${artifactsFile}`; - await $`npm run artifacts:local`; -} diff --git a/packages/mako/scripts/release.ts b/packages/mako/scripts/release.ts index 12372f602..ccd12ffe0 100644 --- a/packages/mako/scripts/release.ts +++ b/packages/mako/scripts/release.ts @@ -1,3 +1,4 @@ +import assert from 'assert'; import 'zx/globals'; import { ensureGitStatus, @@ -9,11 +10,7 @@ import { } from './utils'; (async () => { - if (argv.build) { - await build(); - } else { - await run(); - } + await run(); })().catch((e) => { console.error(e); process.exit(1); @@ -22,17 +19,20 @@ import { async function run() { await ensureGitStatus(); - // check docker status - console.log('Check docker status'); - await $`docker ps`; + const commitId = (await $`git rev-parse HEAD`).stdout.trim(); + const artifactsFile = `artifacts-${commitId}.zip`; + const hasArtifacts = fs.existsSync(path.join(process.cwd(), artifactsFile)); + assert(hasArtifacts, `${artifactsFile} not found in cwd`); const nodePkgPath = rootPkgPath(); const nodePkg = loadPkg(nodePkgPath); const { newVersion, tag, branch } = await queryNewVersion(nodePkg); + nodePkg.version = newVersion; fs.writeFileSync(nodePkgPath, JSON.stringify(nodePkg, null, 2) + '\n'); await build(); + await artifacts(artifactsFile); await $`npm publish --tag ${tag} --access public`; @@ -42,84 +42,17 @@ async function run() { } async function build() { - // clean await $`rm -rf ./*.node`; await $`find ./npm -name '*.node' | xargs rm -f`; await $`rm -rf ./dist`; - // build linux *.node - console.log('linux building started...'); - const start = Date.now(); - const cargoRoot = path.join(__dirname, '../../..'); - // clean sailfish - // since its lock files may cause build error - await $`rm -rf ${cargoRoot}/target/release/build/sailfish*`; - await build_linux_binding('gnu'); - await build_linux_binding('musl'); - await $`pnpm run format`; - const duration = (Date.now() - start) / 1000; - console.log(`linux building done ${duration}s`); - - // build macos *.node - await $`cargo build --lib -r --target x86_64-apple-darwin`; - await $`pnpm run build:mac:x86`; - await $`cargo build --lib -r --target aarch64-apple-darwin`; - await $`pnpm run build:mac:aarch`; - await $`strip -x ./mako.darwin-*.node`; - - // build src + await $`pnpm run build`; await $`pnpm run src:build`; await $`pnpm run format`; - - // move artifacts to npm - await $`pnpm run artifacts:local`; } -async function build_linux_binding(cLib: 'musl' | 'gnu') { - const isArm = process.arch === 'arm64'; - const cargoBase = path.join( - process.env['CARGO_HOME'] || process.env['HOME']!, - '.cargo', - ); - const cargoMapOption = (p: string) => [ - '-v', - `${path.join(cargoBase, p)}:${path.join('/usr/local/cargo', p)}`, - ]; - const rustupRoot = path.join(os.homedir(), '.rustup'); - const makoRoot = path.join(__dirname, '../../..'); - const volumeOptions = [ - ...cargoMapOption('config'), - ...cargoMapOption('git/db'), - ...cargoMapOption('registry/cache'), - ...cargoMapOption('registry/index'), - ...[`-v`, `${makoRoot}:/build`], - ...[`-v`, `${rustupRoot}:/usr/local/rustup`], - ...[`-w`, `/build`], - ]; - const containerCMD = [ - `cargo build -r --lib --target x86_64-unknown-linux-${cLib}`, - 'cd packages/mako', - `npm run build:linux:${cLib}`, - 'strip mako.linux*.node', - ].join('&&'); - const envOptions: string[] = []; - if (process.env['RUSTUP_DIST_SERVER']) { - envOptions.push( - ...['-e', `RUSTUP_DIST_SERVER=${process.env['RUSTUP_DIST_SERVER']}`], - ); - } - if (process.env[`RUSTUP_UPDATE_ROOT`]) { - envOptions.push( - ...['-e', `RUSTUP_UPDATE_ROOT=${process.env[`RUSTUP_UPDATE_ROOT`]}`], - ); - } - const options = ['--rm', ...volumeOptions, ...envOptions]; - if (isArm) { - options.push(...['--platform', 'linux/amd64']); - } - const image = - cLib === 'gnu' - ? 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian' - : 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine'; - await $`docker run ${options} ${image} bash -c ${containerCMD}`; +async function artifacts(artifactsFile: string) { + await $`rm -rf *.node`; + await $`unzip ${artifactsFile}`; + await $`npm run artifacts:local`; } diff --git a/scripts/release.ts b/scripts/release.ts deleted file mode 100644 index 03d9f1d9c..000000000 --- a/scripts/release.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { parse } from 'semver'; -import 'zx/globals'; - -(async () => { - // check branch - console.log('Check branch'); - const branch = (await $`git branch --show-current`).stdout.trim(); - if (branch !== 'master') { - throw new Error('Please run this script in master branch'); - } - - // check git status - console.log('Check git status'); - const status = (await $`git status --porcelain`).stdout.trim(); - if (status) { - throw new Error('Please commit all changes before release'); - } - - // bump version - console.log('Bump version'); - const nodePkgDir = path.join(__dirname, '../crates/node'); - const nodePkgPath = path.join(nodePkgDir, 'package.json'); - const nodePkg = JSON.parse(fs.readFileSync(nodePkgPath, 'utf-8')); - const version = nodePkg.version; - const parsedVersion = parse(version); - if (!parsedVersion) { - throw new Error(`Invalid version: ${version}`); - } - parsedVersion.patch += 1; - let newVersion = parsedVersion.format(); - // remove prerelease tag - newVersion = newVersion.replace(/-.+/, ''); - nodePkg.version = newVersion; - fs.writeFileSync(nodePkgPath, JSON.stringify(nodePkg, null, 2) + '\n'); - - // set new version to bundler-okam - console.log('Set new version to bundler-okam'); - const bundlerOkamPkgPath = path.join( - __dirname, - '../packages/bundler-okam/package.json', - ); - const bundlerOkamPkg = JSON.parse( - fs.readFileSync(bundlerOkamPkgPath, 'utf-8'), - ); - bundlerOkamPkg.dependencies['@okamjs/okam'] = `${newVersion}`; - fs.writeFileSync( - bundlerOkamPkgPath, - JSON.stringify(bundlerOkamPkg, null, 2) + '\n', - ); - - // pnpm install to update lockfile - console.log('pnpm install'); - await $`pnpm install`; - - // commit - console.log('Commit'); - await $`git add ./`; - await $`git commit -m "Release ${newVersion}"`; - - // tag - console.log('Tag'); - await $`git tag v${newVersion}`; - - // push - console.log('Push'); - await $`git push origin ${branch} --tags`; -})().catch((e) => { - console.error(e); - process.exit(1); -});