feat: adding auto publish pipeline
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
name: Publish to npm
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'package.json' # se déclenche uniquement si package.json change
|
||||
|
||||
jobs:
|
||||
check-and-publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 2 # pour pouvoir comparer avec le commit précédent
|
||||
|
||||
- name: Check if version changed
|
||||
id: version_check
|
||||
run: |
|
||||
PREV=$(git show HEAD~1:package.json | node -p "require('/dev/stdin').version" 2>/dev/null || echo "none")
|
||||
CURR=$(node -p "require('./package.json').version")
|
||||
echo "prev=$PREV"
|
||||
echo "curr=$CURR"
|
||||
if [ "$PREV" != "$CURR" ]; then
|
||||
echo "changed=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "changed=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Setup Node
|
||||
if: steps.version_check.outputs.changed == 'true'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Update npm
|
||||
if: steps.version_check.outputs.changed == 'true'
|
||||
run: npm install -g npm@latest
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.version_check.outputs.changed == 'true'
|
||||
run: npm ci
|
||||
|
||||
- name: Publish
|
||||
if: steps.version_check.outputs.changed == 'true'
|
||||
run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
Reference in New Issue
Block a user