Skip to content

v1.0.0 : Official release #9

v1.0.0 : Official release

v1.0.0 : Official release #9

Workflow file for this run

name: NPM Publish Workflow
on:
workflow_dispatch:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '21'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Handle Version for Manual Trigger
if: github.event_name == 'workflow_dispatch'
run: |
if ! npm view $(node -p "require('./package.json').name")@$(node -p "require('./package.json').version") version; then
echo "Version does not exist, proceeding with publishing."
else
echo "Version exists, bumping version."
git config --global user.email "[email protected]"
git config --global user.name "EDM115"
npm version patch -m "Bump version to %s due to existing version in registry"
git push --follow-tags
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Set NPM Version for Release Trigger
if: github.event_name == 'release'
run: |
RELEASE_VERSION=$(echo ${{ github.event.release.tag_name }} | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+')
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [ "$RELEASE_VERSION" != "" ]; then
if ! npm view $(node -p "require('./package.json').name")@$RELEASE_VERSION version; then
if [ "v$CURRENT_VERSION" != "$RELEASE_VERSION" ]; then
echo "Release version does not exist in registry and differs from package.json, setting it."
npm version $RELEASE_VERSION --no-git-tag-version
git config --global user.email "[email protected]"
git config --global user.name "EDM115"
git commit -am "Update version to $RELEASE_VERSION"
git push
else
echo "Release version matches package.json but not in registry, safe to publish."
fi
else
echo "Release version exists in registry, bumping version."
npm version patch -m "Bump version to %s due to existing version in registry"
git push --follow-tags
fi
else
echo "Release tag does not follow semantic versioning, reverting to manual trigger logic."
# Fallback to manual trigger logic if release tag is not valid
if ! npm view $(node -p "require('./package.json').name")@"v$CURRENT_VERSION" version; then
echo "Current package.json version does not exist in registry, safe to publish."
else
echo "Current package.json version exists in registry, bumping version."
npm version patch -m "Bump version to %s due to existing version in registry"
git push --follow-tags
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}