diff --git a/.github/workflows/bumped.yml b/.github/workflows/bumped.yml new file mode 100644 index 0000000..9b6e809 --- /dev/null +++ b/.github/workflows/bumped.yml @@ -0,0 +1,26 @@ +# A package whose shipped files change keeps nothing of the change unless +# its version changes too (scripts/bumped.mjs, plugins#1131). Runs on each +# pull request and on each push to main, against what it is based on. +name: bumped + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + bumped: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: oven-sh/setup-bun@v2 + - uses: actions/setup-node@v4 + with: + node-version: 24 + - name: versions raised + run: bun scripts/bumped.mjs "${{ github.event.pull_request.base.sha || github.event.before }}" diff --git a/scripts/bumped.mjs b/scripts/bumped.mjs new file mode 100644 index 0000000..2644ab8 --- /dev/null +++ b/scripts/bumped.mjs @@ -0,0 +1,68 @@ +// Fails when a package's shipped files changed since while its +// version stayed the same. +// bun scripts/bumped.mjs +// A version is packed once: the dist branch keeps the first tarball made of +// it (scripts/dist.mjs), npm refuses to publish it twice, and magpie's +// update compares versions only. So a change shipped under a version that +// is already out never reaches anyone who has that version, and new +// installs from dist get the old code under the new number (plugins#1131: +// astudio 0.2.2's DeepSeek-V4.1-Flash fill-in went out without a bump). +// README.md is left out: magpie reads it from dist's index.json, which is +// written again on every run. Files npm doesn't pack (tests) don't count. +import { execFileSync } from "node:child_process" +import { existsSync, readFileSync } from "node:fs" +import { join, resolve } from "node:path" + +// unbumped lists "@: files…" for each package whose shipped +// files changed with its version the same. changed: repo paths changed +// since base. versionAt(dir, "base"|"head"): the version, or null when +// the package isn't there. packed(dir): the paths npm packs, relative to +// dir. +export function unbumped(changed, versionAt, packed) { + const byDir = new Map() + for (const p of changed) { + const m = /^(packages\/[^/]+)\/(.+)$/.exec(p) + if (!m) continue + if (!byDir.has(m[1])) byDir.set(m[1], []) + byDir.get(m[1]).push(m[2]) + } + const out = [] + for (const [dir, files] of byDir) { + const head = versionAt(dir, "head") + const base = versionAt(dir, "base") + if (head === null || base === null || head !== base) continue + const ships = new Set(packed(dir)) + const hit = files.filter((f) => f !== "README.md" && ships.has(f)).sort() + if (hit.length) out.push(`${dir}@${head}: ${hit.join(", ")}`) + } + return out.sort() +} + +if (import.meta.main) { + const base = process.argv[2] + if (!base || /^0+$/.test(base)) { + console.log("no base to compare with") + process.exit(0) + } + const root = resolve(import.meta.dir, "..") + const git = (...a) => execFileSync("git", a, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }) + const changed = git("diff", "--name-only", base, "HEAD", "--", "packages").split("\n").filter(Boolean) + const versionAt = (dir, at) => { + try { + const src = at === "head" ? (existsSync(join(root, dir, "package.json")) ? readFileSync(join(root, dir, "package.json"), "utf8") : null) : git("show", `${base}:${dir}/package.json`) + return src === null ? null : JSON.parse(src).version ?? null + } catch { + return null + } + } + const packed = (dir) => { + const out = execFileSync("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], { cwd: join(root, dir), encoding: "utf8" }) + return JSON.parse(out)[0].files.map((f) => f.path) + } + const problems = unbumped(changed, versionAt, packed) + if (problems.length) { + for (const p of problems) console.log(`::error::${p} changed without a version bump; raise the version in its package.json`) + process.exit(1) + } + console.log(`every package that changed since ${base} has a new version`) +} diff --git a/scripts/bumped.test.mjs b/scripts/bumped.test.mjs new file mode 100644 index 0000000..086c854 --- /dev/null +++ b/scripts/bumped.test.mjs @@ -0,0 +1,18 @@ +import { expect, test } from "bun:test" +import { unbumped } from "./bumped.mjs" + +const versions = { "packages/a": ["0.1.0", "0.1.0"], "packages/b": ["0.1.0", "0.1.1"], "packages/new": [null, "0.1.0"], "packages/gone": ["0.1.0", null] } +const versionAt = (dir, at) => (versions[dir] ?? [null, null])[at === "base" ? 0 : 1] +const packed = () => ["index.mjs", "opencode2.mjs", "package.json", "README.md"] + +test("a shipped file changed under the same version is named (plugins#1131)", () => { + expect(unbumped(["packages/a/index.mjs", "packages/a/opencode2.mjs"], versionAt, packed)).toEqual(["packages/a@0.1.0: index.mjs, opencode2.mjs"]) +}) + +test("a bumped, new or removed package passes", () => { + expect(unbumped(["packages/b/index.mjs", "packages/new/index.mjs", "packages/gone/index.mjs"], versionAt, packed)).toEqual([]) +}) + +test("README.md, tests and files outside packages need no bump", () => { + expect(unbumped(["packages/a/README.md", "packages/a/index.test.mjs", "scripts/check.mjs", "registry.json"], versionAt, packed)).toEqual([]) +})