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
56 changes: 56 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish

# Publishing runs here rather than from a laptop, so a release never depends on who
# happens to hold a working `npm login`. Tags in this repo are bare versions (0.3.1),
# not v-prefixed.
on:
push:
tags: ['[0-9]*.[0-9]*.[0-9]*']
workflow_dispatch:

permissions:
contents: read
# Lets npm attach a provenance attestation, so consumers can verify the tarball was
# built from this commit by this workflow.
id-token: write

jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v7

- uses: actions/setup-node@v6
with:
node-version: 22
registry-url: https://registry.npmjs.org
cache: npm

- run: npm ci

# The tag decides what gets published, so a tag that disagrees with package.json
# would ship a version nobody asked for. This is exactly how 0.3.0 went wrong:
# the tag existed while package.json still said 0.2.0.
- name: Verify tag matches package.json
if: github.ref_type == 'tag'
run: |
tag="${GITHUB_REF_NAME}"
packageVersion="$(node -p "require('./package.json').version")"
if [ "$tag" != "$packageVersion" ]; then
echo "::error::Tag ${tag} does not match package.json version ${packageVersion}"
exit 1
fi

- run: npm run lint
- run: npm run format:check
- run: npm test
- run: npm run build

# --access public is required for a scoped package; without it npm defaults to
# restricted and rejects the publish.
- name: Publish to npm
run: npm publish --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"LICENSE"
],
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
Expand Down