-
Notifications
You must be signed in to change notification settings - Fork 3
378 lines (355 loc) · 14.4 KB
/
ci.yml
File metadata and controls
378 lines (355 loc) · 14.4 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: CI
on:
pull_request:
push:
branches: [main]
paths-ignore:
- 'docs/**'
- 'README.md'
release:
types: ['published']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
CYPRESS_CACHE_FOLDER: ~/.cache/Cypress
BUN_CACHE: ~/.bun/install/cache
jobs:
# ─── Quality ────────────────────────────────────────────────
install:
name: Install Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with: { bun-version: 1.3.14 } # renovate: datasource=docker depName=oven/bun
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
id: cache-deps
with:
path: |
${{ env.BUN_CACHE }}
**/node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package.json') }}
- if: steps.cache-deps.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
lint:
name: Lint & Format
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
${{ env.BUN_CACHE }}
**/node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package.json') }}
- run: bun run lint && bun run format
typecheck:
name: Type Check
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with: { bun-version: 1.3.14 } # renovate: datasource=docker depName=oven/bun
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
${{ env.BUN_CACHE }}
**/node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package.json') }}
- run: bun typecheck
build:
name: Build
needs: [lint, typecheck]
runs-on: ubuntu-latest
if: ${{ !failure() && !cancelled() }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with: { bun-version: 1.3.14 } # renovate: datasource=docker depName=oven/bun
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
${{ env.BUN_CACHE }}
**/node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package.json') }}
- run: bun run build
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: build
key: build-${{ github.sha }}
# ─── Tests ──────────────────────────────────────────────────
unit-tests:
name: Unit Tests
needs: build
runs-on: ubuntu-latest
if: ${{ !failure() && !cancelled() }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with: { bun-version: 1.3.14 } # renovate: datasource=docker depName=oven/bun
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
${{ env.BUN_CACHE }}
**/node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package.json') }}
- run: bunx cypress install && bunx cypress verify
- run: bun run test:unit:prod
env:
NODE_ENV: test
CYPRESS: 'true'
e2e-smoke:
name: E2E Smoke
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
if: ${{ !failure() && !cancelled() }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with: { bun-version: 1.3.14 } # renovate: datasource=docker depName=oven/bun
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
${{ env.BUN_CACHE }}
**/node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package.json') }}
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: build
key: build-${{ github.sha }}
- name: Setup Environment
env:
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
SUB: ${{ secrets.SUB }}
API_URL: ${{ secrets.API_URL }}
GRAPHQL_URL: ${{ secrets.GRAPHQL_URL }}
AUTH_OIDC_ISSUER: ${{ secrets.AUTH_OIDC_ISSUER }}
AUTH_OIDC_CLIENT_ID: ${{ secrets.AUTH_OIDC_CLIENT_ID }}
run: |
cat > .env << EOF
NODE_ENV=test
CYPRESS=true
APP_URL=http://localhost:3000
API_URL=$API_URL
GRAPHQL_URL=$GRAPHQL_URL
AUTH_OIDC_ISSUER=$AUTH_OIDC_ISSUER
AUTH_OIDC_CLIENT_ID=$AUTH_OIDC_CLIENT_ID
SESSION_SECRET=$SESSION_SECRET
LOG_LEVEL=warn
CYPRESS_BASE_URL=http://localhost:3000
EOF
- run: bunx cypress install && bunx cypress verify
- name: Run Smoke Tests
env:
NODE_ENV: test
CYPRESS: 'true'
CYPRESS_BASE_URL: http://localhost:3000
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
SUB: ${{ secrets.SUB }}
run: >-
bunx start-server-and-test
'bun run start' http://localhost:3000/_healthz
'bunx cypress run --spec "cypress/e2e/smoke/**" --config-file cypress.config.ts'
- if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: e2e-smoke-artifacts-${{ github.run_id }}
path: |
cypress/videos
cypress/screenshots
retention-days: 7
if-no-files-found: warn
e2e-regression:
name: E2E Regression
needs: e2e-smoke
runs-on: ubuntu-latest
timeout-minutes: 20
if: ${{ !failure() && !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# if: ${{ !failure() && !cancelled() }}
strategy:
fail-fast: false
matrix:
shard: [0, 1, 2, 3]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with: { bun-version: 1.3.14 } # renovate: datasource=docker depName=oven/bun
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: |
${{ env.BUN_CACHE }}
**/node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock', '**/bun.lockb', '**/package.json') }}
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5
with:
path: build
key: build-${{ github.sha }}
- name: Setup Environment
env:
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
SUB: ${{ secrets.SUB }}
API_URL: ${{ secrets.API_URL }}
GRAPHQL_URL: ${{ secrets.GRAPHQL_URL }}
AUTH_OIDC_ISSUER: ${{ secrets.AUTH_OIDC_ISSUER }}
AUTH_OIDC_CLIENT_ID: ${{ secrets.AUTH_OIDC_CLIENT_ID }}
run: |
cat > .env << EOF
NODE_ENV=test
CYPRESS=true
APP_URL=http://localhost:3000
API_URL=$API_URL
GRAPHQL_URL=$GRAPHQL_URL
AUTH_OIDC_ISSUER=$AUTH_OIDC_ISSUER
AUTH_OIDC_CLIENT_ID=$AUTH_OIDC_CLIENT_ID
SESSION_SECRET=$SESSION_SECRET
LOG_LEVEL=warn
CYPRESS_BASE_URL=http://localhost:3000
EOF
- run: bunx cypress install && bunx cypress verify
- name: Run Regression Tests
env:
NODE_ENV: test
CYPRESS: 'true'
CYPRESS_BASE_URL: http://localhost:3000
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
SUB: ${{ secrets.SUB }}
SPLIT: ${{ strategy.job-total }}
SPLIT_INDEX: ${{ strategy.job-index }}
CYPRESS_specPattern: 'cypress/e2e/regression/**/*.{cy,spec}.{js,jsx,ts,tsx}'
run: >-
bunx start-server-and-test
'bun run start' http://localhost:3000/_healthz
'bunx cypress run --config-file cypress.config.ts'
- if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: e2e-regression-artifacts-${{ github.run_id }}-shard-${{ matrix.shard }}
path: |
cypress/videos
cypress/screenshots
retention-days: 7
if-no-files-found: warn
# ─── Status Gate ────────────────────────────────────────────
status-check:
name: Final Status Check
needs: [install, lint, typecheck, build, unit-tests, e2e-smoke, e2e-regression]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check Workflow Status
run: |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
echo "❌ One or more jobs failed"
exit 1
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
echo "⚠️ One or more jobs were cancelled"
exit 1
else
echo "✅ All jobs passed"
fi
# ─── Publish (only after all checks pass) ──────────────────
publish-container-image:
name: Publish Container Image
needs: [status-check]
if: ${{ !failure() && !cancelled() }}
permissions:
id-token: write
contents: read
packages: write
attestations: write
uses: datum-cloud/actions/.github/workflows/publish-docker.yaml@545f34cd6f35e9688c9a04a7e890281bcdbaefd2 # v1.14.0
with:
image-name: cloud-portal
# NOTE: `secrets: inherit` is required because the upstream workflow
# references `secrets.SENTRY_AUTH_TOKEN` without declaring it under
# `workflow_call.secrets`. Once upstream declares it, switch to an
# explicit `secrets:` block passing only SENTRY_AUTH_TOKEN.
secrets: inherit
publish-kustomize-bundles:
name: Publish Kustomize Bundles
needs: [publish-container-image]
if: ${{ !failure() && !cancelled() }}
permissions:
id-token: write
contents: read
packages: write
uses: datum-cloud/actions/.github/workflows/publish-kustomize-bundle.yaml@545f34cd6f35e9688c9a04a7e890281bcdbaefd2 # v1.14.0
with:
bundle-name: ghcr.io/datum-cloud/cloud-portal-kustomize
bundle-path: config
image-overlays: config/base
image-name: ghcr.io/datum-cloud/cloud-portal
# No explicit secrets block: upstream only uses GITHUB_TOKEN, which is
# automatically available to reusable workflows.
# ─── PR Comment ─────────────────────────────────────────────
pr-comment:
name: PR Test Summary
needs: [unit-tests, e2e-smoke]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
actions: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Build test summary
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const fs = require('fs');
const runId = context.runId;
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId,
});
const testJobs = jobs.jobs.filter(j =>
j.name === 'Unit Tests' || j.name.startsWith('E2E')
);
const statusEmoji = (conclusion) => {
if (!conclusion || conclusion === 'skipped') return '⏭️';
if (conclusion === 'success') return '✅';
if (conclusion === 'failure') return '❌';
if (conclusion === 'cancelled') return '🚫';
return '❓';
};
let table = '| Job | Status |\n|-----|--------|\n';
for (const job of testJobs.sort((a, b) => a.name.localeCompare(b.name))) {
table += `| ${job.name} | ${statusEmoji(job.conclusion)} ${job.conclusion || 'pending'} |\n`;
}
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId,
});
let body = `## 🧪 Test Summary\n\n${table}\n\n`;
body += `[View workflow run](${runUrl})`;
body += `\n\n### 📎 Artifacts\n\n`;
if (artifacts.artifacts.length > 0) {
body += `Videos and screenshots from failed E2E tests:\n\n`;
for (const a of artifacts.artifacts) {
body += `- **${a.name}** – [Download](${runUrl})\n`;
}
} else {
body += `No artifacts (all tests passed).\n`;
}
fs.writeFileSync('pr-summary.md', body);
- uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: pr-summary.md
comment-tag: ci-summary
edit-mode: replace