Repository navigation
Harden npm release publishing #1
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
6 commits
Select commit
Hold shift + click to select a range
d746b45
Harden npm release publishing
FlyOverCoderKY 98b2db2
Declare release helper exports
FlyOverCoderKY 4edbe1b
Add pinned CodeQL analysis
FlyOverCoderKY d04a55d
Honor npm shell fallback
FlyOverCoderKY d803454
Support SHA-256 Git object IDs
FlyOverCoderKY 3430cf0
Address release review findings
FlyOverCoderKY 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: CodeQL | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| schedule: | ||
| - cron: "31 7 * * 1" | ||
|
|
||
| permissions: | ||
| contents: read | ||
| security-events: write | ||
|
|
||
| concurrency: | ||
| group: codeql-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| analyze: | ||
| name: Analyze JavaScript and TypeScript | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
|
|
||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 | ||
| with: | ||
| node-version: 24.18.0 | ||
| package-manager-cache: false | ||
|
|
||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4 | ||
| with: | ||
| languages: javascript-typescript | ||
|
|
||
| - name: Build | ||
| uses: github/codeql-action/autobuild@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4 | ||
|
|
||
| - name: Analyze | ||
| uses: github/codeql-action/analyze@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4 |
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| node_modules/ | ||
| dist/ | ||
| coverage/ | ||
| .release/ | ||
| *.tsbuildinfo | ||
|
|
||
| .env | ||
|
|
||
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,64 @@ | ||
| # Release operations | ||
|
|
||
| `@pegma/spine` publishes only from a stable GitHub release. Merging a pull | ||
| request never publishes, and the workflow has no manual-dispatch or npm-token | ||
| fallback. | ||
|
|
||
| ## Required external configuration | ||
|
|
||
| Before the first release through this workflow: | ||
|
|
||
| - configure `@pegma/spine` on npm with the GitHub Actions trusted publisher | ||
| `pegma-dev/spine`, workflow `publish.yml`, environment `npm-publish`, and | ||
| allowed action `npm publish`; | ||
| - create the GitHub `npm-publish` environment. A second reviewer is not | ||
| required under Pegma's single-maintainer policy; | ||
| - create the repository Actions variable `RELEASE_ALLOWED_SIGNERS` containing | ||
| the reviewed Git SSH allowed-signers entry for the maintainer's release key; | ||
| this is public-key material, not a secret; and | ||
| - create an active tag ruleset targeting `v*` that prevents tag updates and | ||
| deletions and limits tag creation to the release maintainer. | ||
|
|
||
| Do not add `NODE_AUTH_TOKEN`, an npm automation token, or another credential | ||
| fallback. After one trusted-publisher release is verified, disable any | ||
| remaining traditional npm publish tokens. | ||
|
|
||
| ## Release procedure | ||
|
|
||
| The version in `packages/spine/package.json` is the release version. Change it | ||
| through an ordinary reviewed pull request and run the complete gate on Node 22 | ||
| and 24. | ||
|
|
||
| After that pull request is merged, create a signed annotated tag at the exact | ||
| `origin/main` commit, push the tag, verify the fetched tag, and only then | ||
| create the GitHub release with `--verify-tag`. Do not let GitHub create the tag | ||
| and never move or recreate a release tag. | ||
|
|
||
| The release workflow verifies that the tag: | ||
|
|
||
| - is a stable annotated `vX.Y.Z` tag signed by an allowed signer; | ||
| - matches the package version; | ||
| - points to the checkout and the GitHub release-event commit; and | ||
| - is contained in `origin/main`. | ||
|
|
||
| Its preparation job has no OIDC permission. It installs the reviewed npm | ||
| version without dependency caching, runs the full gate, builds and packs once, | ||
| smoke-tests the tarball from a clean consumer, records its SHA-1 and SHA-512 | ||
| integrity, and uploads the exact prepared artifact. | ||
|
|
||
| Only the `npm-publish` job receives `id-token: write`. It installs no | ||
| dependencies, verifies the prepared manifest and tarball hashes against the | ||
| release commit, and publishes that tarball with npm provenance. | ||
|
|
||
| ## Safe retry | ||
|
|
||
| The workflow is globally serialized. Re-run the failed release jobs against | ||
| the unchanged tag: | ||
|
|
||
| - an absent version is published; | ||
| - an existing version with identical `dist.integrity` is verified and skipped; | ||
| - a different integrity, or any registry error other than `E404`, stops the | ||
| release. | ||
|
|
||
| Never unpublish and reuse a version. If any released byte must change, prepare | ||
| a new version and a new signed tag. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
| export interface ReleasePackageDefinition { | ||
| readonly directory: string; | ||
| readonly name: string; | ||
| } | ||
|
|
||
| export interface ValidationOptions { | ||
| readonly root?: string; | ||
| readonly releaseTag?: string; | ||
| readonly releasePrerelease?: boolean | string; | ||
| readonly expectedReleaseCommit?: string; | ||
| readonly requireClean?: boolean; | ||
| readonly requireMainAncestor?: boolean; | ||
| readonly requireReleaseTag?: boolean; | ||
| } | ||
|
|
||
| export interface ReleaseCommandOptions extends ValidationOptions { | ||
| readonly manifest?: string; | ||
| readonly output?: string; | ||
| } | ||
|
|
||
| export interface PublicPackageManifest { | ||
| readonly name: string; | ||
| readonly version: string; | ||
| readonly [key: string]: unknown; | ||
| } | ||
|
|
||
| export interface ValidationResult { | ||
| readonly root: string; | ||
| readonly manifest: PublicPackageManifest; | ||
| readonly packageDirectory: string; | ||
| readonly releaseTag: string | undefined; | ||
| } | ||
|
|
||
| export const RELEASE_PACKAGES: readonly ReleasePackageDefinition[]; | ||
|
|
||
| export function parseArguments( | ||
| arguments_: readonly string[], | ||
| ): ReleaseCommandOptions; | ||
|
|
||
| export function validateRepository( | ||
| options?: ValidationOptions, | ||
| ): Promise<ValidationResult>; | ||
|
|
||
| export function validateReleaseTag(options?: { | ||
| readonly root?: string; | ||
| readonly releaseTag?: string; | ||
| readonly expectedReleaseCommit?: string; | ||
| }): { headCommit: string; releaseTag: string }; | ||
|
|
||
| export function decidePublication( | ||
| localIntegrity: string, | ||
| registryIntegrity: string | null, | ||
| ): "publish" | "skip"; | ||
|
|
||
| export function prepareRelease( | ||
| options?: ReleaseCommandOptions, | ||
| ): Promise<{ manifestPath: string; manifest: unknown }>; | ||
|
|
||
| export function publishPreparedRelease( | ||
| options?: ReleaseCommandOptions, | ||
| ): Promise<void>; |
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.