Files
nicktrn cad8791859 chore: make changeset:version atomic (#3505)
Follow-up to the v4.4.5 release incident where the release PR (#3406)
was merged with a stale lockfile and stale Chart.yaml, breaking npm +
helm releases. The two automation jobs (`update-lockfile`,
`bump-chart-version`) got cancelled mid-flight by `cancel-in-progress`
when the merge fired the workflow again on `main`.

This restructures `changeset:version` so all the post-version-bump
fixups happen in the same script and end up in a single atomic commit on
`changeset-release/main`, via `changesets/action`'s normal commit step.

Pattern borrowed from Cloudflare workers-sdk, Astro, shadcn/ui.

## Before

```
push: main
└── release-pr (changeset version → bumps package.jsons, opens PR)
    └── update-lockfile (separate job, separate commit)
        └── bump-chart-version (separate job, separate commit)
```

Three jobs, three commits to the release branch.

## After

```
push: main
└── release-pr
    └── changesets/action runs:
          changeset version
          pnpm install --lockfile-only
          node scripts/bump-helm-chart.mjs
          node scripts/cleanup-server-changes.mjs
        ...all staged and committed as ONE commit by the action
```

One job, one commit.
2026-05-02 09:45:44 +01:00

32 lines
1.2 KiB
JavaScript

import { readFileSync, writeFileSync } from "node:fs";
const VERSION_SOURCE = "packages/cli-v3/package.json";
const CHART_PATH = "hosting/k8s/helm/Chart.yaml";
const { version } = JSON.parse(readFileSync(VERSION_SOURCE, "utf8"));
const desiredVersion = `version: ${version}`;
const desiredAppVersion = `appVersion: v${version}`;
const original = readFileSync(CHART_PATH, "utf8");
const versionMatch = original.match(/^version:.*$/m);
const appVersionMatch = original.match(/^appVersion:.*$/m);
if (!versionMatch || !appVersionMatch) {
const missing = [!versionMatch && "version:", !appVersionMatch && "appVersion:"]
.filter(Boolean)
.join(", ");
console.error(`${CHART_PATH} is missing required key(s): ${missing}`);
process.exit(1);
}
if (versionMatch[0] === desiredVersion && appVersionMatch[0] === desiredAppVersion) {
console.log(`${CHART_PATH} already at ${version} (from ${VERSION_SOURCE}), no changes`);
} else {
const updated = original
.replace(/^version:.*/m, desiredVersion)
.replace(/^appVersion:.*/m, desiredAppVersion);
writeFileSync(CHART_PATH, updated);
console.log(`${CHART_PATH} bumped to ${version} (from ${VERSION_SOURCE})`);
}