-
Notifications
You must be signed in to change notification settings - Fork 2
273 lines (244 loc) · 10 KB
/
Copy pathci-pnpm-node.yml
File metadata and controls
273 lines (244 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
name: Common CI for Node (pnpm)
on:
workflow_call:
inputs:
node-version:
description: Node version to use
required: true
type: string
extra-commands:
description: Extra setup commands to run before lint/test/build
required: false
type: string
app-directory:
description: Application subdirectory for lint/test/build
required: false
type: string
default: "."
typecheck:
description: Run type checking
required: false
type: boolean
default: false
upload-artifacts:
description: Upload build artifacts
required: false
type: boolean
default: false
skip-sonar:
description: Skip SonarQube
required: false
type: boolean
default: false
skip-build:
description: Skip build phase
required: false
type: boolean
default: false
working-directory:
description: Working directory for install/build/test jobs
required: false
type: string
default: "."
ignore-scripts:
description: Pass --ignore-scripts to pnpm install
required: false
type: boolean
default: true
pnpm-version:
description: >
pnpm version to use (passed to pnpm/action-setup).
If empty, pnpm/action-setup reads the version from the
packageManager field in package.json.
required: false
type: string
default: ""
commitlint-config-file:
description: 'Path to commitlint config file'
required: false
type: string
default: './commitlint.config.mjs'
secrets:
SONAR_TOKEN:
description: 'SonarQube Cloud token'
required: false
workflow_dispatch:
permissions:
contents: read
pull-requests: read
jobs:
commitlint:
name: Check commit messages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Run commitlint
uses: wagoid/commitlint-github-action@b948419dd99f3fd78a6548d48f94e3df7f6bf3ed # v6.2.1
with:
configFile: ${{ inputs.commitlint-config-file }}
build:
name: Lint and build
if: ${{ !inputs.skip-build }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup pnpm
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
with:
version: ${{ inputs.pnpm-version }}
- name: Setup Node.js with dependency path
if: ${{ inputs.working-directory != '.' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ inputs.node-version }}
cache: pnpm
cache-dependency-path: ${{ inputs.working-directory }}/pnpm-lock.yaml
- name: Setup Node.js without dependency path
if: ${{ inputs.working-directory == '.' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ inputs.node-version }}
cache: pnpm
- name: Install dependencies
run: |
IGNORE_SCRIPTS="${{ inputs.ignore-scripts == true && '--ignore-scripts' || '' }}"
pnpm install --frozen-lockfile $IGNORE_SCRIPTS
- name: Run extra commands
if: ${{ inputs.extra-commands != '' }}
run: ${{ inputs.extra-commands }}
- name: Typecheck application
if: ${{ inputs.typecheck }}
working-directory: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
run: pnpm typecheck
- name: Lint application
working-directory: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
run: pnpm lint
- name: Build application
working-directory: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
run: pnpm build
- name: Upload build
if: ${{ inputs.upload-artifacts }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: build-artifacts-${{ inputs.node-version }}
path: |
${{ inputs.app-directory }}/dist
${{ inputs.app-directory }}/build
${{ inputs.app-directory }}/lib
retention-days: 1
- name: Check browser bundle size limits
if: ${{ hashFiles(format('{0}/.size-limit.js', inputs.app-directory)) != '' }}
working-directory: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
run: pnpm check-size
- name: Check ecmascript checks for build files
if: ${{ hashFiles(format('{0}/.escheckrc', inputs.app-directory)) != '' }}
working-directory: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
run: pnpm check-dist
tests:
name: Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup pnpm
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
with:
version: ${{ inputs.pnpm-version }}
- name: Setup Node.js with dependency path
if: ${{ inputs.working-directory != '.' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ inputs.node-version }}
cache: pnpm
cache-dependency-path: ${{ inputs.working-directory }}/pnpm-lock.yaml
- name: Setup Node.js without dependency path
if: ${{ inputs.working-directory == '.' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ inputs.node-version }}
cache: pnpm
- name: Install dependencies
run: |
IGNORE_SCRIPTS="${{ inputs.ignore-scripts == true && '--ignore-scripts' || '' }}"
pnpm install --frozen-lockfile $IGNORE_SCRIPTS
- name: Run extra commands
if: ${{ inputs.extra-commands != '' }}
run: ${{ inputs.extra-commands }}
- name: Run tests
working-directory: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
run: pnpm test:coverage
env:
CI: true
# Coverage path logic (keep in sync with sonarcloud job's cache/restore step):
# Resolves the effective directory (app-directory if set, else working-directory),
# then prefixes 'coverage' with '<dir>/' when running in a subdirectory.
- name: Store coverage report
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ (inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory) && format('{0}/', inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory) || ''}}coverage
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
sonarcloud:
name: Run SonarQube Cloud Scan
if: ${{ !inputs.skip-sonar }}
runs-on: ubuntu-latest
needs: tests
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
persist-credentials: false
# Coverage path logic (keep in sync with tests job's cache/save step):
# Resolves the effective directory (app-directory if set, else working-directory),
# then prefixes 'coverage' with '<dir>/' when running in a subdirectory.
- name: Restore coverage report
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ (inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory) && format('{0}/', inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory) || ''}}coverage
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
fail-on-cache-miss: true
# Without this workaround, SonarQube Cloud reports a warning about an incorrect source path.
- name: Override coverage report source path for SonarQube Cloud
working-directory: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
run: |
find coverage -type f \( -name '*.info' -o -name 'lcov.info' \) 2>/dev/null | xargs -r sed -i 's@SF:'$GITHUB_WORKSPACE'@SF:/github/workspace/@g' || true
find coverage -type f -name '*.json' 2>/dev/null | xargs -r sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' || true
- name: SonarQube Cloud Scan
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0
with:
projectBaseDir: ${{ inputs.app-directory == '.' && inputs.working-directory || inputs.app-directory }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
dependency-review:
name: Dependency Review
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
with:
fail-on-severity: moderate
fail-on-scopes: runtime, development, unknown
license-check: false
vulnerability-check: true
comment-summary-in-pr: on-failure
show-patched-versions: true