Repository navigation
412 lines (376 loc) · 18.9 KB
/
Copy pathgate.yml
File metadata and controls
412 lines (376 loc) · 18.9 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
name: Gate
# The jobs both `ci.yml` and `release.yml` run, defined once. They were only in `ci.yml` before,
# and a release asked a smaller set of questions than a push to `main` did — so v0.6.0 was tagged
# on a commit whose adapter legs were red, passed its own gate, and asked for the deploy approval.
# A release now fails wherever CI would fail, because it is the same file.
#
# `zizmor` stays in `ci.yml`. Its offline audit already runs inside `mise run check`, on every leg
# of this gate; what the separate job adds is the online audit and the upload to the security tab,
# which are facts about this repository rather than about the code being released.
on:
workflow_call:
inputs:
hardened:
description: >-
Build from nothing. A cache entry is writable by any ordinary branch run, and a release
publishes under a version number that can never be reused, so a poisoned `_build` would
ship. A release is rare and a cold build is minutes; zizmor's `cache-poisoning` audit
reports the alternative.
type: boolean
default: false
# So the hardened path can be proved before a tag spends a version number on it. A `v*` tag is
# permanent here, and v0.6.0 is what one costs when the gate is wrong.
workflow_dispatch:
inputs:
hardened:
description: Build from nothing, the way a release does.
type: boolean
default: false
permissions:
contents: read
jobs:
check:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
# One red leg must not hide the others: which of them fail is the whole answer.
fail-fast: false
matrix:
include:
# The pinned pair, which is also what a laptop gets from mise.toml.
- name: check
# The floor of the `elixir` requirement in mix.exs. The pin moves by a file written
# below; mise.toml stays the single source for a local checkout.
- name: floor (elixir 1.18)
elixir: "1.18"
erlang: "27"
# A narrower task, named in mise.toml with its reason: the full gate judges style
# against the toolchain the tree was written with, and this leg's question is
# compatibility.
gate: build-and-test
# The claim that `users_key_type: :id` is supported. Why it needs a build of its own:
# config/config.exs.
- name: integer account keys
users_key_type: id
# The claim that a consumer without Phoenix gets a core that compiles. `mix deps.get`
# fetches optional dependencies for this project's own build, so every other leg compiles
# with them present.
- name: without optional deps
without_optional: "1"
# Not the full gate, for the same reason the colocated leg is not: style is judged
# once, on this same source. And `mix docs` cannot run here at all — without the web
# half there is no `Ithibati.Web.Handler` for a guide to link to, so every reference
# to it is unresolved. The published documentation is always built with the optional
# dependencies present, so a docs build without them would be checking a product
# nobody ships.
gate: build-and-test
# The colocated delivery route, which every other leg leaves unbuilt: the variable is what
# puts LiveView's compiler in `compilers/0`, and nothing else in this matrix sets it. Its
# own step below checks that the manifest a consumer imports was actually written — the
# compile succeeding proves only that the task exists.
- name: colocated hooks
colocated_hooks: "1"
# Not the full gate: style is judged once, by the `check` leg, on this same source and
# this same toolchain. What is new here is the compiler entry and the manifest below.
gate: build-and-test
env:
ITHIBATI_USERS_KEY_TYPE: ${{ matrix.users_key_type }}
ITHIBATI_WITHOUT_OPTIONAL: ${{ matrix.without_optional }}
ITHIBATI_COLOCATED_HOOKS: ${{ matrix.colocated_hooks }}
# Through the environment rather than straight into `run:`, which is where a workflow
# expression becomes code. `matrix` is written in this file and not attacker-controlled, so
# the risk here is theoretical — the habit is not.
GATE: ${{ matrix.gate || 'check' }}
services:
postgres:
# A tag, where every action below is pinned by SHA, and the difference is deliberate: an
# action runs inside this job with its token and its workspace, while this is a database
# the tests reach over TCP. A tag that moves breaks the run visibly; an action that moves
# does not.
image: postgres:18-alpine
# No credentials in the job: config/config.exs falls back to postgres/postgres on
# localhost:5432, which is exactly what this container offers.
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# A file rather than `MISE_ELIXIR_VERSION`. The variable was set for every step of the job
# and mise-action honoured it — it installed 1.17.3-otp-27 — but the `mise run` two steps
# below ignored it, re-resolved mise.toml, and tried to start Elixir 1.20 on OTP 27, which
# crashes at boot. Why that invocation ignored it is unexplained and reproduces nowhere
# locally; a config file is honoured by both, which is the property worth depending on. It
# also leaves the tracked pin alone.
- name: Pin the toolchain this leg is for
if: matrix.elixir
env:
ELIXIR: ${{ matrix.elixir }}
ERLANG: ${{ matrix.erlang }}
run: printf '[tools]\nelixir = "%s"\nerlang = "%s"\n' "$ELIXIR" "$ERLANG" > mise.local.toml
- uses: jdx/mise-action@08ae2a091c038e1e05ec6f5115dc5c69d5a2a6b8 # v5.1.2
with:
# Pinned like everything else here.
version: 2026.9.5
cache: ${{ !inputs.hardened }}
# Keyed on the toolchain rather than on the leg: three of the four install the same one
# and should share a cache entry, and renaming a leg should not throw one away. Set
# explicitly rather than left to the action's own key, which is computed from the config
# files it knows about.
cache_key_prefix: mise-${{ matrix.elixir || 'pinned' }}-${{ matrix.erlang || 'pinned' }}
# A cold Elixir compile is otherwise the whole job. _build is only reusable under the Erlang
# and Elixir that produced it, so the key names them directly rather than trusting that a leg
# bumping its toolchain also renames itself. The leg is in there too, because a build under a
# different `users_key_type` does not merely rebuild: Elixir refuses to boot at all, since
# that setting is read with `compile_env`.
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
if: ${{ !inputs.hardened }}
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ matrix.name }}-${{ matrix.elixir || 'pinned' }}-${{ matrix.erlang || 'pinned' }}-${{ hashFiles('mise.toml') }}-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-mix-${{ matrix.name }}-${{ matrix.elixir || 'pinned' }}-${{ matrix.erlang || 'pinned' }}-${{ hashFiles('mise.toml') }}-
- name: Fetch dependencies
run: |
# Pinned, and kept equal to the archive a laptop has by hand. An unpinned
# `mix local.hex --force` fetches whatever is current from builds.hex.pm
# unverified, and this gate is what a release is judged by.
mix local.hex 2.5.1 --force
mix local.rebar --force
mix deps.get
# `mix deps.get` does not prune, so on the leg that drops the optional dependencies they
# and everything they brought stay behind in mix.lock — where `deps.unlock --check-unused`
# inside the gate finds them and fails the leg for a reason that is not the leg's point.
# This checkout is disposable; the committed lock is untouched.
# `= 1` rather than "non-empty", because `enabled?/1` in mix.exs reads named values and
# the two must agree about the same variable. The matrix above is its only writer.
if [ "$ITHIBATI_WITHOUT_OPTIONAL" = 1 ]; then mix deps.unlock --unused; fi
- name: Run the gate
run: mise run "$GATE"
- name: Run PostgreSQL capability probes
if: matrix.name == 'check'
run: mise run probe-postgres
# The gate compiling proves the compiler task exists; it does not prove a consumer can import
# anything. This is the file that import resolves to, and the name inside it is what a
# template's `phx-hook` has to say.
- name: Check the colocated manifest was written
if: matrix.colocated_hooks
run: |
manifest=_build/test/phoenix-colocated/ithibati/index.js
test -f "$manifest" || { echo "no manifest at $manifest"; exit 1; }
# The name is spelled here by hand; test/ithibati/web/hooks_test.exs is what owns it and
# derives it from the module, so a rename fails there first and loudly.
grep -q "Ithibati.Web.Hooks.PasskeyCeremony" "$manifest"
adapter:
name: adapter (${{ matrix.name }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: SQLite UUID text
adapter: sqlite
users_key_type: binary_id
uuid_storage: string
- name: SQLite UUID binary
adapter: sqlite
users_key_type: binary_id
uuid_storage: binary
- name: SQLite integer
adapter: sqlite
users_key_type: id
uuid_storage: string
- name: MySQL UUID
adapter: mysql
users_key_type: binary_id
uuid_storage: string
- name: MySQL integer
adapter: mysql
users_key_type: id
uuid_storage: string
env:
ITHIBATI_ADAPTER_PROBE: ${{ matrix.adapter }}
ITHIBATI_USERS_KEY_TYPE: ${{ matrix.users_key_type }}
ITHIBATI_SQLITE_UUID_STORAGE: ${{ matrix.uuid_storage }}
MYSQL_HOST: 127.0.0.1
MYSQL_USER: root
# Disposable service credentials, matching the container below.
MYSQL_PASSWORD: mysql
services:
mysql:
# An empty image skips the service for SQLite. Each MySQL leg gets its own server.
image: ${{ matrix.adapter == 'mysql' && 'mysql:8.4' || '' }}
env:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_ROOT_HOST: "%"
ports:
- 3306/tcp
options: >-
--health-cmd "mysql --protocol=TCP -h127.0.0.1 -uroot -pmysql -e 'SELECT 1'"
--health-interval 10s
--health-timeout 5s
--health-retries 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: jdx/mise-action@08ae2a091c038e1e05ec6f5115dc5c69d5a2a6b8 # v5.1.2
with:
version: 2026.9.5
cache: ${{ !inputs.hardened }}
cache_key_prefix: mise-pinned-pinned
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
if: ${{ !inputs.hardened }}
with:
path: |
deps
_build
key: ${{ runner.os }}-adapter-${{ matrix.adapter }}-${{ matrix.users_key_type }}-${{ matrix.uuid_storage }}-${{ hashFiles('mise.toml') }}-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-adapter-${{ matrix.adapter }}-${{ matrix.users_key_type }}-${{ matrix.uuid_storage }}-${{ hashFiles('mise.toml') }}-
- name: Fetch dependencies
run: |
mix local.hex 2.5.1 --force
mix local.rebar --force
mix deps.get
- name: Run adapter integration tests
env:
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] || '3306' }}
run: mise run build-and-test
# The examples are documentation that either compiles or does not — and their own suites drive
# them in a real browser, which is the only thing here that executes `priv/static/ithibati.js`.
# They take the library by path, so this is also the only place that compiles the library the way
# a consumer does.
example:
name: example (${{ matrix.example }})
runs-on: ubuntu-latest
strategy:
# Run every registration example even when another example fails.
fail-fast: false
matrix:
example:
- open_registration
- invitation_only
- email_registration
services:
postgres:
# A tag, where every action below is pinned by SHA, and the difference is deliberate: an
# action runs inside this job with its token and its workspace, while this is a database
# the tests reach over TCP. A tag that moves breaks the run visibly; an action that moves
# does not.
image: postgres:18-alpine
# No credentials in the job: config/config.exs falls back to postgres/postgres on
# localhost:5432, which is exactly what this container offers.
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Node for this job alone: Playwright runs on it. A file, as the toolchain pin above uses.
- name: Add node to this job's toolchain
run: printf '[tools]\nnode = "26"\n' > mise.local.toml
- uses: jdx/mise-action@08ae2a091c038e1e05ec6f5115dc5c69d5a2a6b8 # v5.1.2
with:
version: 2026.9.5
cache: ${{ !inputs.hardened }}
cache_key_prefix: mise-example
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
if: ${{ !inputs.hardened }}
with:
path: |
examples/${{ matrix.example }}/deps
examples/${{ matrix.example }}/_build
key: ${{ runner.os }}-example-${{ matrix.example }}-${{ hashFiles(format('examples/{0}/mix.lock', matrix.example)) }}
restore-keys: ${{ runner.os }}-example-${{ matrix.example }}-
# The lockfile pins playwright, and each playwright version pins its browser build.
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
if: ${{ !inputs.hardened }}
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles(format('examples/{0}/assets/package-lock.json', matrix.example)) }}
# The browser tests run in Playwright's Chrome for Testing. `--with-deps` adds the system
# libraries it needs, which the runner image does not promise.
- name: Install Playwright and its browser
working-directory: examples/${{ matrix.example }}/assets
run: |
npm ci --no-audit --no-fund
npx playwright install --with-deps chromium --only-shell
# `mix precommit` rather than a second copy of it, the way mise.toml puts it for this
# repository: following the example's own alias locally then means following the gate. It
# runs compile, format, the assets and the tests — including the browser tests under
# `test/features/`, which are the only thing anywhere that executes the library's JavaScript.
- name: Run the example's gate
working-directory: examples/${{ matrix.example }}
run: |
mix local.hex 2.5.1 --force
mix local.rebar --force
mix deps.get
# In the environment the gate runs in, not the default `dev`: `assets.setup` goes through
# `app.config`, which compiles, so leaving it in `dev` builds the example, the library and
# every dependency once in each environment. The binaries land in `_build/` either way.
MIX_ENV='test' mix assets.setup
if ! mix precommit; then
# Reruns the failed features with a screenshot of each, for the artifact below.
PW_SCREENSHOT=true mix test --failed || true
exit 1
fi
# A failed feature test names a selector and nothing about the page it failed against.
- name: Keep the screenshots when a browser test fails
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: screenshots-${{ matrix.example }}
path: examples/${{ matrix.example }}/screenshots/
if-no-files-found: ignore
retention-days: 7
# What the root matrix cannot see: `lib/` compiled *as a dependency*, where `Mix.env()` is
# `prod` — Mix puts `env: :prod` on every dependency that does not ask for another, whatever
# the parent's `MIX_ENV` is — so `elixirc_paths` is `["lib"]` alone. Counted rather than
# assumed: the build holds 24 modules for the 24 files under `lib/` and nothing from `credo/`.
# That is why this can use the build the gate above already filled.
#
# It has to use that one. Pointed at an empty `_build/dev` the compile answers with a screen
# of `cannot infer signatures from :bandit because it is not loaded` — the sibling
# dependencies are simply absent there — and the check then reports the library for the state
# of its own build.
#
# The switch cannot do this: measured, a consumer's `mix compile` does not apply
# `--warnings-as-errors` to its dependencies, and `mix deps.compile` does not accept it at
# all. So the output is read — and printed before it is judged, because a compile that *fails*
# says why in the same stream, and swallowing that leaves a red job with an empty log.
#
# Once, not per example: all take the same library at the same path with the same optional
# dependencies present.
- name: Check the library compiled into the example without warnings
if: matrix.example == 'open_registration'
working-directory: examples/${{ matrix.example }}
run: |
rm -rf _build/test/lib/ithibati
set +e
out=$(MIX_ENV='test' mix deps.compile ithibati --force 2>&1)
rc=$?
set -e
echo "$out"
if [ $rc -ne 0 ]; then
echo "the library did not compile as a dependency at all"
exit 1
fi
if sed -n '/^==> ithibati$/,$p' <<<"$out" | grep -q "warning:"; then
echo "the library emitted warnings into a consumer's build"
exit 1
fi