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
145 changes: 83 additions & 62 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,31 +68,53 @@ jobs:
- name: Run tests
run: npm test

# Published one workspace at a time, skipping versions already on the
# registry. A repository holding several packages routinely releases with
# only some of them changed, and `npm publish --workspaces` fails the
# whole run on the first unchanged one.
# Two passes so a package is never published before something it depends
# on. Pass 1 takes the packages with no dependency inside this scope,
# pass 2 takes the rest.
- name: Publish
run: |
set -euo pipefail
for pass in 1 2; do
for manifest in packages/*/package.json; do
name=$(node -p "require('./$manifest').name")
version=$(node -p "require('./$manifest').version")
if [ "$(node -p "require('./$manifest').private === true")" = "true" ]; then
continue
fi
dependent=$(node -p "Object.keys(require('./$manifest').dependencies||{}).some(d=>d.startsWith('@pegma/'))")
if [ "$pass" = "1" ] && [ "$dependent" = "true" ]; then continue; fi
if [ "$pass" = "2" ] && [ "$dependent" = "false" ]; then continue; fi
if npm view "$name@$version" version >/dev/null 2>&1; then
echo "skipping $name@$version (already on the registry)"
continue
fi
echo "publishing $name@$version"
npm publish -w "$name" --provenance
done
done
- 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: audit-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: audit-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
Expand Up @@ -2,6 +2,7 @@ node_modules/
dist/
coverage/
*.tsbuildinfo
.release/

.env
.env.*
Expand Down
20 changes: 10 additions & 10 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ Every test that matters here is a test about atomicity. When adding behaviour,
ask what happens when the caller's transaction is refused, and assert that this
package left nothing behind.

Publishing is trusted-publisher only; no tokens exist. A release is
`gh release create vX.Y.Z`, which runs the gate and publishes every changed
workspace package with a provenance attestation. The publish step is idempotent
and dependency-ordered, so it skips versions already on the registry. A
brand-new package cannot use trusted publishing for its first version: publish
it once by hand, then add its trusted publisher on npmjs.com.
Publishing is trusted-publisher only; no tokens exist. Follow
`docs/RELEASING.md`: create and push a signed annotated version tag already on
`origin/main`, then publish the GitHub release for that existing tag. The
workflow prepares and verifies the package without OIDC, and the minimal
environment-scoped publish job receives OIDC only for the exact prepared
tarball. Never add a token fallback or an unprotected manual publish path.

## Where things stand

`@pegma/audit` is at `0.1.0` and unpublished. It offers the event type and its
codec, `defineAudit` binding the package to a caller's records, `action` for
the atomic case, `append` for the case with no accompanying state change,
`history`, and `sweep`.
`@pegma/audit` is published at `0.1.0`. It offers the event type and its codec,
`defineAudit` binding the package to a caller's records, `action` for the
atomic case, `append` for the case with no accompanying state change, `history`,
and `sweep`.

Known gaps, in the order they are likely to matter:

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ the same transaction as the change they describe.

> [!IMPORTANT]
> Audit is in early `0.x` development. Its public API is not stable, its
> package is not published, and it is not ready for production use.
> package is published for evaluation, and it is not ready for production use.

## Why it exists

Expand Down Expand Up @@ -178,6 +178,9 @@ npm run check
npm test
```

Maintainer releases use npm trusted publishing and the signed-tag procedure in
[docs/RELEASING.md](docs/RELEASING.md).

## License

MIT. Copyright (c) 2026 RetireGolden, LLC.
5 changes: 3 additions & 2 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Status

**Stage:** Phase 1 complete; awaiting the first real consumer
(`0.x`, public API unstable, unpublished)
(`0.1.0` published, public API unstable)

**Initial reference application:** RetireGolden, through
`@pegma/authorization-core` and the Pegma support desk
Expand Down Expand Up @@ -275,7 +275,8 @@ already solved this its own way.
stored twice so history cannot drift from the lifecycle. This package
stores the payload; that is a real difference and it may be the right one
or it may not.
- [ ] Publish `0.1.0` by hand, then configure the trusted publisher.
- [x] Publish `0.1.0`; future releases use the trusted publisher and the
signed-tag procedure in `RELEASING.md`.
- [ ] Record what the migration had to work around, in this document.

### Phase 3 — second consumer and the shape's verdict
Expand Down
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/audit` 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/audit` on npm with the GitHub Actions trusted publisher
`pegma-dev/audit`, 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/audit/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.
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 append-only audit records for Pegma components.",
"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
Loading