-
Notifications
You must be signed in to change notification settings - Fork 75
325 lines (312 loc) · 11.7 KB
/
Copy pathchecks.yaml
File metadata and controls
325 lines (312 loc) · 11.7 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# PR Checks Workflow
#
# Runs build, test, lint, and type-check in parallel for faster feedback.
# Build runs first (required by all others), then test/lint/types fan out.
#
# Path filtering:
# - code or tooling config -> full checks (build + test + lint + types)
# - other non-code changes -> build + lint only
# - manual dispatch -> full checks
#
# Addresses: https://github.com/equinor/design-system/issues/4624
name: Checks
permissions:
contents: read
on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
NODE_VERSION: '24.16.0'
CACHE_KEY: ${{ github.sha }}-checks
jobs:
# ─── Setup: checkout + install + cache ───────────────────────────
setup:
uses: ./.github/workflows/_setup.yml
secrets: inherit
with:
cacheKey: ${{ github.sha }}-checks
# ─── Detect what changed to skip unnecessary jobs ───────────────
changes:
runs-on: ubuntu-latest
# dorny/paths-filter fetches the PR's changed-file list via the REST API on
# pull_request events, which needs pull-requests: read on top of the
# workflow's contents: read.
permissions:
contents: read
pull-requests: read
outputs:
# Manual runs are an explicit request for the complete suite.
code: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.code == 'true' }}
steps:
# fetch-depth: 2 so dorny/paths-filter can diff against the previous
# commit on push events (the default depth of 1 omits it).
- uses: actions/checkout@v7
with:
fetch-depth: 2
# SHA-pinned (v3.0.2) — third-party action running on every PR; pin to an
# immutable commit so a compromised tag can't inject code into CI.
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
if: github.event_name != 'workflow_dispatch'
id: filter
with:
filters: |
code:
- 'packages/**'
- 'apps/**'
- 'scripts/**'
- '.github/actions/**'
# Root dependencies and tooling config warrant full checks.
- '.npmrc'
- '.node-version'
- '.nvmrc'
- '.prettier*'
- '.stylelintrc*'
- 'package.json'
- 'pnpm-lock.yaml'
- 'pnpm-workspace.yaml'
- 'tsconfig*.json'
- 'babel.config.cjs'
- 'eslint.config.mjs'
# ─── Build (required before test/lint/types) ─────────────────────
build:
name: Build
runs-on: ubuntu-latest
needs: [setup, changes]
if: needs.changes.outputs.code == 'true'
steps:
- name: Restore workspace cache
id: cache
uses: actions/cache/restore@v6
with:
path: |
./*
~/.pnpm-store
key: ${{ env.CACHE_KEY }}
# Cache misses are rare (setup runs first and saves the workspace) but
# not impossible — a cache-service hiccup, eviction, or size limit
# shouldn't fail the run when a plain checkout + install can proceed.
- name: Fallback checkout (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v7
- name: Install Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Fallback install (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile
# Must run BEFORE the build: `prebuild` regenerates the index in the
# workspace, which would mask a stale committed file.
- name: Check AI component index freshness
run: pnpm run generate:component-index --check
- name: Build packages
run: pnpm run build
- name: Cache build output
uses: actions/cache/save@v6
with:
path: |
./*
~/.pnpm-store
key: ${{ env.CACHE_KEY }}-built
# ─── Test (parallel, depends on build) ───────────────────────────
test:
name: Test
runs-on: ubuntu-latest
needs: [build, changes]
if: needs.changes.outputs.code == 'true'
steps:
- name: Restore build cache
id: cache
uses: actions/cache/restore@v6
with:
path: |
./*
~/.pnpm-store
key: ${{ env.CACHE_KEY }}-built
# On a build-cache miss, reconstruct from scratch (checkout + install +
# build) rather than failing — the build job's output cache is not
# guaranteed to survive a cache-service hiccup or eviction.
- name: Fallback checkout (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v7
- name: Install Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Fallback build (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
run: |
pnpm install --frozen-lockfile
pnpm run build
- name: Test packages
run: pnpm run test
# ─── Lint (parallel, depends on build) ───────────────────────────
lint:
name: Lint
runs-on: ubuntu-latest
needs: [build, changes]
if: needs.changes.outputs.code == 'true'
steps:
- name: Restore build cache
id: cache
uses: actions/cache/restore@v6
with:
path: |
./*
~/.pnpm-store
key: ${{ env.CACHE_KEY }}-built
# On a build-cache miss, reconstruct from scratch (checkout + install +
# build) rather than failing — the build job's output cache is not
# guaranteed to survive a cache-service hiccup or eviction.
- name: Fallback checkout (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v7
- name: Install Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Fallback build (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
run: |
pnpm install --frozen-lockfile
pnpm run build
- name: Lint packages
run: pnpm run lint:all
# ─── Type check (parallel, depends on build) ────────────────────
types:
name: Type check
runs-on: ubuntu-latest
needs: [build, changes]
if: needs.changes.outputs.code == 'true'
steps:
- name: Restore build cache
id: cache
uses: actions/cache/restore@v6
with:
path: |
./*
~/.pnpm-store
key: ${{ env.CACHE_KEY }}-built
# On a build-cache miss, reconstruct from scratch (checkout + install +
# build) rather than failing — the build job's output cache is not
# guaranteed to survive a cache-service hiccup or eviction.
- name: Fallback checkout (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v7
- name: Install Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Fallback build (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
run: |
pnpm install --frozen-lockfile
pnpm run build
- name: Type check packages
run: pnpm run types
# ─── Lint-only for non-code changes (workflows, docs) ───────────
#
# Trade-off (decided 2026-06): this job runs a full `pnpm run build`
# before linting because `lint:all` is type-aware and needs every
# workspace package's built `.d.ts` to resolve cross-package imports.
# So a docs/workflow-only PR still pays for a full build here.
#
# We deliberately did NOT add granular per-package affected detection
# (e.g. pnpm `--filter "...[origin/main]"` or Turborepo) because CI is
# currently fast enough and the existing binary `changes.code` gate +
# cross-job `-built` cache already cover the common cases. Revisit only
# if build time becomes a real bottleneck — Turborepo (input-hash
# caching + affected filtering) is the preferred next step if so.
lint-only:
name: Lint (non-code changes)
runs-on: ubuntu-latest
needs: [setup, changes]
if: needs.changes.outputs.code != 'true'
steps:
- name: Restore workspace cache
id: cache
uses: actions/cache/restore@v6
with:
path: |
./*
~/.pnpm-store
key: ${{ env.CACHE_KEY }}
# Cache misses are rare (setup runs first and saves the workspace) but
# not impossible — a cache-service hiccup, eviction, or size limit
# shouldn't fail the run when a plain checkout + install can proceed.
- name: Fallback checkout (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/checkout@v7
- name: Install Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Fallback install (cache miss)
if: steps.cache.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile
# lint:all runs type-aware ESLint across the whole monorepo, which
# needs each workspace package's built type declarations. Without a
# build, cross-package imports resolve to `any`/error and trip
# no-unsafe-* / no-redundant-type-constituents. Build first.
- name: Build packages
run: pnpm run build
- name: Lint packages
run: pnpm run lint:all
# ─── Status check (single gate for branch protection) ───────────
checks-passed:
name: All checks passed
runs-on: ubuntu-latest
if: always()
needs: [setup, changes, build, test, lint, types, lint-only]
steps:
- name: Evaluate results
run: |
# Each needs.<job>.result must be expanded as a static expression:
# template expressions are evaluated at render time, before bash runs,
# so a bash loop variable cannot index the needs context.
# A "skipped" result is expected (path filtering) and is not a failure.
for result in \
"setup:${{ needs.setup.result }}" \
"changes:${{ needs.changes.result }}" \
"build:${{ needs.build.result }}" \
"test:${{ needs.test.result }}" \
"lint:${{ needs.lint.result }}" \
"types:${{ needs.types.result }}" \
"lint-only:${{ needs.lint-only.result }}"; do
job="${result%%:*}"
status="${result#*:}"
if [ "$status" = "failure" ] || [ "$status" = "cancelled" ]; then
echo "::error::Job '$job' $status"
exit 1
fi
done
echo "All checks passed ✅"
- name: log-errors-to-slack
if: failure()
uses: act10ns/slack@v2
with:
status: ${{ job.status }}