-
Notifications
You must be signed in to change notification settings - Fork 0
fix(release): bind artifact build to exact tag checkout #326
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
9 commits
Select commit
Hold shift + click to select a range
cf64209
test(release): require exact credential-free artifact checkout
seonghobae cbab679
fix(release): attest exact credential-free artifact checkout
seonghobae 68b0c59
test(release): expose prerelease fake-success path
seonghobae b4b13cc
fix(release): fail closed on prerelease tags
seonghobae 2e31d4c
chore(release): preserve workflow formatting
seonghobae 2e604d1
test(release): preserve scoped tag semantics
seonghobae 0623c22
fix(release): preserve prerelease scope after exact checkout hardening
seonghobae c255afb
test(release): require current checkout action baseline
seonghobae 42f05e6
fix(release): align artifact checkout action baseline
seonghobae 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { resolve } from 'node:path'; | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const RELEASE_CHECKOUT_ACTION = | ||
| 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1'; | ||
|
|
||
| /** Read one authoritative repository file as UTF-8 text. */ | ||
| function repositoryFile(path: string): string { | ||
| return readFileSync(resolve(process.cwd(), path), 'utf8'); | ||
| } | ||
|
|
||
| /** Extract one top-level workflow job without allowing another job to satisfy it. */ | ||
| function workflowJob(source: string, jobName: string, nextJobName: string): string { | ||
| const start = source.indexOf(` ${jobName}:`); | ||
| const end = source.indexOf(` ${nextJobName}:`, start + 1); | ||
| expect(start).toBeGreaterThan(-1); | ||
| expect(end).toBeGreaterThan(start); | ||
| return source.slice(start, end); | ||
| } | ||
|
|
||
| /** Extract one named workflow step so unrelated steps cannot satisfy its contract. */ | ||
| function workflowStep(source: string, stepName: string, nextStepName: string): string { | ||
| const start = source.indexOf(` - name: ${stepName}`); | ||
| const end = source.indexOf(` - name: ${nextStepName}`, start + 1); | ||
| expect(start).toBeGreaterThan(-1); | ||
| expect(end).toBeGreaterThan(start); | ||
| return source.slice(start, end); | ||
| } | ||
|
|
||
| describe('release artifact checkout authority', () => { | ||
| it('binds the artifact build to the repository checkout baseline and exact tag SHA before setup', () => { | ||
| const workflow = repositoryFile('.github/workflows/release.yml'); | ||
| const buildJob = workflowJob( | ||
| workflow, | ||
| 'build-release-artifacts', | ||
| 'browser-release-evidence', | ||
| ); | ||
| const checkoutStep = workflowStep( | ||
| buildJob, | ||
| 'Check out the tagged source', | ||
| 'Verify exact checkout', | ||
| ); | ||
| const verifyStep = workflowStep( | ||
| buildJob, | ||
| 'Verify exact checkout', | ||
| 'Set up pnpm', | ||
| ); | ||
|
|
||
| expect(checkoutStep).toContain(`uses: ${RELEASE_CHECKOUT_ACTION}`); | ||
| expect(checkoutStep).toContain('with:'); | ||
| expect(checkoutStep).toContain('ref: ${{ github.sha }}'); | ||
| expect(checkoutStep).toContain('fetch-depth: 0'); | ||
| expect(checkoutStep).toContain('persist-credentials: false'); | ||
| expect(verifyStep).toContain('INKSPAN_EXPECTED_HEAD_SHA: ${{ github.sha }}'); | ||
| expect(verifyStep).toContain('actual_head="$(git rev-parse HEAD)"'); | ||
| expect(verifyStep).toContain( | ||
| 'test "$actual_head" = "$INKSPAN_EXPECTED_HEAD_SHA"', | ||
| ); | ||
|
|
||
| expect(buildJob.indexOf('name: Verify exact checkout')).toBeLessThan( | ||
| buildJob.indexOf('name: Set up pnpm'), | ||
| ); | ||
| expect(buildJob.indexOf('name: Verify exact checkout')).toBeLessThan( | ||
| buildJob.indexOf('name: Set up Node.js'), | ||
| ); | ||
| expect(buildJob.indexOf('name: Verify exact checkout')).toBeLessThan( | ||
| buildJob.indexOf('name: Set up Python'), | ||
| ); | ||
| }); | ||
|
|
||
| it('preserves the established prerelease tag semantics while npm publication remains gated', () => { | ||
| const workflow = repositoryFile('.github/workflows/release.yml'); | ||
| const buildJob = workflowJob( | ||
| workflow, | ||
| 'build-release-artifacts', | ||
| 'browser-release-evidence', | ||
| ); | ||
| const identityStep = workflowStep( | ||
| buildJob, | ||
| 'Verify release identity and current main tip', | ||
| 'Install JavaScript dependencies', | ||
| ); | ||
|
|
||
| expect(identityStep).toContain( | ||
| "if (!/^v(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-[0-9A-Za-z.-]+)?$/.test(releaseTag))", | ||
| ); | ||
| expect(identityStep).toContain('Release tag is not valid semantic version syntax'); | ||
| expect(identityStep).not.toContain('valid stable semantic version syntax'); | ||
| expect(workflow).toContain( | ||
| "github.repository == 'ContextualWisdomLab/inkspan' && !contains(github.ref_name, '-')", | ||
| ); | ||
| }); | ||
| }); | ||
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.