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
85 changes: 50 additions & 35 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
name: Release

name: Publish package to npmjs registry
on:
release:
types: [created]
types: [published]

jobs:
build:
publish-npm:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/checkout@v7
with:
node-version: "22.x"

- name: Install dependencies
run: npm install

- name: Build
run: npm run build-ts

# Tarball name matches npm’s naming for this scoped package (see npm pack output)
- name: Pack the npm package
id: pack
run: echo "filename=$(npm pack | tail -1)" >> "$GITHUB_OUTPUT"

- name: Publish to npm
id: publish_npm
uses: JS-DevTools/npm-publish@v3
ref: ${{ github.event.release.tag_name }}
persist-credentials: false
- uses: actions/setup-node@v7
with:
token: ${{ secrets.NPM_TOKEN }}
# access: public # Uncomment if this package’s first npm publish must be public

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
node-version: 24
registry-url: https://registry.npmjs.org/
cache: 'npm'
- name: Check the release tag matches package.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
PKG_VERSION="v$(node -p "require('./package.json').version")"
if [ "$RELEASE_TAG" != "$PKG_VERSION" ]; then
echo "::error::release tag $RELEASE_TAG does not match package.json version $PKG_VERSION"
exit 1
fi
- run: npm ci
- run: npm run build-ts
- name: Update npm
run: npm install -g npm@latest
- name: Release
run: npm publish --access public --tag ${{ github.event.release.prerelease && 'beta' || 'latest' }}

upload-release-asset:
runs-on: ubuntu-latest
needs: publish-npm
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ steps.pack.outputs.filename }}
asset_name: ${{ steps.pack.outputs.filename }}
asset_content_type: application/gzip
ref: ${{ github.event.release.tag_name }}
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 24
cache: 'npm'
- run: npm ci
- run: npm run build-ts
- name: Pack
run: npm pack
- name: Attach the tarball to the release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: gh release upload "$RELEASE_TAG" ./*.tgz --clobber
Loading
Loading