Skip to main content

max / alloy

4.1 KB · 97 lines History Blame Raw
1 #!/usr/bin/env bash
2 #
3 # preflight-gate.sh — run build/preflight.sh ahead of a mint, and decide what a
4 # finding means. Sourced by build/build-image.sh and build/build-iso.sh, so the
5 # policy exists once rather than in two places that drift.
6 #
7 # WHY THIS IS A GATE AND WAS NOT ONE ON DAY ONE. A gate that fires wrongly on
8 # its first day is worse than no gate, and the preflight had never been run in
9 # anger. It has since caught four things nobody predicted, one of them a recipe
10 # combination the Containerfile's own validator refuses, so the condition is met.
11 #
12 # WHAT REFUSES A BUILD, and this is the decision the gate exists to hold.
13 # preflight answers two different kinds of question, and only one of them is
14 # about the thing being built:
15 #
16 # dials, requires, var-payload about the medium. An image with one of these
17 # outstanding is wrong wherever it is built.
18 # These refuse.
19 # guards about this machine. It reads sibling repos
20 # under ~/Code that no image contains, so it
21 # predicts a failed AppImage on this host and
22 # says nothing about the medium. This warns.
23 #
24 # Refusing a mint because a repo next door is stale would make the gate a thing
25 # people route around, and routing around it is how the four findings above
26 # would have been missed. So the warning is loud and the build proceeds; the
27 # finding is still on the screen and still worth fixing before a release.
28 #
29 # HOW MUCH PREFLIGHT RUNS, which is the other half of the decision. The probe is
30 # one dnf transaction: seconds on the host's own architecture, minutes under
31 # emulation. Measured 2026-09-04, the astra probe took minutes on fw13 and
32 # seconds on astra. A gate that always builds it makes every cross-architecture
33 # mint slow to start, for an answer emulation is the worst way to get. So the
34 # gate runs the full preflight when the mint's architecture is this machine's,
35 # and --fast when it is not, saying which it chose and why.
36 #
37 # Usage: preflight_gate HOST ARCH SKIP
38 # HOST the recipe name, empty for a mint with no recipe
39 # ARCH the medium's architecture, empty for this machine's
40 # SKIP 1 to skip the gate entirely (--no-preflight)
41 #
42 # Returns 0 to proceed. On a finding about the image it does not return: it
43 # exits the calling script, because a caller that had to remember to check would
44 # eventually forget.
45
46 preflight_gate() {
47 local host="$1" arch="${2:-}" skip="${3:-0}"
48 local rc=0 mode=()
49
50 if [ "$skip" = "1" ]; then
51 printf '==> preflight: skipped (--no-preflight)\n'
52 return 0
53 fi
54
55 # No recipe, nothing to check. preflight reads build/hosts/<name>.env and has
56 # nothing to say about a mint that takes the Containerfile's own defaults.
57 # Stated rather than silent, so a hostless mint does not read as a gated one.
58 if [ -z "$host" ]; then
59 printf '==> preflight: skipped (no --host, so there is no recipe to check)\n'
60 return 0
61 fi
62
63 if [ -n "$arch" ] && [ "$arch" != "$(uname -m)" ]; then
64 mode=(--fast)
65 printf '==> preflight %s --fast (minting %s on %s; the probe would be emulated)\n' \
66 "$host" "$arch" "$(uname -m)"
67 else
68 printf '==> preflight %s\n' "$host"
69 fi
70
71 "$REPO_ROOT/build/preflight.sh" "$host" "${mode[@]}" || rc=$?
72
73 case "$rc" in
74 0) return 0 ;;
75 4)
76 printf '\n'
77 printf '==> preflight: this HOST has findings; the medium is clean, so the build goes on.\n'
78 printf ' Fix them before you cut a release from this machine.\n\n'
79 return 0
80 ;;
81 2)
82 # Usage, not a finding: --host named a recipe preflight could not read.
83 # Saying "findings" here would send someone looking for a defect in an
84 # image that was never described.
85 printf '\n'
86 printf 'error: preflight could not read a recipe for %s. Not building.\n' "$host" >&2
87 exit 2
88 ;;
89 *)
90 printf '\n'
91 printf 'error: preflight found something the mint would carry. Not building.\n' >&2
92 printf ' Pass --no-preflight to mint anyway, for a deliberately incomplete image.\n' >&2
93 exit "$rc"
94 ;;
95 esac
96 }
97