also looking at this
fix: validate native SDK release prerequisites before tagging
#364
7 files
+153
-15
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
Binary file. Nothing to show line by line.
| @@ -61,11 +61,12 @@ | ||
| 61 | 61 | "changelog:generate": "bun scripts/generate-release-changelog.ts", |
| 62 | 62 | "test:release": "bun test ./scripts/changelog-preview.test.ts ./scripts/release-workflow.test.ts ./scripts/release-manifest.test.ts ./scripts/verify-sbom.test.ts", |
| 63 | 63 | "release": "bun scripts/release-version.ts --preflight && bun x --bun @stacksjs/bumpx prompt --recursive", |
| 64 | "release:patch": "bun scripts/release-version.ts --preflight && bun x --bun @stacksjs/bumpx patch --recursive --commit --tag --push --yes --no-changelog --execute \"bun scripts/sync-release-version.ts && bun scripts/generate-release-changelog.ts && git add packages/zig/build.zig.zon packages/zig/pantry.json CHANGELOG.md\"" | |
| 64 | "release:patch": "bun scripts/release-version.ts --preflight && bun x --bun @stacksjs/bumpx patch --recursive --commit --tag --push --yes --no-changelog --execute \"bun scripts/sync-release-version.ts && bun scripts/generate-release-changelog.ts && git add packages/zig/build.zig.zon packages/zig/pantry.json CHANGELOG.md\"", | |
| 65 | "release:version": "bun scripts/release-version.ts --preflight && bun x --bun @stacksjs/bumpx --recursive --commit --tag --push --yes --no-changelog --execute \"bun scripts/sync-release-version.ts && bun scripts/generate-release-changelog.ts && git add packages/zig/build.zig.zon packages/zig/pantry.json CHANGELOG.md\"" | |
| 65 | 66 | }, |
| 66 | 67 | "devDependencies": { |
| 67 | 68 | "@stacksjs/buddy": "0.72.56", |
| 68 | "@stacksjs/bumpx": "^0.2.10", | |
| 69 | "@stacksjs/bumpx": "^0.2.22", | |
| 69 | 70 | "@stacksjs/bunpress": "^0.2.13", |
| 70 | 71 | "@stacksjs/env": "^0.72.50", |
| 71 | 72 | "better-dx": "^0.2.38", |
| @@ -109,6 +109,18 @@ test('failed release generation leaves the changelog unchanged', () => { | ||
| 109 | 109 | }) |
| 110 | 110 | }) |
| 111 | 111 | |
| 112 | test('release notes can include changes since the last published release after an abandoned tag', () => { | |
| 113 | fixture((directory, git) => { | |
| 114 | git('commit', '--allow-empty', '-qm', 'feat: native trail maps') | |
| 115 | git('tag', 'v1.0.1') | |
| 116 | writeFileSync(join(directory, 'package.json'), '{"name":"fixture","version":"1.0.2"}') | |
| 117 | const content = generateReleaseChangelog(directory, 'v1.0.0') | |
| 118 | expect(content).toContain('native trail maps') | |
| 119 | expect(content).toContain('/compare/v1.0.0...v1.0.2)') | |
| 120 | expect(git('tag', '--list', 'v1.0.1')).toBe('v1.0.1\n') | |
| 121 | }) | |
| 122 | }) | |
| 123 | ||
| 112 | 124 | test('patch release uses the guarded changelog generator before committing', () => { |
| 113 | 125 | const project = JSON.parse(readFileSync(join(import.meta.dir, '..', 'package.json'), 'utf8')) |
| 114 | 126 | const command = project.scripts['release:patch'] as string |
| @@ -118,14 +130,15 @@ test('patch release uses the guarded changelog generator before committing', () | ||
| 118 | 130 | expect(command).toContain('git add packages/zig/build.zig.zon packages/zig/pantry.json CHANGELOG.md') |
| 119 | 131 | }) |
| 120 | 132 | |
| 121 | test('bumpx commits and tags the guarded changelog without its duplicate generator', () => { | |
| 133 | test('an explicit version commits and tags the guarded changelog without its duplicate generator', () => { | |
| 122 | 134 | fixture((directory, git) => { |
| 123 | 135 | git('commit', '--allow-empty', '-qm', 'Merge pull request #326 from example/feature') |
| 124 | 136 | const bumpx = Bun.resolveSync('@stacksjs/bumpx/bin/cli.js', import.meta.dir) |
| 125 | 137 | const generator = join(import.meta.dir, 'generate-release-changelog.ts') |
| 126 | 138 | const result = Bun.spawnSync([ |
| 127 | process.execPath, bumpx, 'patch', '--commit', '--tag', '--no-push', '--yes', '--no-changelog', | |
| 139 | process.execPath, bumpx, '--recursive', '--commit', '--tag', '--no-push', '--yes', '--no-changelog', | |
| 128 | 140 | '--execute', `bun ${JSON.stringify(generator)} && git add CHANGELOG.md`, |
| 141 | '1.0.2', | |
| 129 | 142 | ], { cwd: directory, stdout: 'pipe', stderr: 'pipe', timeout: 30_000 }) |
| 130 | 143 | expect(result.exitCode, result.stderr.toString()).toBe(0) |
| 131 | 144 | expect(git('tag', '--list', 'v1.0.2')).toBe('v1.0.2\n') |
| @@ -12,12 +12,12 @@ function previousTag(cwd: string): string { | ||
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** Generate the next release section before bumpx commits and tags it. */ |
| 15 | export function generateReleaseChangelog(cwd: string): string { | |
| 15 | export function generateReleaseChangelog(cwd: string, fromRef?: string): string { | |
| 16 | 16 | const version = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')).version |
| 17 | 17 | if (typeof version !== 'string' || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(version)) |
| 18 | 18 | throw new Error('The root package must have a valid release version') |
| 19 | 19 | |
| 20 | const from = previousTag(cwd) | |
| 20 | const from = fromRef ?? previousTag(cwd) | |
| 21 | 21 | const to = `v${version}` |
| 22 | 22 | if (from === to) |
| 23 | 23 | throw new Error(`Release ${to} is already tagged`) |
| @@ -44,4 +44,4 @@ export function generateReleaseChangelog(cwd: string): string { | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if (import.meta.main) |
| 47 | generateReleaseChangelog(process.cwd()) | |
| 47 | generateReleaseChangelog(process.cwd(), process.env.CRAFT_CHANGELOG_FROM) | |