@@ -13,6 +13,7 @@ const { join } = require("node:path"); |
13 | 13 | const { test } = require("node:test"); |
14 | 14 |
|
15 | 15 | const { setMobileVersion } = require("./set-mobile-version.cjs"); |
| 16 | +const { RELEASE_PACKAGE_FILES, setReleaseVersion } = require("./set-release-version.cjs"); |
16 | 17 |
|
17 | 18 | const read = (path) => readFileSync(join(__dirname, "..", path), "utf8"); |
18 | 19 |
|
@@ -200,6 +201,15 @@ test("the version override token covers this repository only", () => { |
200 | 201 | assert.doesNotMatch(production, /RELEASE_APP|create-github-app-token/); |
201 | 202 | }); |
202 | 203 |
|
| 204 | +test("the release version bump is pushed by a job that installs nothing, with a token for this repository only", () => { |
| 205 | + const { finalize } = jobs("workflows/release.yml"); |
| 206 | + const mint = steps(finalize).find((step) => step.includes("create-github-app-token")); |
| 207 | + assert.doesNotMatch(mint, /^\s+(?:owner|repositories):/m); |
| 208 | + assert.match(mint, /^\s+permission-contents: write$/m); |
| 209 | + assert.ok(!runsProjectCode(finalize), "finalize holds a write token and runs code"); |
| 210 | + assert.match(finalize, /run: node \.github\/scripts\/set-release-version\.cjs /); |
| 211 | +}); |
| 212 | + |
203 | 213 | test("the Vite+ toolchain is cached before the job installs or runs project code", () => { |
204 | 214 | const names = Array.from( |
205 | 215 | read("actions/setup-ci-deps/action.yml").matchAll( |
@@ -300,3 +310,35 @@ test("a version override rewrites only the app version", () => { |
300 | 310 | } |
301 | 311 | assert.throws(() => setMobileVersion("export default {};", "1.2.3"), /Could not update/); |
302 | 312 | }); |
| 313 | + |
| 314 | +test("a release version bump rewrites only the version of each release manifest", () => { |
| 315 | + const listed = /releasePackageFiles = \[\n([^\]]+)\]/.exec( |
| 316 | + read("../scripts/lib/tagged-source-version.ts"), |
| 317 | + )[1]; |
| 318 | + assert.deepEqual( |
| 319 | + RELEASE_PACKAGE_FILES, |
| 320 | + Array.from(listed.matchAll(/"([^"]+)"/g), (m) => m[1]), |
| 321 | + ); |
| 322 | + for (const file of RELEASE_PACKAGE_FILES) { |
| 323 | + const manifest = read(`../${file}`); |
| 324 | + const next = setReleaseVersion(manifest, "98.7.6"); |
| 325 | + assert.equal(JSON.parse(next).version, "98.7.6"); |
| 326 | + assert.deepEqual( |
| 327 | + { ...JSON.parse(next), version: "" }, |
| 328 | + { ...JSON.parse(manifest), version: "" }, |
| 329 | + ); |
| 330 | + assert.equal(setReleaseVersion(next, "98.7.6"), next); |
| 331 | + assert.deepEqual( |
| 332 | + next.split("\n").filter((line, index) => line !== manifest.split("\n")[index]).length, |
| 333 | + 1, |
| 334 | + ); |
| 335 | + } |
| 336 | + for (const version of ["", "1", "1.2", "v1.2.3", '1.2.3", "x": "y']) { |
| 337 | + assert.throws(() => setReleaseVersion('{\n "version": "1.0.0"\n}\n', version), /Invalid/); |
| 338 | + } |
| 339 | + assert.equal( |
| 340 | + setReleaseVersion('{\n "version": "1.0.0"\n}\n', "1.2.3-rc.1"), |
| 341 | + '{\n "version": "1.2.3-rc.1"\n}\n', |
| 342 | + ); |
| 343 | + assert.throws(() => setReleaseVersion('{\n "name": "x"\n}\n', "1.2.3"), /exactly one/); |
| 344 | +}); |