Create npm-publish.yml
This commit is contained in:
parent
536714a31b
commit
55c0279613
53
.github/workflows/npm-publish.yml
vendored
Normal file
53
.github/workflows/npm-publish.yml
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
name: NPM Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build-and-publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js with caching
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
cache: 'npm' # Enables npm dependency caching
|
||||
cache-dependency-path: '**/package-lock.json' # Cache key based on lockfile
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Check version change
|
||||
id: check_version
|
||||
run: |
|
||||
git fetch origin main
|
||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||
PREV_VERSION=$(git show origin/main:package.json | grep '"version":' | sed -E 's/.*"version": *"([^"]+)".*/\1/')
|
||||
if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
|
||||
echo "Version changed from $PREV_VERSION to $CURRENT_VERSION"
|
||||
echo "version_changed=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Version unchanged: $CURRENT_VERSION"
|
||||
echo "version_changed=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Publish to npm
|
||||
if: steps.check_version.outputs.version_changed == 'true'
|
||||
run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
Loading…
x
Reference in New Issue
Block a user