Skip to content

Palex publish workflow #4

Palex publish workflow

Palex publish workflow #4

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
- 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]+')
if [ "$RELEASE_VERSION" != "" ]; then
if ! npm view $(node -p "require('./package.json').name")@$RELEASE_VERSION version; then
echo "Release version does not exist, setting version in package.json."
npm version $RELEASE_VERSION --no-git-tag-version
else
echo "Release version exists, proceeding without change."
fi
else
echo "Release tag does not follow semantic versioning. Checking current package.json version."
if ! npm view $(node -p "require('./package.json').name")@$(node -p "require('./package.json').version") version; then
echo "Current version does not exist, safe to publish."
else
echo "Current 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
fi
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}