-
Notifications
You must be signed in to change notification settings - Fork 1
63 lines (56 loc) · 2.25 KB
/
npm-publish.yml
File metadata and controls
63 lines (56 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
#
# DISABLED: Manual npm publishing is preferred for this package
# To re-enable: uncomment the 'on:' section below and add NPM_TOKEN secret
name: Node.js Package
# Disabled - uncomment to re-enable automated publishing
# on:
# release:
# types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm ci
# Check if this version already exists on npm
- name: Check if version exists on npm
id: check_version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PACKAGE_NAME=$(node -p "require('./package.json').name")
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version 2>/dev/null; then
echo "version_exists=true" >> $GITHUB_OUTPUT
echo "Version $PACKAGE_VERSION already exists on npm registry"
else
echo "version_exists=false" >> $GITHUB_OUTPUT
echo "Version $PACKAGE_VERSION does not exist on npm registry"
fi
# Only publish if version doesn't exist
- name: Publish to npm
if: steps.check_version.outputs.version_exists == 'false'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
# Skip publishing with informative message
- name: Skip publishing (version exists)
if: steps.check_version.outputs.version_exists == 'true'
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "✅ Skipping npm publish - version $PACKAGE_VERSION already exists on npm registry"
echo "This is expected when the package was published manually before the release"