diff --git a/bin/release b/bin/release index 54076a4..e6e76d4 100755 --- a/bin/release +++ b/bin/release @@ -122,17 +122,9 @@ published || folded=$(pnpm exec cli-dev changelog fold --land --version "$versio [ -z "$folded" ] || echo "$folded" rerun_if_changed "$@" -# Two sessions preparing the same number is normal; the second takes the next free one. -latest=$(npm view "$package" version --prefer-online 2>/dev/null || true) -versions=$(npm view "$package" versions --json --prefer-online 2>/dev/null || true) -next=$(pnpm exec cli-dev next-version "$version" "$latest" "$versions") -fragments=$(find changes -maxdepth 1 -type f -name '*.md' ! -name README.md 2>/dev/null | wc -l) -if [ "$next" != "$version" ]; then - taken="" - if published; then taken=1; why="$version is already on npm"; else why="$version is not above npm's latest $latest"; fi - next=$(pnpm exec cli-dev changelog level --next "$next") - echo "$why — publishing $next instead" - # A version npm already has keeps its changelog section; the unreleased one becomes the new version. +# Raises the version from $1 to $2 in package.json, src/version.ts and the CHANGELOG heading. With $3 set, npm has +# $1, so its section stays and the unreleased one becomes $2. +renumber() { node -e 'const fs = require("fs"); const [o, n, taken] = process.argv.slice(1) const swap = (file, from, to) => { const text = fs.readFileSync(file, "utf8") @@ -146,10 +138,30 @@ if [ "$next" != "$version" ]; then const log = fs.readFileSync("CHANGELOG.md", "utf8") if (taken && log.includes("\n## Unreleased\n")) swap("CHANGELOG.md", "\n## Unreleased\n", `\n## ${n} — ${today}\n`) else if (taken) swap("CHANGELOG.md", "\n## ", `\n## ${n} — ${today}\n\n## `) - else swap("CHANGELOG.md", `\n## ${o} — `, `\n## ${n} — `)' "$version" "$next" "$taken" + else swap("CHANGELOG.md", `\n## ${o} — `, `\n## ${n} — `)' "$1" "$2" "$3" +} + +# Two sessions preparing the same number is normal; the second takes the next free one. +latest=$(npm view "$package" version --prefer-online 2>/dev/null || true) +versions=$(npm view "$package" versions --json --prefer-online 2>/dev/null || true) +next=$(pnpm exec cli-dev next-version "$version" "$latest" "$versions") +fragments=$(find changes -maxdepth 1 -type f -name '*.md' ! -name README.md 2>/dev/null | wc -l) +if [ "$next" != "$version" ]; then + taken="" + if published; then taken=1; why="$version is already on npm"; else why="$version is not above npm's latest $latest"; fi + renumber "$version" "$next" "$taken" pnpm exec cli-dev changelog fragments --collect "$next" - body="bin/release: $why. Only the number changes: package.json, src/version.ts, the CHANGELOG heading, and the -changes/ fragments collected under it. + # next-version keeps the level of the version it raises; the section, with the fragments now in it, may need more: + # an Added is a minor. + levelled=$(pnpm exec cli-dev changelog level --next "$next") + if [ "$levelled" != "$next" ]; then + levelled=$(pnpm exec cli-dev next-version "$levelled" "$latest" "$versions") + renumber "$next" "$levelled" "" + next=$levelled + fi + echo "$why — publishing $next instead" + body="bin/release: $why. Only the number changes, to the level the changelog needs: package.json, src/version.ts, +the CHANGELOG heading, and the changes/ fragments collected under it. ## Conformance @@ -158,10 +170,20 @@ The release pull request of $version recorded the checks; this one changes only rerun_if_changed "$@" version=$next elif [ "$fragments" -gt 0 ]; then - # The version was dated by hand; fragments merged since then still belong to it. + # The version was dated by hand; fragments merged since then still belong to it, and may need a higher level. pnpm exec cli-dev changelog fragments --collect "$version" - land "release/$version-changes" "chore(changelog): collect changes/ into $version" \ - "bin/release: the changes/ fragments merged since $version was dated, collected into its section." + levelled=$(pnpm exec cli-dev changelog level --next "$version") + if [ "$levelled" != "$version" ]; then + levelled=$(pnpm exec cli-dev next-version "$levelled" "$latest" "$versions") + renumber "$version" "$levelled" "" + echo "the changes/ fragments need $levelled — publishing it instead of $version" + land "release/$levelled" "chore(release): $levelled" \ + "bin/release: the changes/ fragments merged since $version was dated need $levelled, collected into its section." + version=$levelled + else + land "release/$version-changes" "chore(changelog): collect changes/ into $version" \ + "bin/release: the changes/ fragments merged since $version was dated, collected into its section." + fi rerun_if_changed "$@" fi top=$(sed -n '/^## /{p;q;}' CHANGELOG.md) diff --git a/changes/fix-release-level-after-fragments.md b/changes/fix-release-level-after-fragments.md new file mode 100644 index 0000000..8d8bd4d --- /dev/null +++ b/changes/fix-release-level-after-fragments.md @@ -0,0 +1,11 @@ +### Fixed + +- **`bin/release` picks the version after it collects `changes/`.** When npm already had the version, it chose the + next one from the changelog before the fragments were in it, so a fragment with `Added` still gave a patch, and + `version:check` then refused the release pull request (wordpress-cli 0.1.3, which had to be 0.2.0). The fragments + are now collected first, and an `Added` raises the release to a minor. A version dated by hand is raised the same + way when the fragments merged since need more. `scripts/release.test.ts` checks both and is kept up to date by + `upgrade`, as `bin/release` is. A CLI gets this with its next `upgrade`. +- **The template builds on cli-core 0.718.0 and cli-base 0.126.1**, so `pnpm audit:commands` passes the family audit + again: the published CLIs still name an unknown profile twice, and cli-base 0.126.1 lists that as a shared + difference. diff --git a/contracts/help.snap b/contracts/help.snap index bd3c87f..f86e2d5 100644 --- a/contracts/help.snap +++ b/contracts/help.snap @@ -18,6 +18,7 @@ Works with: notion Notion pages and databases as local text, searchable with your other WireCat data ydisk Yandex Disk folders as local text, searchable with your other WireCat data wordpress WordPress posts and pages, searchable with your other WireCat data + linear Linear issues and projects, searchable with your other WireCat data Next: clidev commands every command, by section clidev help options output, offline, timeouts, dry run diff --git a/package.json b/package.json index d2ec7b2..6ebd471 100644 --- a/package.json +++ b/package.json @@ -90,8 +90,8 @@ "kit:docs": "cspell lint --config cspell.json --no-progress --no-summary kit/*.md SKILL.md && rumdl check --config config/wirecat/rumdl.toml kit/*.md SKILL.md" }, "dependencies": { - "@wirecat/cli-base": "0.125.2", - "@wirecat/cli-core": "0.710.0", + "@wirecat/cli-base": "0.126.1", + "@wirecat/cli-core": "0.718.0", "commander": "15.0.0", "valibot": "1.5.0", "yaml": "2.9.1" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 73c8b73..d2ef98c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,11 +13,11 @@ importers: .: dependencies: '@wirecat/cli-base': - specifier: 0.125.2 - version: 0.125.2(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) + specifier: 0.126.1 + version: 0.126.1(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) '@wirecat/cli-core': - specifier: 0.710.0 - version: 0.710.0(@wirecat/cli-base@0.125.2(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) + specifier: 0.718.0 + version: 0.718.0(@wirecat/cli-base@0.126.1(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) commander: specifier: 15.0.0 version: 15.0.0 @@ -1179,8 +1179,8 @@ packages: '@wasm-audio-decoders/opus-ml@0.0.3': resolution: {integrity: sha512-SEeTmk0eb3q5etJA/NHCRWW6BivTx9tqvNTmG0kg2ynuATEQRUZnwQE6Ibvl1BBvqIGHqI57+qyJMWmJBwb5XQ==} - '@wirecat/cli-base@0.125.2': - resolution: {integrity: sha512-7MRAVJzHn+j4Y5Xq3M6EcKfn3iR1vHrCaWqqUKrckNeInpf5zzXqdvVUlXKMV1pP1MXZfKoH8M8akrkp8GHVlg==} + '@wirecat/cli-base@0.126.1': + resolution: {integrity: sha512-pZyRiK4Z9O3QZuOgwGZt+ISsaA2UU+u4AarnHjmIWG9aeAJ3ot2Hz7Dbctj2msjb7JgvR2+S7+OS+ZNGKcolQA==} engines: {node: '>=22'} hasBin: true peerDependencies: @@ -1207,13 +1207,13 @@ packages: '@wirecat/cli-core-sqlite@1.1.0': resolution: {integrity: sha512-GpGlh/dAIX/nblBYCdT6DfWSLFxav9mxxeELQAfEuw+QZdT9unKxbi5xa02s/s4JS1P7n0PQx2sCABj4FlMRNw==} - '@wirecat/cli-core@0.710.0': - resolution: {integrity: sha512-cZ/eLpANwnL6JyDa/YmmRDCpNEKwbMLjE2OhGKLW8U6itxRCRjF64xYl6C30R9OpqFz/ZvkTLmNuzb+Iqrszwg==} + '@wirecat/cli-core@0.718.0': + resolution: {integrity: sha512-2h5pSWF6BmYyUkxOyc6cPw6ai2p8n3I7dXsrSzcfyHxqHfkcssZ8EcuqJl6wWfCBMtyWSi+U23gg/g4asoOs+w==} engines: {node: ^22.16.0 || >=24} hasBin: true peerDependencies: '@napi-rs/canvas': '>=0.1.69 <2' - '@wirecat/cli-base': '>=0.120.0 <1.0.0' + '@wirecat/cli-base': '>=0.125.0 <1.0.0' commander: '>=15' mysql2: ^3.24.6 pg: ^8.23.1 @@ -3307,7 +3307,7 @@ snapshots: dependencies: '@wasm-audio-decoders/common': 9.0.7 - '@wirecat/cli-base@0.125.2(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5)': + '@wirecat/cli-base@0.126.1(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5)': dependencies: '@valibot/to-json-schema': 1.8.0(valibot@1.5.0(typescript@7.0.2)) cli-table3: 0.6.5 @@ -3329,7 +3329,7 @@ snapshots: '@wirecat/cli-core-sqlite@1.1.0': {} - '@wirecat/cli-core@0.710.0(@wirecat/cli-base@0.125.2(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': + '@wirecat/cli-core@0.718.0(@wirecat/cli-base@0.126.1(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': dependencies: '@anthropic-ai/sdk': 1.3.0(zod@4.6.7) '@bomb.sh/tab': 0.0.22(commander@15.0.0) @@ -3339,7 +3339,7 @@ snapshots: '@valibot/to-json-schema': 1.8.0(valibot@1.5.0(typescript@7.0.2)) '@wasm-audio-decoders/flac': 0.2.11 '@wasm-audio-decoders/ogg-vorbis': 0.1.20 - '@wirecat/cli-base': 0.125.2(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) + '@wirecat/cli-base': 0.126.1(@scalar/openapi-upgrader@0.4.6)(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) '@wirecat/cli-core-onnx': 1.2.0 '@wirecat/cli-core-sqlite': 1.1.0 '@xmldom/xmldom': 0.9.12 diff --git a/scripts/release.test.ts b/scripts/release.test.ts new file mode 100644 index 0000000..6ea9ebf --- /dev/null +++ b/scripts/release.test.ts @@ -0,0 +1,108 @@ +import { execFileSync, spawnSync } from "node:child_process" +import { chmodSync, cpSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { afterEach, expect, it } from "vitest" + +const root = join(import.meta.dirname, "..") +const devBin = join(root, "node_modules/@wirecat/cli-base/dist/dev/bin.js") +const dirs: string[] = [] +afterEach(() => { + for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }) +}) + +const git = (cwd: string, ...args: string[]) => execFileSync("git", args, { cwd, encoding: "utf8" }) + +const stub = (dir: string, name: string, body: string) => { + writeFileSync(join(dir, name), `#!/bin/sh\n${body}\n`) + chmodSync(join(dir, name), 0o755) +} + +// npm has 0.1.2, so bin/release raises the version through a pull request. gh refuses to open it, which stops the run +// right after the release branch is pushed, before anything could publish. +const raised = (fragment: string, dated = "") => { + const work = mkdtempSync(join(tmpdir(), "release-level-")) + dirs.push(work) + const origin = join(work, "origin.git") + const repo = join(work, "repo") + const stubs = join(work, "bin") + mkdirSync(stubs) + git(work, "init", "-q", "--bare", "-b", "main", origin) + git(work, "clone", "-q", origin, repo) + mkdirSync(join(repo, "bin")) + mkdirSync(join(repo, "config/wirecat"), { recursive: true }) + cpSync(join(root, "bin/release"), join(repo, "bin/release")) + for (const file of ["release-lock.sh", "release-lock-info.mjs"]) + cpSync(join(root, "config/wirecat", file), join(repo, "config/wirecat", file)) + mkdirSync(join(repo, "kit")) + writeFileSync(join(repo, "kit/.keep"), "") + mkdirSync(join(repo, "src")) + mkdirSync(join(repo, "changes")) + writeFileSync( + join(repo, "package.json"), + `${JSON.stringify({ name: "@example/acme-cli", version: dated ? "0.1.3" : "0.1.2" }, null, 2)}\n`, + ) + writeFileSync(join(repo, "src/version.ts"), `export const VERSION = "${dated ? "0.1.3" : "0.1.2"}"\n`) + writeFileSync( + join(repo, "CHANGELOG.md"), + `# Changelog\n\n${dated}## 0.1.2 — 19.11.2026\n\n### Fixed\n\n- **One.** A fix.\n`, + ) + writeFileSync(join(repo, "changes/feat-pages.md"), fragment) + git(repo, "add", "-A") + git(repo, "-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "-q", "-m", "init") + git(repo, "tag", "v0.1.2") + git(repo, "push", "-q", "origin", "main", "v0.1.2") + + stub( + stubs, + "pnpm", + `[ "$1" = install ] && exit 0\n[ "$1 $2" = "exec cli-dev" ] && shift 2 && exec node "${devBin}" "$@"\nexit 1`, + ) + stub( + stubs, + "npm", + 'case "$*" in\n *" versions "*) echo \'["0.1.2"]\' ;;\n "view @example/acme-cli version "*|"view @example/acme-cli@0.1.2 version "*) echo 0.1.2 ;;\n *) exit 1 ;;\nesac', + ) + stub(stubs, "gh", "exit 1") + const run = spawnSync("sh", ["bin/release"], { + cwd: repo, + encoding: "utf8", + env: { + ...process.env, + PATH: `${stubs}:${process.env.PATH}`, + XDG_RUNTIME_DIR: work, + GIT_AUTHOR_NAME: "t", + GIT_AUTHOR_EMAIL: "t@example.com", + GIT_COMMITTER_NAME: "t", + GIT_COMMITTER_EMAIL: "t@example.com", + }, + }) + const branches = git(origin, "branch", "--format=%(refname:short)").split("\n").filter(Boolean) + return { run, branches, show: (branch: string, file: string) => git(origin, "show", `${branch}:${file}`) } +} + +it("raises a taken version to the level its changes/ fragments need: an Added is a minor", () => { + const { run, branches, show } = raised("### Added\n\n- **Pages.** Pages are written.\n") + expect(run.stdout).toContain("0.1.2 is already on npm — publishing 0.2.0 instead") + expect(branches).toContain("release/0.2.0") + expect(JSON.parse(show("release/0.2.0", "package.json")).version).toBe("0.2.0") + expect(show("release/0.2.0", "src/version.ts")).toContain('VERSION = "0.2.0"') + expect(show("release/0.2.0", "CHANGELOG.md")).toMatch(/## 0\.2\.0 — [\d.]+\n\n### Added\n\n- \*\*Pages\.\*\*/) +}) + +it("keeps a patch for fragments that only fix", () => { + const { run, branches } = raised("### Fixed\n\n- **Two.** Another fix.\n") + expect(run.stdout).toContain("publishing 0.1.3 instead") + expect(branches).toContain("release/0.1.3") +}) + +it("raises a version dated by hand when the fragments merged since need more", () => { + const { run, branches, show } = raised( + "### Added\n\n- **Pages.** Pages are written.\n", + "## 0.1.3 — 20.11.2026\n\n### Fixed\n\n- **Two.** Another fix.\n\n", + ) + expect(run.stdout).toContain("the changes/ fragments need 0.2.0 — publishing it instead of 0.1.3") + expect(branches).toContain("release/0.2.0") + expect(JSON.parse(show("release/0.2.0", "package.json")).version).toBe("0.2.0") + expect(show("release/0.2.0", "CHANGELOG.md")).toMatch(/## 0\.2\.0 — 20\.11\.2026\n\n### Added[\s\S]*### Fixed/) +}) diff --git a/template.json b/template.json index 2bbd212..b3cad3b 100644 --- a/template.json +++ b/template.json @@ -15,6 +15,7 @@ "docs/dev/TESTING.md", "lefthook.yml", "scripts/one-cli-base.ts", + "scripts/release.test.ts", "scripts/sandboxed.ts", "src/test-timeouts.test.ts", "tsconfig.json",