fix(chat): thinking execution graph (#880)
This commit is contained in:
45
scripts/assert-release-version.mjs
Normal file
45
scripts/assert-release-version.mjs
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* npm/pnpm `version` lifecycle hook: runs after package.json is bumped, before
|
||||
* `git tag`. Aborts if the target tag already exists so we never fail late on
|
||||
* `fatal: tag 'vX.Y.Z' already exists`.
|
||||
*/
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
|
||||
function readPackageVersion() {
|
||||
const raw = readFileSync(join(root, 'package.json'), 'utf8');
|
||||
return JSON.parse(raw).version;
|
||||
}
|
||||
|
||||
const version = process.env.npm_package_version || readPackageVersion();
|
||||
const tag = `v${version}`;
|
||||
|
||||
function localTagExists(t) {
|
||||
try {
|
||||
execSync(`git rev-parse -q --verify refs/tags/${t}`, { stdio: 'pipe' });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (localTagExists(tag)) {
|
||||
console.error(`
|
||||
Release version check failed: git tag ${tag} already exists locally.
|
||||
|
||||
You cannot run \`pnpm version …\` for ${version} until that tag is gone or the
|
||||
version is bumped to a value that does not yet have a tag.
|
||||
|
||||
Typical fixes:
|
||||
• Use the next prerelease explicitly, e.g. \`pnpm version 0.3.10-beta.4\`
|
||||
• Or delete only if you are sure it was created by mistake: \`git tag -d ${tag}\`
|
||||
`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Release version OK: tag ${tag} is not present locally yet.`);
|
||||
35
scripts/assert-tag-matches-package.mjs
Normal file
35
scripts/assert-tag-matches-package.mjs
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* CI / global release sanity: when building from a version tag, the root
|
||||
* package.json "version" must match the tag (without the leading "v").
|
||||
*
|
||||
* Exits 0 when GITHUB_REF is not refs/tags/v* (e.g. branch builds, PRs).
|
||||
*/
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const ref = process.env.GITHUB_REF || '';
|
||||
|
||||
if (!ref.startsWith('refs/tags/v')) {
|
||||
console.log(
|
||||
`[assert-tag-matches-package] Skip: GITHUB_REF is not a version tag (${ref || '(empty)'})`,
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const tagVersion = ref.slice('refs/tags/v'.length);
|
||||
const pkgVersion = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).version;
|
||||
|
||||
if (tagVersion !== pkgVersion) {
|
||||
console.error(
|
||||
`[assert-tag-matches-package] Mismatch: git tag is "${tagVersion}" but package.json version is "${pkgVersion}".`,
|
||||
);
|
||||
console.error(
|
||||
'Push a commit that sets package.json "version" to match the tag before cutting the release.',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`[assert-tag-matches-package] OK: tag v${tagVersion} matches package.json.`);
|
||||
Reference in New Issue
Block a user