Skip to content
Merged
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
57 changes: 39 additions & 18 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,64 @@
name: Publish
on:
push:
tags:
- 'v*'
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Get version from tag
id: get_version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Show version being published
run: echo "Publishing version ${{ steps.get_version.outputs.version }} to npm"


- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: "20.x"

- name: Create .npmrc file
run: |
echo "//registry.npmjs.org/:_authToken=\${NPM_AUTH_TOKEN}" > .npmrc
echo "registry=https://registry.npmjs.org/" >> .npmrc

- name: Install dependencies
run: npm ci
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Run tests
run: npm test

- name: Build
run: npm run build


- name: Get current package version
id: current_version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT

- name: Get published version
id: published_version
run: |
PUBLISHED_VERSION=$(npm view usagey version 2>/dev/null || echo "0.0.0")
echo "version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Compare versions
id: version_check
run: |
CURRENT="${{ steps.current_version.outputs.version }}"
PUBLISHED="${{ steps.published_version.outputs.version }}"
echo "Current version: $CURRENT"
echo "Published version: $PUBLISHED"

if [ "$CURRENT" != "$PUBLISHED" ]; then
echo "should_publish=true" >> $GITHUB_OUTPUT
echo "New version detected - will publish"
else
echo "should_publish=false" >> $GITHUB_OUTPUT
echo "No version change - skipping publish"
fi

- name: Publish to npm
if: steps.version_check.outputs.should_publish == 'true'
run: npm publish --access public
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
Loading