mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: unify release workflow into single release-all script
Consolidate version bumping, building, npm publishing, and git operations into a single release script that handles platform packages first. This solves the issue where optionalDependencies needed platform packages published before bun install could generate complete lockfile hashes. Changes: - Created cli/scripts/release-all.ts with support for --dry-run, --publish-npm, and --skip-build flags - Removed release-it dependency and old release/publish-npm scripts - Simplified GitHub Actions release workflow to always use --generate-notes - Deleted obsolete release configuration files (.release-it.json, .release-it.notes.js, publish-npm.ts)
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env bun
|
||||
/**
|
||||
* Unified release script that handles the complete release flow:
|
||||
* 1. Bump version
|
||||
* 2. Build binaries (with embedded web assets)
|
||||
* 3. Publish platform packages first (so lockfile can resolve them)
|
||||
* 4. bun install (to get complete lockfile with published packages)
|
||||
* 5. Publish main package
|
||||
* 6. Git commit + tag + push
|
||||
*/
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const scriptDir = import.meta.dir;
|
||||
const projectRoot = join(scriptDir, '..');
|
||||
const repoRoot = join(projectRoot, '..');
|
||||
|
||||
// 解析参数
|
||||
const args = process.argv.slice(2);
|
||||
const version = args.find(arg => !arg.startsWith('--'));
|
||||
const dryRun = args.includes('--dry-run');
|
||||
const publishNpm = args.includes('--publish-npm'); // 只发布 npm,跳过 git 操作
|
||||
const skipBuild = args.includes('--skip-build'); // 跳过构建(二进制已存在)
|
||||
|
||||
if (!version) {
|
||||
console.error('Usage: bun run scripts/release-all.ts <version> [options]');
|
||||
console.error('Options:');
|
||||
console.error(' --dry-run Preview the release process');
|
||||
console.error(' --publish-npm Only publish to npm, skip git operations');
|
||||
console.error(' --skip-build Skip building binaries (use existing)');
|
||||
console.error('Example: bun run scripts/release-all.ts 0.2.0');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function run(cmd: string, cwd = projectRoot): void {
|
||||
console.log(`\n$ ${cmd}`);
|
||||
if (!dryRun) {
|
||||
execSync(cmd, { cwd, stdio: 'inherit' });
|
||||
}
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const flags = [dryRun && 'dry-run', publishNpm && 'publish-npm', skipBuild && 'skip-build'].filter(Boolean);
|
||||
console.log(`\n🚀 Starting release v${version}${flags.length ? ` (${flags.join(', ')})` : ''}\n`);
|
||||
|
||||
// Step 1: Update package.json version
|
||||
console.log('📦 Step 1: Updating package.json version...');
|
||||
const pkgPath = join(projectRoot, 'package.json');
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
||||
const oldVersion = pkg.version;
|
||||
pkg.version = version;
|
||||
if (!dryRun) {
|
||||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
||||
}
|
||||
console.log(` ${oldVersion} → ${version}`);
|
||||
|
||||
// Step 2: Build all platform binaries (with embedded web assets)
|
||||
if (!skipBuild) {
|
||||
console.log('\n🔨 Step 2: Building all platform binaries with web assets...');
|
||||
run('bun run build:single-exe:all', repoRoot);
|
||||
} else {
|
||||
console.log('\n🔨 Step 2: Skipping build (--skip-build)');
|
||||
}
|
||||
|
||||
// Step 3: Prepare and publish platform packages
|
||||
console.log('\n📤 Step 3: Publishing platform packages...');
|
||||
run('bun run prepare-npm-packages');
|
||||
const platforms = ['darwin-arm64', 'darwin-x64', 'linux-arm64', 'linux-x64', 'win32-x64'];
|
||||
for (const platform of platforms) {
|
||||
const npmDir = join(projectRoot, 'npm', platform);
|
||||
run(`npm publish --access public${dryRun ? ' --dry-run' : ''}`, npmDir);
|
||||
}
|
||||
|
||||
// Step 4: bun install to get complete lockfile
|
||||
console.log('\n📥 Step 4: Updating lockfile...');
|
||||
run('bun install', repoRoot);
|
||||
|
||||
// Step 5: Publish main package
|
||||
console.log('\n📤 Step 5: Publishing main package...');
|
||||
run(`npm publish --access public${dryRun ? ' --dry-run' : ''}`);
|
||||
|
||||
// --publish-npm 模式到此结束
|
||||
if (publishNpm) {
|
||||
console.log(`\n✅ Published v${version} to npm!`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 6: Git commit + tag + push
|
||||
console.log('\n📝 Step 6: Creating git commit and tag...');
|
||||
run(`git add .`, repoRoot);
|
||||
run(`git commit -m "Release version ${version}"`, repoRoot);
|
||||
run(`git tag v${version}`, repoRoot);
|
||||
run(`git push && git push --tags`, repoRoot);
|
||||
|
||||
console.log(`\n✅ Release v${version} completed!`);
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Release failed:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user