Skip to content

Publish to npm

Publish to npm #1

Workflow file for this run

name: Publish to npm
on:
workflow_dispatch:
release:
types: [published]
permissions:
contents: read
id-token: write
concurrency:
group: publish-npm-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify package
if: github.repository == 'shbernal/gitpulse'
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.13
- name: Ensure npm supports trusted publishing
run: |
npm install -g npm@latest
npm --version
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Verify package metadata
run: |
PACKAGE_NAME="$(node -p "require('./package.json').name")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if [ "$PACKAGE_NAME" != "@shbernal/gitpulse" ]; then
echo "::error::Expected package '@shbernal/gitpulse' but found '$PACKAGE_NAME'."
exit 1
fi
if [ "${{ github.event_name }}" = "release" ] && [ "${{ github.ref_name }}" != "v$PACKAGE_VERSION" ] && [ "${{ github.ref_name }}" != "$PACKAGE_VERSION" ]; then
echo "::error::Release tag '${{ github.ref_name }}' does not match package version '$PACKAGE_VERSION'."
exit 1
fi
- name: Typecheck
run: bun run typecheck
- name: Test
run: bun test
- name: Build
run: bun run build
- name: Verify package contents
run: npm pack --dry-run --ignore-scripts
- name: Verify version is unpublished
run: |
PACKAGE_NAME="$(node -p "require('./package.json').name")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version >/dev/null 2>&1; then
echo "::error::$PACKAGE_NAME@$PACKAGE_VERSION is already published on npm."
exit 1
fi
publish:
name: Publish package
needs: verify
if: github.repository == 'shbernal/gitpulse' && github.event_name == 'release'
runs-on: ubuntu-latest
environment: npm-publish
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.13
- name: Ensure npm supports trusted publishing
run: |
npm install -g npm@latest
npm --version
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build
run: bun run build
- name: Publish to npm
run: npm publish --access public --provenance --ignore-scripts