Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/codeql.yml
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
119 changes: 83 additions & 36 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
# Publishes every public workspace package to npm.
#
# Runs when a GitHub release is published, so the tag, the release notes, and
# the published version are one action rather than three.
#
# AUTHENTICATION
#
# This package is configured on npmjs.com to accept publishes only from a
# trusted publisher: this repository, this workflow file. Authentication is a
# short-lived OIDC token minted per run, so there is no long-lived credential
# to leak, rotate, or forget to delete. `--provenance` additionally attaches a
# signed attestation tying the tarball to the commit that built it.
#
# There is deliberately no token fallback. If OIDC fails, the publish should
# fail loudly rather than quietly reaching for a secret.
#
# Bootstrapping a NEW package is the one case this cannot cover: npm will not
# let you configure a trusted publisher for a package that does not exist yet
# (https://github.com/npm/cli/issues/8544). Publish version 0.1.0 once from a
# workstation with `npm publish -w <package>`, add the trusted publisher on
# npmjs.com, and every release after that runs here.
# Publishes the exact tarball prepared from a stable GitHub release tag.
# Authentication is npm trusted-publisher OIDC only; no token fallback exists.

name: Publish

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: read
id-token: write # OIDC: trusted publishing and provenance attestation

concurrency:
group: publish-${{ github.ref }}
group: npm-publish
cancel-in-progress: false

jobs:
publish:
prepare:
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}
RELEASE_COMMIT: ${{ github.sha }}
RELEASE_ALLOWED_SIGNERS: ${{ vars.RELEASE_ALLOWED_SIGNERS }}

steps:
- name: Check out repository
- name: Check out the release tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: refs/tags/${{ github.event.release.tag_name }}
fetch-depth: 0

- name: Fetch the protected release branch
run: git fetch --no-tags origin main:refs/remotes/origin/main

- name: Configure approved release signers
shell: bash
run: |
if [[ -z "${RELEASE_ALLOWED_SIGNERS}" ]]; then
echo "::error::RELEASE_ALLOWED_SIGNERS must contain the reviewed SSH allowed-signers entries"
exit 1
fi
allowed_signers="${RUNNER_TEMP}/release-allowed-signers"
umask 077
printf '%s\n' "${RELEASE_ALLOWED_SIGNERS}" > "${allowed_signers}"
git config --local gpg.format ssh
git config --local gpg.ssh.allowedSignersFile "${allowed_signers}"

- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24
cache: npm
node-version: 24.18.0
registry-url: https://registry.npmjs.org
package-manager-cache: false

# Trusted publishing needs npm 11.5.1 or newer, which is ahead of what
# some Node images bundle.
- name: Use a current npm
run: npm install -g npm@latest
- name: Use the reviewed npm release
run: npm install --global npm@11.18.0

- name: Install dependencies
run: npm ci

# Publishing runs the same gate as CI. A release should never ship
# something that would have failed a pull request.
- name: Check formatting
run: npm run format:check

Expand All @@ -69,5 +68,53 @@ jobs:
- name: Run tests
run: npm test

- name: Publish
run: npm publish --workspaces --provenance
- name: Prepare and verify the release tarball
run: npm run release:pack -- -- --require-clean --require-main-ancestor --require-release-tag --expected-release-commit "${RELEASE_COMMIT}" --output .release

- name: Upload the prepared release
id: upload
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: spine-release-${{ github.run_id }}
path: .release/
if-no-files-found: error
include-hidden-files: true
overwrite: true
retention-days: 30

- name: Record the prepared artifact digest
run: echo "Prepared artifact SHA-256 ${{ steps.upload.outputs.artifact-digest }}" >> "${GITHUB_STEP_SUMMARY}"

publish:
needs: prepare
runs-on: ubuntu-latest
environment: npm-publish
permissions:
contents: read
id-token: write
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_COMMIT: ${{ github.sha }}

steps:
- name: Check out the exact release tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: refs/tags/${{ github.event.release.tag_name }}
fetch-depth: 1

- name: Set up Node.js and the npm registry
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24.18.0
registry-url: https://registry.npmjs.org
package-manager-cache: false

Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
- name: Download the prepared release
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: spine-release-${{ github.run_id }}
path: .release

- name: Publish the verified prepared tarball
run: npm run release:publish -- -- --expected-release-commit "${RELEASE_COMMIT}" --manifest .release/package-manifest.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
dist/
coverage/
.release/
*.tsbuildinfo

.env
Expand Down
8 changes: 5 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ exclude `src/**/*.test.ts`, or compiled tests are published to consumers.
Work on a `claude/*` branch and open a pull request. The gate is
`npm run format:check`, `npm run check`, `npm test` — all three, on Node 22 and 24.

Publishing is trusted-publisher only; no tokens exist. A release is
`gh release create vX.Y.Z`, which runs the gate and publishes with a provenance
attestation.
Publishing is trusted-publisher only; no tokens exist. A release starts from a
protected signed annotated `vX.Y.Z` tag already on `origin/main`, followed by
`gh release create vX.Y.Z --verify-tag`. The unprivileged preparation job runs
the gate and packs the exact artifact; only the minimal publish job receives
OIDC authority. See `docs/RELEASING.md`.

## Where things stand

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ npm test
npm run format:check
```

Maintainers should follow [the release runbook](docs/RELEASING.md). Releases
publish only from protected signed tags through npm trusted publishing.

## License

[MIT](LICENSE) © 2026 RetireGolden, LLC
64 changes: 64 additions & 0 deletions docs/RELEASING.md
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.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Shared identity, time, logging, and event contracts for the Pegma component ecosystem.",
"license": "MIT",
"type": "module",
"packageManager": "npm@11.18.0",
"engines": {
"node": ">=22"
},
Expand All @@ -17,6 +18,9 @@
"clean": "tsc -b --clean",
"format": "prettier --write .",
"format:check": "prettier --check .",
"release:check": "node scripts/release-packages.mjs check",
"release:pack": "node scripts/release-packages.mjs pack",
"release:publish": "node scripts/release-packages.mjs publish",
"test": "npm run build && vitest run"
},
"devDependencies": {
Expand Down
61 changes: 61 additions & 0 deletions scripts/release-packages.d.mts
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>;
Loading