Skip to content

Commit 6182460

Browse files
DavertMikclaude
andcommitted
ci: add auto-publish workflow with npm provenance
Two workflows: - test.yml: runs typecheck + full test suite on push/PR against Node 18, 20, 22 - publish.yml: auto-publishes on GitHub release using npm trusted publishing (OIDC via id-token: write — no NPM_TOKEN secret needed), upgrades to latest npm for best provenance support, auto-selects latest/beta dist-tag based on release tag, and publishes with --provenance --access public so each version is cryptographically linked to codeceptjs/reflection. package.json now declares repository, homepage, bugs, and publishConfig.{ access: public, provenance: true } — required for npm provenance to link published tarballs back to this repo. Release flow: git push --follow-tags → GitHub release → auto-publish. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 17c2bdf commit 6182460

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish to npm
2+
3+
# Auto-publishes @codeceptjs/reflection to npm on every GitHub release.
4+
# Uses npm provenance (sigstore transparency log) so the published package
5+
# is cryptographically linked to this repo (codeceptjs/reflection) and the
6+
# exact workflow run that built it.
7+
#
8+
# Tag the release with a SemVer tag like `v0.4.0` or `v0.5.0-beta.1`.
9+
# - Stable tags (no prerelease suffix) publish under the default `latest` dist-tag.
10+
# - Prereleases (alpha/beta/rc) publish under the `beta` dist-tag.
11+
12+
on:
13+
release:
14+
types: [published]
15+
16+
# Required for npm provenance: id-token grants OIDC to the workflow so npm
17+
# can verify the build came from this repository's Actions runner.
18+
permissions:
19+
contents: read
20+
id-token: write
21+
22+
jobs:
23+
publish:
24+
name: Publish @codeceptjs/reflection (provenance)
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout codeceptjs/reflection at release ref
29+
uses: actions/checkout@v4
30+
with:
31+
ref: ${{ github.event.release.target_commitish }}
32+
33+
- name: Setup Node 22 with npm registry
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 22
37+
registry-url: 'https://registry.npmjs.org'
38+
39+
- name: Install dependencies
40+
run: npm install
41+
42+
# Upgrade npm to the latest version — provenance support improves with
43+
# every release and we want the most up-to-date signer on every publish.
44+
- name: Install latest npm
45+
run: npm install -g npm@latest
46+
47+
- name: Typecheck
48+
run: npm run typecheck
49+
50+
- name: Run tests before publishing
51+
run: npm test
52+
53+
- name: Set package version from release tag
54+
run: |
55+
TAG="${{ github.event.release.tag_name }}"
56+
VERSION="${TAG#v}"
57+
echo "Publishing @codeceptjs/reflection version $VERSION"
58+
npm version "$VERSION" --no-git-tag-version
59+
60+
- name: Determine dist-tag
61+
id: disttag
62+
run: |
63+
if [[ "${{ github.event.release.prerelease }}" == "true" ]] \
64+
|| [[ "${{ github.event.release.tag_name }}" == *alpha* ]] \
65+
|| [[ "${{ github.event.release.tag_name }}" == *beta* ]] \
66+
|| [[ "${{ github.event.release.tag_name }}" == *rc* ]]; then
67+
echo "tag=beta" >> "$GITHUB_OUTPUT"
68+
else
69+
echo "tag=latest" >> "$GITHUB_OUTPUT"
70+
fi
71+
72+
# `--provenance` requires npm >= 9.5.0 (we installed latest above).
73+
# Auth uses npm trusted publishing via OIDC (id-token: write above) —
74+
# no NPM_TOKEN secret needed. The published package gets a provenance
75+
# statement linking it to this workflow run at github.com/codeceptjs/reflection.
76+
- name: Publish to npm with provenance
77+
run: npm publish --provenance --access public --tag ${{ steps.disttag.outputs.tag }}

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test (Node ${{ matrix.node }})
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
node: [18, 20, 22]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node }}
24+
registry-url: 'https://registry.npmjs.org'
25+
26+
- run: npm install
27+
28+
- name: Typecheck
29+
run: npm run typecheck
30+
31+
- name: Unit + integration tests
32+
run: npm test

0 commit comments

Comments
 (0)