Repository navigation
ci(release): only release commits that are on main #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { spawnSync } from 'node:child_process' | ||
| import { readFileSync } from 'node:fs' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { parse } from 'yaml' | ||
|
|
||
| // Regression guard for the release gate: a `v*` tag (or a dispatch) pointing at a commit that is | ||
| // not on main must not build or publish anything — not the GitHub Release, not npm. | ||
| const workflow = parse(readFileSync(new URL('../.github/workflows/release.yml', import.meta.url), 'utf8')) | ||
| const jobs: Record<string, { needs?: string | string[]; steps: { name?: string; run?: string }[] }> = workflow.jobs | ||
| const needsOf = (job: string) => [jobs[job].needs ?? []].flat() | ||
|
|
||
| const gateStep = jobs['require-main'].steps.find((s) => s.name === 'Require the commit to be on main') | ||
|
|
||
| describe('release workflow main-only gate', () => { | ||
| it('has the gate job with no dependencies of its own', () => { | ||
| expect(gateStep?.run).toContain('compare/$SHA...main') | ||
| expect(needsOf('require-main')).toEqual([]) | ||
| }) | ||
|
|
||
| it('makes every other job depend on the gate directly', () => { | ||
| for (const name of Object.keys(jobs).filter((j) => j !== 'require-main')) { | ||
| expect(needsOf(name), name).toContain('require-main') | ||
| } | ||
| }) | ||
|
|
||
| it.skipIf(process.platform === 'win32').each([ | ||
| { status: 'ahead', ok: true }, | ||
| { status: 'identical', ok: true }, | ||
| { status: 'behind', ok: false }, | ||
| { status: 'diverged', ok: false }, | ||
| { status: '', ok: false }, | ||
| ])('compare status $status -> passes=$ok', ({ status, ok }) => { | ||
| // Stub `gh` with a shell function that prints the compare status the API would return. | ||
| const script = `set -e\ngh() { printf '%s\\n' "$STATUS"; }\n${gateStep!.run}` | ||
| const r = spawnSync('bash', ['-c', script], { | ||
| env: { ...process.env, STATUS: status, SHA: 'abc123', GITHUB_REPOSITORY: 'o/r' }, | ||
| encoding: 'utf8', | ||
| }) | ||
| // Exact exit code and the gate's own message, so a crash in the script can't pass as a refusal. | ||
| expect(r.status, r.stdout + r.stderr).toBe(ok ? 0 : 1) | ||
| if (!ok) expect(r.stdout).toContain('is not on main') | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.