Skip to content

Remove npmrc

Remove npmrc #6

Workflow file for this run

name: Publish to npm on Version Bump
# Trigger the workflow on push events to the master branch
on:
push:
branches:
- master
# Optional: Run only when package.json is modified
# paths:
# - 'package.json'
jobs:
publish:
runs-on: ubuntu-latest
steps:
# 1. Checkout the repository code
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for version comparison
# 2. Setup Node.js environment
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # Specify your Node.js version
registry-url: 'https://registry.npmjs.org/'
# 3. Install dependencies
- name: Install dependencies
run: npm install
# 4. Get the current version from package.json
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "current_version=$CURRENT_VERSION" >> $GITHUB_ENV
# 5. Get the latest published version from npm
- name: Get latest published version from npm
id: latest_version
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
# Fetch the latest version from npm registry
LATEST_VERSION=$(npm view "$PACKAGE_NAME" version || echo "0.0.0")
echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV
# 6. Compare versions to detect a bump
- name: Check for version bump
id: version_check
run: |
if [ "${{env.latest_version}}" != "${{env.current_version}}" ]; then
echo "version_bumped=true" >> $GITHUB_ENV
else
echo "version_bumped=false" >> $GITHUB_ENV
fi
# 7. Publish to npm if version is bumped
- name: Publish to npm
if: env.version_bumped == 'true'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# 8. Notify if no version bump detected (optional)
- name: Notify no version bump
if: env.version_bumped != 'true'
run: echo "No version bump detected. Skipping npm publish."