Skip to content

Commit 8808e57

Browse files
feat(ci): add comprehensive GitHub Actions workflows for testing, linting, and npm publishing
- Enhanced CI workflow with Node.js matrix testing (18, 20, 22) - Added pnpm caching for faster builds - Created npm-publish workflow for automated releases to npm and GitHub Packages - Updated github-package workflow to use pnpm - Fixed package.json publishConfig to allow npm registry publishing
1 parent 4270337 commit 8808e57

File tree

4 files changed

+237
-20
lines changed

4 files changed

+237
-20
lines changed
Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,89 @@
1-
name: Node.js Github Package
1+
name: Publish to GitHub Packages
22

33
on:
4-
release:
5-
types: [created]
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v*'
68

79
jobs:
8-
build:
10+
test:
911
runs-on: ubuntu-latest
1012
steps:
1113
- uses: actions/checkout@v4
12-
- uses: actions/setup-node@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
1317
with:
14-
node-version: 20
15-
- run: npm ci
16-
- run: npm test
18+
node-version: '20'
19+
20+
- name: Install pnpm
21+
uses: pnpm/action-setup@v3
22+
with:
23+
version: 10.10.0
24+
25+
- name: Get pnpm store directory
26+
shell: bash
27+
run: |
28+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
29+
30+
- uses: actions/cache@v4
31+
name: Setup pnpm cache
32+
with:
33+
path: ${{ env.STORE_PATH }}
34+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
35+
restore-keys: |
36+
${{ runner.os }}-pnpm-store-
37+
38+
- name: Install dependencies
39+
run: pnpm install --frozen-lockfile
40+
41+
- name: Build
42+
run: pnpm build
43+
44+
- name: Run tests
45+
run: pnpm test
1746

1847
publish-gpr:
19-
needs: build
48+
needs: test
2049
runs-on: ubuntu-latest
2150
permissions:
2251
contents: read
2352
packages: write
2453
steps:
2554
- uses: actions/checkout@v4
26-
- uses: actions/setup-node@v4
55+
56+
- name: Setup Node.js
57+
uses: actions/setup-node@v4
2758
with:
28-
node-version: 20
59+
node-version: '20'
2960
registry-url: https://npm.pkg.github.com/
30-
- run: npm ci
31-
- run: npm publish
61+
62+
- name: Install pnpm
63+
uses: pnpm/action-setup@v3
64+
with:
65+
version: 10.10.0
66+
67+
- name: Get pnpm store directory
68+
shell: bash
69+
run: |
70+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
71+
72+
- uses: actions/cache@v4
73+
name: Setup pnpm cache
74+
with:
75+
path: ${{ env.STORE_PATH }}
76+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
77+
restore-keys: |
78+
${{ runner.os }}-pnpm-store-
79+
80+
- name: Install dependencies
81+
run: pnpm install --frozen-lockfile
82+
83+
- name: Build
84+
run: pnpm build
85+
86+
- name: Publish to GitHub Packages
87+
run: pnpm publish --no-git-checks
3288
env:
3389
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/npm-publish.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: '20'
17+
18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v3
20+
with:
21+
version: 10.10.0
22+
23+
- name: Get pnpm store directory
24+
shell: bash
25+
run: |
26+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
27+
28+
- uses: actions/cache@v4
29+
name: Setup pnpm cache
30+
with:
31+
path: ${{ env.STORE_PATH }}
32+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33+
restore-keys: |
34+
${{ runner.os }}-pnpm-store-
35+
36+
- name: Install dependencies
37+
run: pnpm install --frozen-lockfile
38+
39+
- name: Build
40+
run: pnpm build
41+
42+
- name: Run lint
43+
run: pnpm lint
44+
45+
- name: Run tests
46+
run: pnpm test
47+
48+
publish-npm:
49+
needs: test
50+
runs-on: ubuntu-latest
51+
permissions:
52+
contents: read
53+
id-token: write
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Setup Node.js
58+
uses: actions/setup-node@v4
59+
with:
60+
node-version: '20'
61+
registry-url: 'https://registry.npmjs.org'
62+
63+
- name: Install pnpm
64+
uses: pnpm/action-setup@v3
65+
with:
66+
version: 10.10.0
67+
68+
- name: Get pnpm store directory
69+
shell: bash
70+
run: |
71+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
72+
73+
- uses: actions/cache@v4
74+
name: Setup pnpm cache
75+
with:
76+
path: ${{ env.STORE_PATH }}
77+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
78+
restore-keys: |
79+
${{ runner.os }}-pnpm-store-
80+
81+
- name: Install dependencies
82+
run: pnpm install --frozen-lockfile
83+
84+
- name: Build
85+
run: pnpm build
86+
87+
- name: Publish to npm
88+
run: pnpm publish --access public --no-git-checks
89+
env:
90+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
91+
NPM_CONFIG_PROVENANCE: true
92+
93+
publish-github:
94+
needs: test
95+
runs-on: ubuntu-latest
96+
permissions:
97+
contents: read
98+
packages: write
99+
steps:
100+
- uses: actions/checkout@v4
101+
102+
- name: Setup Node.js
103+
uses: actions/setup-node@v4
104+
with:
105+
node-version: '20'
106+
registry-url: 'https://npm.pkg.github.com/'
107+
108+
- name: Install pnpm
109+
uses: pnpm/action-setup@v3
110+
with:
111+
version: 10.10.0
112+
113+
- name: Get pnpm store directory
114+
shell: bash
115+
run: |
116+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
117+
118+
- uses: actions/cache@v4
119+
name: Setup pnpm cache
120+
with:
121+
path: ${{ env.STORE_PATH }}
122+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
123+
restore-keys: |
124+
${{ runner.os }}-pnpm-store-
125+
126+
- name: Install dependencies
127+
run: pnpm install --frozen-lockfile
128+
129+
- name: Build
130+
run: pnpm build
131+
132+
- name: Publish to GitHub Packages
133+
run: pnpm publish --no-git-checks
134+
env:
135+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tests
1+
name: CI
22

33
on:
44
push:
@@ -9,25 +9,51 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [18, 20, 22]
1215
steps:
1316
- uses: actions/checkout@v4
1417

15-
- name: Setup Node.js
18+
- name: Setup Node.js ${{ matrix.node-version }}
1619
uses: actions/setup-node@v4
1720
with:
18-
node-version: '20'
21+
node-version: ${{ matrix.node-version }}
1922

2023
- name: Install pnpm
2124
uses: pnpm/action-setup@v3
2225
with:
2326
version: 10.10.0
2427

28+
- name: Get pnpm store directory
29+
shell: bash
30+
run: |
31+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
32+
33+
- uses: actions/cache@v4
34+
name: Setup pnpm cache
35+
with:
36+
path: ${{ env.STORE_PATH }}
37+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38+
restore-keys: |
39+
${{ runner.os }}-pnpm-store-
40+
2541
- name: Install dependencies
26-
run: pnpm install --no-frozen-lockfile
42+
run: pnpm install --frozen-lockfile
43+
44+
- name: Build
45+
run: pnpm build
2746

2847
- name: Run lint
2948
run: pnpm lint
3049

31-
- name: Run tests
32-
run: pnpm test
50+
- name: Run tests with coverage
51+
run: pnpm test:coverage
52+
53+
- name: Upload coverage reports
54+
if: matrix.node-version == 20
55+
uses: codecov/codecov-action@v4
56+
with:
57+
token: ${{ secrets.CODECOV_TOKEN }}
58+
fail_ci_if_error: false
3359

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"typescript": "^5.8.3"
6363
},
6464
"publishConfig": {
65-
"registry": "https://npm.pkg.github.com/"
65+
"access": "public"
6666
},
6767
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
6868
}

0 commit comments

Comments
 (0)