This repository has no description
9.8 kB
255 lines
1name: CI
2
3on:
4 push:
5 branches: [master]
6 pull_request:
7 workflow_dispatch:
8
9# A newer run for the same ref replaces a running one.
10concurrency:
11 group: ci-${{ github.ref }}
12 cancel-in-progress: true
13
14# One job per check shows failing checks in the run overview, the same for
15# the NixOS machines, see the eval job.
16jobs:
17 list:
18 runs-on: ubuntu-latest
19 outputs:
20 checks: ${{ steps.list.outputs.checks }}
21 steps:
22 - uses: actions/checkout@v4
23 with:
24 # Fetch all history for git-based operations
25 fetch-depth: 0
26
27 - uses: cachix/install-nix-action@v31
28
29 - id: list
30 run: |
31 checks=$(nix eval --json .#checks.x86_64-linux --apply builtins.attrNames)
32 echo "checks=$checks" >> "$GITHUB_OUTPUT"
33
34 check:
35 needs: list
36 name: ${{ matrix.check }}
37 runs-on: ubuntu-latest
38 strategy:
39 fail-fast: false
40 matrix:
41 check: ${{ fromJSON(needs.list.outputs.checks) }}
42 steps:
43 - uses: actions/checkout@v4
44 with:
45 # Fetch all history for git-based operations
46 fetch-depth: 0
47
48 - uses: cachix/install-nix-action@v31
49
50 - run: nix build -L --no-link '.#checks.x86_64-linux.${{ matrix.check }}'
51
52 outputs:
53 name: packages and devShells
54 runs-on: ubuntu-latest
55 steps:
56 - uses: actions/checkout@v4
57 with:
58 # Fetch all history for git-based operations
59 fetch-depth: 0
60
61 - uses: cachix/install-nix-action@v31
62
63 - run: |
64 for output in packages devShells; do
65 echo "$output:"
66 # shellcheck disable=SC2016 # ${...} is Nix interpolation
67 nix eval --raw ".#$output.x86_64-linux" --apply 'xs: builtins.deepSeq (builtins.mapAttrs (_: x: x.drvPath) xs) "${toString (builtins.length (builtins.attrNames xs))} evaluated\n"'
68 done
69
70 # The NixOS machines, built on plain runners with hestia (the GitHub Actions
71 # cache) as binary cache next to cache.lassul.us:
72 #
73 # - eval: evaluates ciToplevels once, uploads the drv closures to hestia
74 # and lists the machines whose toplevel is in neither cache.
75 # - shared: builds the derivations needed by more than one of them once,
76 # so the machine jobs substitute them instead of each building them.
77 # - one job per listed machine, builds its toplevel by drv path on a lazy
78 # /nix/store (.github/lazy-store.sh): the paths it would substitute are
79 # only downloaded once a file in them is opened.
80 #
81 # Every job pushes what it added to the store to cache.lassul.us
82 # (.github/ci-build.sh), for deploys.
83 eval:
84 runs-on: ubuntu-latest
85 permissions:
86 contents: read
87 actions: read # hestia: detect evicted cache entries upfront
88 id-token: write # niks3 push
89 outputs:
90 matrix: ${{ steps.matrix.outputs.matrix }}
91 any-jobs: ${{ steps.matrix.outputs.any-jobs }}
92 manifest-version: ${{ steps.matrix.outputs.manifest-version }}
93 niks3: ${{ steps.tools.outputs.niks3 }}
94 lazy-store: ${{ steps.tools.outputs.lazy-store }}
95 steps:
96 - uses: actions/checkout@v4
97 - uses: cachix/install-nix-action@v31
98 with:
99 extra_nix_config: |
100 trusted-users = root runner
101 extra-substituters = https://cache.lassul.us
102 extra-trusted-public-keys = cache.lassul.us-1:aOMEO5TU6eLvhyPi0jmgjR2sVlGjMq3rK0MeACjTcQ0=
103 - uses: Mic92/hestia@v3
104 with:
105 upstream-cache-filter: true
106 upstream-cache-key-names: cache.nixos.org-1 cache.lassul.us-1
107 filter-drv-closures: true
108 # the niks3 client of all jobs and the lazy store of the machine jobs,
109 # the others substitute them; nix-eval-jobs from the flake's nixpkgs,
110 # which the flake evaluation fetches anyway
111 - id: tools
112 run: |
113 niks3=$(nix build --no-link --print-out-paths .#niks3)
114 lazy=$(nix build --no-link --print-out-paths .#lazy-store)
115 nej=$(nix build --no-link --print-out-paths --inputs-from . nixpkgs#nix-eval-jobs)
116 {
117 echo "niks3=$niks3"
118 echo "lazy-store=$lazy"
119 echo "nix-eval-jobs=$nej/bin/nix-eval-jobs"
120 } >> "$GITHUB_OUTPUT"
121 PATH=$niks3/bin:$PATH .github/niks3-push.sh "$niks3" "$lazy"
122 - id: matrix
123 uses: Mic92/hestia/matrix@v3
124 with:
125 flake: ".#ciToplevels"
126 nix-eval-jobs: "${{ steps.tools.outputs.nix-eval-jobs }} --workers 4 --max-memory-size 3072"
127 - env:
128 MATRIX: ${{ steps.matrix.outputs.matrix }}
129 run: |
130 echo "not cached: $(jq -r '[.include[].name] | join(" ")' <<<"$MATRIX")" |
131 tee -a "$GITHUB_STEP_SUMMARY"
132
133 shared:
134 needs: eval
135 if: needs.eval.outputs.any-jobs == 'true'
136 runs-on: ubuntu-latest
137 permissions:
138 contents: read
139 actions: read # hestia: detect evicted cache entries upfront
140 id-token: write # niks3 push
141 outputs:
142 manifest-version: ${{ steps.build.outputs.manifest-version }}
143 steps:
144 - uses: actions/checkout@v4
145 - uses: cachix/install-nix-action@v31
146 with:
147 extra_nix_config: |
148 trusted-users = root runner
149 extra-substituters = https://cache.lassul.us
150 extra-trusted-public-keys = cache.lassul.us-1:aOMEO5TU6eLvhyPi0jmgjR2sVlGjMq3rK0MeACjTcQ0=
151 - uses: Mic92/hestia@v3
152 with:
153 upstream-cache-filter: true
154 upstream-cache-key-names: cache.nixos.org-1 cache.lassul.us-1
155 wait-manifest-version: ${{ needs.eval.outputs.manifest-version }}
156 - env:
157 NIKS3: ${{ needs.eval.outputs.niks3 }}
158 run: |
159 nix-store --realise "$NIKS3"
160 echo "$NIKS3/bin" >> "$GITHUB_PATH"
161 - id: build
162 env:
163 MATRIX: ${{ needs.eval.outputs.matrix }}
164 EVAL_MANIFEST_VERSION: ${{ needs.eval.outputs.manifest-version }}
165 run: |
166 matrix=$RUNNER_TEMP/matrix.json
167 plans=$RUNNER_TEMP/plans
168 printf '%s' "$MATRIX" > "$matrix"
169 read -ra installables <<<"$(jq -r '[.include[].installables] | join(" ")' "$matrix")"
170 "$HESTIA_BIN" prefetch "${installables[@]}"
171 .github/ci-shared.sh "$matrix" "$plans"
172 mapfile -t shared < "$plans/shared.drvs"
173 version=$EVAL_MANIFEST_VERSION
174 if [ "${#shared[@]}" -gt 0 ]; then
175 # a failed one fails the jobs of the machines that need it
176 .github/ci-build.sh "${shared[@]/%/^*}" ||
177 echo "::warning::some shared derivations failed to build"
178 # upload now instead of in the post step, so the machine jobs can
179 # wait for the manifest version that contains the shared outputs
180 "$HESTIA_BIN" drain --socket "$HESTIA_SOCKET" 2>&1 | tee "$RUNNER_TEMP/drain.txt"
181 drained=$(sed -nE 's/.*; manifest m[0-9]+#([0-9]+)$/\1/p' "$RUNNER_TEMP/drain.txt")
182 version=${drained:-$version}
183 fi
184 echo "manifest-version=$version" >> "$GITHUB_OUTPUT"
185 {
186 for name in $(jq -r '.include[].name' "$matrix"); do
187 echo "- $name: $(wc -l < "$plans/$name.drvs") derivations to build"
188 done
189 echo "- shared (needed by >= 2 machines): ${#shared[@]}"
190 printf '%s\n' "${shared[@]}" | sed -E 's|^/nix/store/[^-]+-(.*)\.drv$| \1|'
191 } | tee -a "$GITHUB_STEP_SUMMARY"
192
193 build:
194 needs: [eval, shared]
195 if: needs.eval.outputs.any-jobs == 'true'
196 name: ${{ matrix.name }}
197 runs-on: ${{ matrix.os }}
198 permissions:
199 contents: read
200 actions: read # hestia: detect evicted cache entries upfront
201 id-token: write # niks3 push
202 strategy:
203 fail-fast: false
204 matrix: ${{ fromJSON(needs.eval.outputs.matrix) }}
205 steps:
206 - uses: actions/checkout@v4
207 - uses: cachix/install-nix-action@v31
208 with:
209 extra_nix_config: |
210 trusted-users = root runner
211 extra-substituters = https://cache.lassul.us
212 extra-trusted-public-keys = cache.lassul.us-1:aOMEO5TU6eLvhyPi0jmgjR2sVlGjMq3rK0MeACjTcQ0=
213 - uses: Mic92/hestia@v3
214 with:
215 upstream-cache-filter: true
216 upstream-cache-key-names: cache.nixos.org-1 cache.lassul.us-1
217 wait-manifest-version: ${{ needs.shared.outputs.manifest-version }}
218 - env:
219 NIKS3: ${{ needs.eval.outputs.niks3 }}
220 run: |
221 nix-store --realise "$NIKS3"
222 echo "$NIKS3/bin" >> "$GITHUB_PATH"
223 - name: build ${{ matrix.name }}
224 env:
225 INSTALLABLES: ${{ matrix.installables }}
226 LAZY_STORE: ${{ needs.eval.outputs.lazy-store }}
227 run: |
228 read -ra installables <<<"$INSTALLABLES"
229 "$HESTIA_BIN" prefetch "${installables[@]}"
230 .github/lazy-store.sh "${installables[@]}"
231 .github/ci-build.sh "${installables[@]}"
232 - name: lazy store log
233 if: always()
234 run: |
235 dir=$RUNNER_TEMP/lazy-store
236 if [ -s "$dir/stats.json" ]; then
237 jq -r '"\(.nar_count // 0) NARs fetched, \((.nar_bytes // 0) / 1048576 | floor) MiB"' "$dir/stats.json"
238 fi
239 cat "$dir/fuse.log" 2>/dev/null || true
240
241 # Fixed-name summary of the jobs above, the required status check for
242 # merging into master (the matrix job names change with the hosts).
243 # Skipped: no machine to build, or a job it needs failed.
244 ci:
245 needs: [list, check, outputs, eval, shared, build]
246 if: always()
247 runs-on: ubuntu-latest
248 steps:
249 - env:
250 RESULTS: ${{ join(needs.*.result, ' ') }}
251 run: |
252 echo "results: $RESULTS"
253 for r in $RESULTS; do
254 [ "$r" = success ] || [ "$r" = skipped ] || exit 1
255 done