refactor(landlock-run): unify workspace release (review round 1)

This commit is contained in:
Hypatia May
2026-08-06 10:23:26 +08:00
parent e88bace07e
commit 598f9719f4
40 changed files with 535 additions and 530 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env node
/**
* Bump every package (workspace root + packages/*) to one version, refresh
* the lockfile, and verify. Usage: `pnpm release:bump <major|minor|patch|x.y.z>`.
* Bump the launcher workspace root and packages/* to one version, refresh the
* repository lockfile, and verify. Usage: `pnpm release:bump <major|minor|patch|x.y.z>`.
*/
import fs from 'node:fs';
@@ -11,14 +11,15 @@ import { packageDirs, readJson, root } from './repo.mjs';
const bump = process.argv[2];
const releaseTypes = new Set(['major', 'minor', 'patch']);
const repositoryRoot = path.resolve(root, '../..');
function writeJson(file, value) {
fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
}
function run(command, args) {
function run(command, args, cwd = root) {
const result = spawnSync(command, args, {
cwd: root,
cwd,
stdio: 'inherit',
env: { ...process.env, CI: 'true' },
});
@@ -84,7 +85,7 @@ for (const file of files) {
console.log(`${file}: ${targetVersion}`);
}
run('pnpm', ['install', '--ignore-scripts', '--lockfile-only']);
run('pnpm', ['install', '--ignore-scripts', '--lockfile-only'], repositoryRoot);
run('node', ['./scripts/verify-release.mjs']);
console.log(`Release version bumped to ${targetVersion}`);

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env node
/**
* Bump, stage, and commit a release in one command:
* `pnpm release:commit <major|minor|patch|x.y.z>`. The tag stays manual —
* create it from the merged release commit.
* `pnpm release:commit <major|minor|patch|x.y.z>`. The namespaced tag stays
* manual — create it from the merged release commit.
*/
import path from 'node:path';
@@ -35,8 +35,8 @@ run('git', [
'add',
'package.json',
'packages/*/package.json',
'pnpm-lock.yaml',
'../../pnpm-lock.yaml',
]);
run('git', ['commit', '-m', `release: ${version}`]);
run('git', ['commit', '-m', `release(landlock-run): ${version}`]);
console.log(`Committed release ${version}. Create the tag manually: git tag v${version}`);
console.log(`Committed release ${version}. Create the tag manually: git tag landlock-run-v${version}`);

View File

@@ -12,10 +12,10 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
export const root = fileURLToPath(new URL('..', import.meta.url));
export const packagesRoot = path.join(root, 'packages');
const packagesRoot = path.join(root, 'packages');
/** ELF `e_machine` (offset 18, little-endian) per platform-package `cpu` value. */
export const E_MACHINE = { x64: 62, arm64: 183 };
const E_MACHINE = { x64: 62, arm64: 183 };
export function readJson(file) {
return JSON.parse(fs.readFileSync(file, 'utf8'));

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env node
/**
* Release verification. Always: every published package carries one shared
* version, and — when running from a tag or publishing — the `vX.Y.Z` tag
* matches it. With `--prebuilds`: every platform package's declared
* version, and — when running from a tag or publishing — the
* `landlock-run-vX.Y.Z` tag matches it. With `--prebuilds`: every platform package's declared
* binaries exist with the right ELF architecture (run after
* `assemble-prebuilds.mjs` or a local `build:native`).
*/
@@ -10,6 +10,8 @@
import path from 'node:path';
import { packageDirs, platformDirs, readJson, root, verifyPlatformBinaries } from './repo.mjs';
const TAG_PREFIX = 'refs/tags/landlock-run-v';
function verifyVersions() {
const packages = packageDirs().map((dir) => ({
dir,
@@ -26,13 +28,13 @@ function verifyVersions() {
const version = packages[0].manifest.version;
const ref = process.env.GITHUB_REF || '';
const publish = process.env.RELEASE_PUBLISH === 'true';
if (publish && !ref.startsWith('refs/tags/v')) {
throw new Error('publishing requires running the workflow from a v* tag');
if (publish && !ref.startsWith(TAG_PREFIX)) {
throw new Error('publishing requires running the workflow from a landlock-run-v* tag');
}
if (ref.startsWith('refs/tags/v')) {
const tagVersion = ref.slice('refs/tags/v'.length);
if (ref.startsWith(TAG_PREFIX)) {
const tagVersion = ref.slice(TAG_PREFIX.length);
if (tagVersion !== version) {
throw new Error(`tag/version mismatch: tag v${tagVersion}, packages ${version}`);
throw new Error(`tag/version mismatch: tag landlock-run-v${tagVersion}, packages ${version}`);
}
}