Skip to content
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
25 changes: 15 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions packages/mako/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -87,4 +85,4 @@
"@umijs/mako-linux-x64-musl": "0.8.15"
},
"repository": "git@github.com:umijs/mako.git"
}
}
58 changes: 0 additions & 58 deletions packages/mako/scripts/quick-release.ts

This file was deleted.

93 changes: 13 additions & 80 deletions packages/mako/scripts/release.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'assert';
import 'zx/globals';
import {
ensureGitStatus,
Expand All @@ -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);
Expand All @@ -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`);
Comment on lines +22 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

增加了对artifacts文件的依赖,需确保文件存在

在第22-25行,您增加了获取commitId并检查对应的artifacts-${commitId}.zip文件是否存在的逻辑。这意味着发布流程现在依赖于此文件的存在。请确保在发布前已经生成了该文件,并放置在正确的目录中。


🛠️ Refactor suggestion

重复检查artifacts文件,可能存在冗余

您在run()函数中检查了artifacts文件是否存在(第22-25行),并在artifacts()函数中再次对该文件进行操作(第56行)。这可能导致冗余的检查和操作。建议将文件存在性检查和操作集中在一个地方,优化代码结构。

Also applies to: 54-57


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`;

Expand All @@ -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`;
Comment on lines +54 to +57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

新增加的artifacts()函数缺少错误处理

在第54-57行,您新增了artifacts(artifactsFile: string)函数,但其中的文件操作缺少错误处理。如果unzip失败或artifactsFile不存在,脚本将会崩溃。建议增加错误处理以提高脚本的健壮性。

可以考虑如下修改,添加错误捕获:

async function artifacts(artifactsFile: string) {
+ try {
    await $`rm -rf *.node`;
    await $`unzip ${artifactsFile}`;
    await $`npm run artifacts:local`;
+ } catch (error) {
+   console.error(`Artifacts processing failed: ${error}`);
+   process.exit(1);
+ }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async function artifacts(artifactsFile: string) {
await $`rm -rf *.node`;
await $`unzip ${artifactsFile}`;
await $`npm run artifacts:local`;
async function artifacts(artifactsFile: string) {
try {
await $`rm -rf *.node`;
await $`unzip ${artifactsFile}`;
await $`npm run artifacts:local`;
} catch (error) {
console.error(`Artifacts processing failed: ${error}`);
process.exit(1);
}
}

}
70 changes: 0 additions & 70 deletions scripts/release.ts

This file was deleted.