Repository navigation
264 lines (233 loc) · 9.44 KB
/
Copy pathci.yml
File metadata and controls
264 lines (233 loc) · 9.44 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
# Checks every pull request and push to dev and main: the pull request title,
# the lint, the build and the Docker image. The gate `passed` ("CI passed") is
# the only check that the rules for dev need to require. Pushes to main stay
# covered because the Deploy workflow publishes after CI for them. Runs also when a pull
# request is edited, so that the title check follows the title; all jobs run
# then, as a run that skipped the build would report "CI passed" for the
# commit. CI also runs the tests (with coverage, reported to Codecov), audits
# the production dependencies and scans the image for known vulnerabilities.
name: CI
on:
pull_request:
types: [opened, synchronize, reopened, edited]
push:
branches: [dev, main]
permissions:
contents: read
# Only a new head commit of a pull request cancels its runs in progress
# (action `synchronize`, first attempt); runs for other actions and reruns
# wait, so that a run on the same commit never leaves a cancelled, failed
# `CI passed` (see "Cancelled runs" in `actions/gate/README.md` of
# `elixir-cloud-aai/.github`). Runs for pushes get their own group, per
# branch and commit (a commit can be pushed to `dev` and `main`), so that
# none is dropped. Runs for edits that leave the title unchanged (e.g. of
# the description, also by bots) share a group of their own, so that they
# don't wait for the run for the pull request's commit
concurrency:
group: >-
ci-${{
github.event_name == 'push' && format('{0}-{1}', github.ref, github.sha) ||
github.event.action == 'edited' && !github.event.changes.title &&
format('{0}-edited', github.ref) ||
github.ref }}
cancel-in-progress: >-
${{ github.event_name == 'pull_request'
&& github.event.action == 'synchronize'
&& github.run_attempt == 1 }}
jobs:
# Pull request titles become the commit messages on `dev` (squash merges):
# Conventional Commits, at most 50 characters (shared action of
# elixir-cloud-aai/.github, pinned to the commit of a release). Skipped on
# pushes and for Dependabot, whose titles can't be configured to pass,
# unless someone else edits the title
title:
name: PR title
if: >-
github.event_name == 'pull_request' && (
github.event.pull_request.user.login != 'dependabot[bot]' ||
github.event.changes.title &&
github.event.sender.login != 'dependabot[bot]')
runs-on: ubuntu-latest
timeout-minutes: 5
permissions: {}
steps:
- name: Check PR title
uses: elixir-cloud-aai/.github/actions/pr-title@31f22fccc1f3c597ed7c1d1f75b2f85522155348 # v1.1.0
# Lints all JavaScript and TypeScript sources with ESLint (Next.js's
# recommended flat config with typescript-eslint, plus the project's rules
# in `eslint.config.js`); fails on errors and warnings
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Lint
run: npm run lint
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
# Writes `coverage/lcov.info` (`vitest.config.mts`)
- name: Run tests with coverage
run: npm run test:coverage
# Upload errors fail the workflow only on pushes to this repository,
# because pull requests from forks and Dependabot, and forks themselves,
# get no access to the Codecov token
- name: Submit report to Codecov
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
disable_search: true
fail_ci_if_error: ${{ github.event_name == 'push' && github.repository_owner == 'elixir-cloud-aai' }}
verbose: true
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Check formatting
run: npx prettier --check "src/**/*.{ts,tsx,json,css}"
- name: Type-check
run: npx tsc --noEmit
- name: Build
run: npm run build
# Fails on high and critical advisories in the production dependencies of
# `package-lock.json`, which Next.js bundles where image scanners can't see
# them. Development tools don't reach the site, so they aren't audited. Needs
# no installed packages
audit:
name: Audit
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26
- name: Audit production dependencies
run: npm audit --omit=dev --audit-level=high
image:
name: Build image
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
# Builds the production image without pushing, so a broken Dockerfile is
# caught before it is merged, and hands it to `scan` as a file, so that
# exactly this image is scanned. The file holds the image alone, as it
# isn't published: no attestations
- name: Build image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
push: false
tags: landing-page:ci
outputs: type=docker,dest=${{ runner.temp }}/image.tar
provenance: false
sbom: false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Upload the image
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: image
path: ${{ runner.temp }}/image.tar
retention-days: 7
if-no-files-found: error
# Scans the image of `image` with Trivy (shared action of
# elixir-cloud-aai/.github, pinned to the commit of a release), in a job of
# its own without credentials, so that a vulnerability with a fix shows up
# before a release, not in it. The findings that have a fix are uploaded to
# code scanning (not for pull requests from forks, whose token can't write
# them), and the job fails on critical and high vulnerabilities that have a
# fix. Accepted findings are listed, with a reason and an expiry date, in
# `.trivyignore.yaml`
scan:
name: Scan build
needs: image
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
security-events: write # upload SARIF to code scanning
steps:
# For `.trivyignore.yaml`
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Download the image
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: image
path: ${{ runner.temp }}
- name: Load the image
run: docker load -i "${RUNNER_TEMP}/image.tar"
- name: Scan image
uses: elixir-cloud-aai/.github/actions/scan-image@31f22fccc1f3c597ed7c1d1f75b2f85522155348 # v1.1.0
with:
image: landing-page:ci
category: image
upload: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
# The only required check: passes if every other job passed, fails on any
# other result (failure, cancelled, skipped), except that `title` may be
# skipped (pushes, Dependabot). Add every new job to `needs`. Uses the
# shared gate action of elixir-cloud-aai/.github, pinned to the commit of
# a release
passed:
name: CI passed
runs-on: ubuntu-latest
timeout-minutes: 5
if: always()
needs: [title, lint, test, build, audit, image, scan]
permissions: {}
steps:
- name: Check results of all jobs
uses: elixir-cloud-aai/.github/actions/gate@31f22fccc1f3c597ed7c1d1f75b2f85522155348 # v1.1.0
with:
needs: ${{ toJSON(needs) }}
allow-skipped: title