Skip to content

Commit c6bd767

Browse files
committed
ci: add npm publish workflow
1 parent e716f80 commit c6bd767

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

.github/workflows/npm-package.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy to npm
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: "18"
25+
cache: "npm"
26+
registry-url: "https://registry.npmjs.org"
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Lint
32+
run: npm run lint
33+
34+
- name: Build
35+
run: npm run build
36+
37+
- name: Test
38+
run: npm run test:only
39+
40+
- name: Publish to npm
41+
run: |
42+
VERSION=$(node -p "require('./package.json').version")
43+
PACKAGE=$(node -p "require('./package.json').name")
44+
OUTPUT=$(npm publish --provenance --access public 2>&1) || {
45+
if echo "$OUTPUT" | grep -q "cannot publish over the previously published"; then
46+
echo "${PACKAGE}@${VERSION} already published, skipping"
47+
exit 0
48+
fi
49+
echo "$OUTPUT" >&2
50+
exit 1
51+
}
52+
echo "$OUTPUT"

0 commit comments

Comments
 (0)