Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add npm publish GitHub workflow #11

Merged
merged 1 commit into from
Oct 7, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Package to npmjs

on:
push:
branches: [ main ]

jobs:
build:
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
with:
node-version: '18.17.0'
registry-url: 'https://registry.npmjs.org'

- name: Check if package version has changed
id: check
run: |
LATEST_VERSION=$(npm view . version)
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version changed from $LATEST_VERSION to $CURRENT_VERSION"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version unchanged"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi

- name: Install dependencies
if: steps.check.outputs.version_changed == 'true'
run: npm ci

- name: Publish to npm
if: steps.check.outputs.version_changed == 'true'
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading