Skip to content

add versin managemt

add versin managemt #2

Workflow file for this run

name: Publish Package to npmjs
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Setup Node.js
- uses: actions/setup-node@v3
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
# Install dependencies and build
- run: npm install --force && npm run build
# Prepare dist folder
- run: |
cp ./package.json ./dist/
echo '//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}' > ./dist/.npmrc
# Resolve version: bump patch number
- run: |
set -x
cd ./dist
PACKAGE=$(jq -r '.name' package.json)
VERNPM=$(curl -s https://registry.npmjs.org/$PACKAGE | jq -r '.["dist-tags"].latest')
if [[ "$VERNPM" == "null" || -z "$VERNPM" ]]; then
echo "First publish or no latest tag, keeping package.json version."
VERLOC=$(jq -r '.version' package.json)
VEROUT=$VERLOC
else
VEROUT=$(echo $VERNPM | awk -F. -v OFS=. '{$NF+=1; print}')
fi
jq --arg ver "$VEROUT" '.version = $ver' package.json > package.tmp.json
mv package.tmp.json package.json
cat package.json
# Publish to npm
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
working-directory: ./dist