File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed
Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Publish package
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths :
8+ - " package.json"
9+
10+ jobs :
11+ publish :
12+ runs-on : ubuntu-latest
13+ permissions :
14+ contents : read
15+ actions : write
16+
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
21+ - name : Setup Node.js
22+ uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
23+ with :
24+ node-version : " 22"
25+ registry-url : " https://registry.npmjs.org"
26+
27+ - name : Install pnpm
28+ uses : pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
29+ with :
30+ version : latest
31+ run_install : false
32+
33+ - name : Get pnpm store directory
34+ id : pnpm-cache
35+ shell : bash
36+ run : |
37+ echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
38+
39+ - name : Setup pnpm cache
40+ uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
41+ with :
42+ path : ${{ steps.pnpm-cache.outputs.STORE_PATH }}
43+ key : ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
44+ restore-keys : |
45+ ${{ runner.os }}-pnpm-store-
46+
47+ - name : Install dependencies
48+ run : pnpm install
49+
50+ - name : Build
51+ run : pnpm build
52+
53+ - name : Check if version exists
54+ id : version-check
55+ run : |
56+ PACKAGE_NAME=$(node -p "require('./package.json').name")
57+ PKG_VERSION=$(node -p "require('./package.json').version")
58+
59+ if npm view $PACKAGE_NAME@$PKG_VERSION version &> /dev/null; then
60+ echo "Version $PKG_VERSION already exists, skipping publish"
61+ echo "exists=true" >> $GITHUB_OUTPUT
62+ else
63+ echo "Version $PKG_VERSION does not exist, will publish"
64+ echo "exists=false" >> $GITHUB_OUTPUT
65+ fi
66+
67+ - name : Publish to npm
68+ if : steps.version-check.outputs.exists == 'false'
69+ run : pnpm publish --access public
70+ env :
71+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
You can’t perform that action at this time.
0 commit comments