forked from
lass.pds.lassul.us/superconfig
This repository has no description
9.3 kB
247 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 filter-drv-closures: true
107 # the niks3 client of all jobs and the lazy store of the machine jobs,
108 # the others substitute them
109 - id: tools
110 run: |
111 niks3=$(nix build --no-link --print-out-paths .#niks3)
112 lazy=$(nix build --no-link --print-out-paths .#lazy-store)
113 echo "niks3=$niks3" >> "$GITHUB_OUTPUT"
114 echo "lazy-store=$lazy" >> "$GITHUB_OUTPUT"
115 PATH=$niks3/bin:$PATH .github/niks3-push.sh "$niks3" "$lazy"
116 - id: matrix
117 uses: Mic92/hestia/matrix@v3
118 with:
119 flake: ".#ciToplevels"
120 nix-eval-jobs: "nix run nixpkgs#nix-eval-jobs -- --workers 4 --max-memory-size 3072"
121 - env:
122 MATRIX: ${{ steps.matrix.outputs.matrix }}
123 run: |
124 echo "not cached: $(jq -r '[.include[].name] | join(" ")' <<<"$MATRIX")" |
125 tee -a "$GITHUB_STEP_SUMMARY"
126
127 shared:
128 needs: eval
129 if: needs.eval.outputs.any-jobs == 'true'
130 runs-on: ubuntu-latest
131 permissions:
132 contents: read
133 actions: read # hestia: detect evicted cache entries upfront
134 id-token: write # niks3 push
135 outputs:
136 manifest-version: ${{ steps.build.outputs.manifest-version }}
137 steps:
138 - uses: actions/checkout@v4
139 - uses: cachix/install-nix-action@v31
140 with:
141 extra_nix_config: |
142 trusted-users = root runner
143 extra-substituters = https://cache.lassul.us
144 extra-trusted-public-keys = cache.lassul.us-1:aOMEO5TU6eLvhyPi0jmgjR2sVlGjMq3rK0MeACjTcQ0=
145 - uses: Mic92/hestia@v3
146 with:
147 upstream-cache-filter: true
148 wait-manifest-version: ${{ needs.eval.outputs.manifest-version }}
149 - env:
150 NIKS3: ${{ needs.eval.outputs.niks3 }}
151 run: |
152 nix-store --realise "$NIKS3"
153 echo "$NIKS3/bin" >> "$GITHUB_PATH"
154 - id: build
155 env:
156 MATRIX: ${{ needs.eval.outputs.matrix }}
157 EVAL_MANIFEST_VERSION: ${{ needs.eval.outputs.manifest-version }}
158 run: |
159 matrix=$RUNNER_TEMP/matrix.json
160 plans=$RUNNER_TEMP/plans
161 printf '%s' "$MATRIX" > "$matrix"
162 read -ra installables <<<"$(jq -r '[.include[].installables] | join(" ")' "$matrix")"
163 "$HESTIA_BIN" prefetch "${installables[@]}"
164 .github/ci-shared.sh "$matrix" "$plans"
165 mapfile -t shared < "$plans/shared.drvs"
166 version=$EVAL_MANIFEST_VERSION
167 if [ "${#shared[@]}" -gt 0 ]; then
168 # a failed one fails the jobs of the machines that need it
169 .github/ci-build.sh "${shared[@]/%/^*}" ||
170 echo "::warning::some shared derivations failed to build"
171 # upload now instead of in the post step, so the machine jobs can
172 # wait for the manifest version that contains the shared outputs
173 "$HESTIA_BIN" drain --socket "$HESTIA_SOCKET" 2>&1 | tee "$RUNNER_TEMP/drain.txt"
174 drained=$(sed -nE 's/.*; manifest m[0-9]+#([0-9]+)$/\1/p' "$RUNNER_TEMP/drain.txt")
175 version=${drained:-$version}
176 fi
177 echo "manifest-version=$version" >> "$GITHUB_OUTPUT"
178 {
179 for name in $(jq -r '.include[].name' "$matrix"); do
180 echo "- $name: $(wc -l < "$plans/$name.drvs") derivations to build"
181 done
182 echo "- shared (needed by >= 2 machines): ${#shared[@]}"
183 printf '%s\n' "${shared[@]}" | sed -E 's|^/nix/store/[^-]+-(.*)\.drv$| \1|'
184 } | tee -a "$GITHUB_STEP_SUMMARY"
185
186 build:
187 needs: [eval, shared]
188 if: needs.eval.outputs.any-jobs == 'true'
189 name: ${{ matrix.name }}
190 runs-on: ${{ matrix.os }}
191 permissions:
192 contents: read
193 actions: read # hestia: detect evicted cache entries upfront
194 id-token: write # niks3 push
195 strategy:
196 fail-fast: false
197 matrix: ${{ fromJSON(needs.eval.outputs.matrix) }}
198 steps:
199 - uses: actions/checkout@v4
200 - uses: cachix/install-nix-action@v31
201 with:
202 extra_nix_config: |
203 trusted-users = root runner
204 extra-substituters = https://cache.lassul.us
205 extra-trusted-public-keys = cache.lassul.us-1:aOMEO5TU6eLvhyPi0jmgjR2sVlGjMq3rK0MeACjTcQ0=
206 - uses: Mic92/hestia@v3
207 with:
208 upstream-cache-filter: true
209 wait-manifest-version: ${{ needs.shared.outputs.manifest-version }}
210 - env:
211 NIKS3: ${{ needs.eval.outputs.niks3 }}
212 run: |
213 nix-store --realise "$NIKS3"
214 echo "$NIKS3/bin" >> "$GITHUB_PATH"
215 - name: build ${{ matrix.name }}
216 env:
217 INSTALLABLES: ${{ matrix.installables }}
218 LAZY_STORE: ${{ needs.eval.outputs.lazy-store }}
219 run: |
220 read -ra installables <<<"$INSTALLABLES"
221 "$HESTIA_BIN" prefetch "${installables[@]}"
222 .github/lazy-store.sh "${installables[@]}"
223 .github/ci-build.sh "${installables[@]}"
224 - name: lazy store log
225 if: always()
226 run: |
227 dir=$RUNNER_TEMP/lazy-store
228 if [ -s "$dir/stats.json" ]; then
229 jq -r '"\(.nar_count // 0) NARs fetched, \((.nar_bytes // 0) / 1048576 | floor) MiB"' "$dir/stats.json"
230 fi
231 cat "$dir/fuse.log" 2>/dev/null || true
232
233 # Fixed-name summary of the jobs above, the required status check for
234 # merging into master (the matrix job names change with the hosts).
235 # Skipped: no machine to build, or a job it needs failed.
236 ci:
237 needs: [list, check, outputs, eval, shared, build]
238 if: always()
239 runs-on: ubuntu-latest
240 steps:
241 - env:
242 RESULTS: ${{ join(needs.*.result, ' ') }}
243 run: |
244 echo "results: $RESULTS"
245 for r in $RESULTS; do
246 [ "$r" = success ] || [ "$r" = skipped ] || exit 1
247 done