-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (45 loc) 路 1.45 KB
/
Copy pathnpm-publish.yml
File metadata and controls
55 lines (45 loc) 路 1.45 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
on:
push:
branches:
- main
name: npm-publish
permissions:
contents: write
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: "24"
registry-url: https://registry.npmjs.org
- name: Update npm to latest version
run: npm install -g npm@latest
- run: npm ci
- run: npm test
- name: Publish to npm
id: publish
run: |
# Verify npm version supports OIDC
echo "npm version: $(npm --version)"
# Check if version is already published
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version 2>/dev/null; then
echo "Version $PACKAGE_VERSION already published"
echo "type=" >> $GITHUB_OUTPUT
else
echo "Publishing $PACKAGE_NAME@$PACKAGE_VERSION..."
npm publish --access public
echo "type=patch" >> $GITHUB_OUTPUT
echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
fi
- if: ${{ steps.publish.outputs.type }}
name: Create Release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="v${{ steps.publish.outputs.version }}"
gh release create $VERSION --generate-notes