Skip to content

release-v.0.0.3.337-code-maxopt-f3ems-alpha-s #79

release-v.0.0.3.337-code-maxopt-f3ems-alpha-s

release-v.0.0.3.337-code-maxopt-f3ems-alpha-s #79

Workflow file for this run

name: Publish npm Package
on:
release:
types: [published]
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm install
- name: Extract version from release tag
if: github.event_name == 'release'
run: |
VERSION="${{ github.event.release.tag_name }}"
# Remove 'v' prefix if present, or use the tag as version base
VERSION=$(echo "$VERSION" | sed 's/^v//')
# If version doesn't match semver, use run number as patch version
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
VERSION="1.0.${{ github.run_number }}"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Set the version in package.json - fail if npm version fails for unexpected reasons
npm version "$VERSION" --no-git-tag-version --allow-same-version
- name: Set version for workflow_dispatch
if: github.event_name == 'workflow_dispatch'
run: |
VERSION="1.0.${{ github.run_number }}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
npm version "$VERSION" --no-git-tag-version --allow-same-version
- name: Publish to npm
run: |
if [ -z "$NODE_AUTH_TOKEN" ]; then
echo "⚠️ Skipping npm publish: NPM_TOKEN secret is not configured."
exit 0
fi
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}