Skip to content

Commit 6c06cfb

Browse files
committed
feat: add publish.yml
1 parent 01eeab7 commit 6c06cfb

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/publish.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: build and publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
id-token: write
10+
11+
jobs:
12+
bp:
13+
name: build and publish to npmjs
14+
runs-on: ubuntu-22.04
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Check if version changed
23+
id: version-check
24+
run: |
25+
if git diff HEAD^ HEAD -- package.json | grep -q '"version"'; then
26+
echo "changed=true" >> $GITHUB_OUTPUT
27+
else
28+
echo "changed=false" >> $GITHUB_OUTPUT
29+
fi
30+
31+
- name: Setup Node.js
32+
if: steps.version-check.outputs.changed == 'true'
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: "20"
36+
registry-url: "https://registry.npmjs.org"
37+
38+
- name: Setup pnpm
39+
if: steps.version-check.outputs.changed == 'true'
40+
uses: pnpm/action-setup@v4
41+
with:
42+
version: 9
43+
44+
- name: install
45+
if: steps.version-check.outputs.changed == 'true'
46+
run: pnpm install --frozen-lockfile
47+
48+
- name: build and publish
49+
if: steps.version-check.outputs.changed == 'true'
50+
working-directory: ./
51+
run: |
52+
pnpm build
53+
npm publish --access public --provenance
54+
env:
55+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)