Skip to content

Commit 3a797c3

Browse files
committed
feat(ci): add publish npm workflow
1 parent 7d0f143 commit 3a797c3

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

.github/workflows/publish-npm.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Publish package
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
env:
9+
node_version: 20
10+
cache-prefix: codecarrot-essentials
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: ${{ inputs.node_version }}
21+
- uses: pnpm/action-setup@v4
22+
name: Install pnpm
23+
id: pnpm-install
24+
with:
25+
version: 9.6.0
26+
27+
- name: Build
28+
run: |
29+
pnpm i --frozen-lockfile --prod=false
30+
pnpm build
31+
32+
- name: Cache 'dist' directory
33+
uses: actions/cache@v4
34+
id: cache-build
35+
with:
36+
path: |
37+
${{ github.workspace }}/dist
38+
# Generate a new cache whenever packages or source files change.
39+
key: |
40+
${{ env.cache-prefix }}-${{ github.sha }}
41+
restore-keys: |
42+
${{ env.cache-prefix }}-${{ github.sha }}
43+
44+
publish-npm:
45+
name: "Publish to NPM"
46+
if: github.event_name == 'push' && github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
47+
runs-on: ubuntu-latest
48+
needs: [build]
49+
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: actions/setup-node@v4
53+
with:
54+
node-version: ${{ inputs.node_version }}
55+
- uses: pnpm/action-setup@v4
56+
name: Install pnpm
57+
id: pnpm-install
58+
with:
59+
version: 9.6.0
60+
61+
- name: Cache 'dist' directory
62+
uses: actions/cache@v4
63+
id: cache-build
64+
with:
65+
path: |
66+
${{ github.workspace }}/dist
67+
key: |
68+
${{ env.cache-prefix }}-${{ github.sha }}
69+
restore-keys: |
70+
${{ env.cache-prefix }}-${{ github.sha }}
71+
72+
- name: Set publishing config
73+
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}"
74+
env:
75+
NODE_AUTH_TOKEN: ${{secrets.PKG_NPM_TOKEN}}
76+
77+
- run: |
78+
pnpm publish --no-git-checks --access=public

0 commit comments

Comments
 (0)