|
| 1 | +import test from "node:test"; |
| 2 | +import assert from "node:assert/strict"; |
| 3 | +import { spawnSync } from "node:child_process"; |
| 4 | +import { readFileSync } from "node:fs"; |
| 5 | + |
| 6 | +test("release tag must exactly match package version", () => { |
| 7 | + for (const tag of [undefined, "0.1.0", "v0.1", "v9.9.9"]) { |
| 8 | + const args = ["scripts/validate-release-tag.mjs", ...(tag ? [tag] : [])]; |
| 9 | + const run = spawnSync(process.execPath, args, { encoding: "utf8", env: { ...process.env, GITHUB_REF_NAME: "" } }); |
| 10 | + assert.equal(run.status, 1, tag); |
| 11 | + } |
| 12 | + assert.equal(spawnSync(process.execPath, ["scripts/validate-release-tag.mjs", "v0.1.0"]).status, 0); |
| 13 | +}); |
| 14 | + |
| 15 | +test("release workflow validates before publishing and publishes before GitHub release", () => { |
| 16 | + const workflow = readFileSync(".github/workflows/release.yml", "utf8"); |
| 17 | + const validate = workflow.indexOf("npm run release:tag"); |
| 18 | + const publish = workflow.indexOf("npm publish --provenance --access public"); |
| 19 | + const githubRelease = workflow.indexOf("gh release create"); |
| 20 | + assert.ok(validate >= 0 && validate < publish); |
| 21 | + assert.ok(publish < githubRelease); |
| 22 | + assert.match(workflow, /permissions:\n contents: write\n id-token: write/); |
| 23 | +}); |
| 24 | + |
| 25 | +test("dry run validates a prospective package tag", () => { |
| 26 | + const workflow = readFileSync(".github/workflows/release-dry-run.yml", "utf8"); |
| 27 | + assert.match(workflow, /npm run release:tag -- "v\$\(node/); |
| 28 | +}); |
0 commit comments