Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit 4f8fdf7

Browse files
committed
feat: Add GA
1 parent b504950 commit 4f8fdf7

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

.github/workflows/build-flake.yaml

+221
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
---
2+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
3+
name: Build Flake
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
branches:
12+
- main
13+
14+
env:
15+
flake: github:${{ github.repository }}/${{ github.sha }}
16+
nix-conf: |-
17+
accept-flake-config = true
18+
builders-use-substitutes = true
19+
max-jobs = auto
20+
cachix-install: nix profile install 'github:${{ github.repository }}/${{ github.sha }}#cachix'
21+
22+
jobs:
23+
flake-check:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: DeterminateSystems/nix-installer-action@v10
27+
with:
28+
extra-conf: ${{ env.nix-conf }}
29+
- uses: cachix/cachix-action@v14
30+
with:
31+
name: bjw-s
32+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
33+
extraPullNames: nix-community
34+
installCommand: ${{ env.cachix-install }}
35+
- name: nix-flake-check
36+
run: nix flake check '${{ env.flake }}'
37+
38+
flake-show:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: DeterminateSystems/nix-installer-action@v10
42+
with:
43+
extra-conf: ${{ env.nix-conf }}
44+
- uses: cachix/cachix-action@v14
45+
with:
46+
name: bjw-s
47+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
48+
extraPullNames: nix-community
49+
installCommand: ${{ env.cachix-install }}
50+
- name: nix-flake-show
51+
run: nix flake show '${{ env.flake }}'
52+
53+
get-attrs:
54+
runs-on: ubuntu-latest
55+
outputs:
56+
build: ${{ steps.get-attrs.outputs.build }}
57+
eval: ${{ steps.get-attrs.outputs.eval }}
58+
env:
59+
has_aarch64_ssh_key: ${{ secrets.AARCH64_BUILDER_KEY != '' }}
60+
steps:
61+
- uses: DeterminateSystems/nix-installer-action@v10
62+
with:
63+
extra-conf: ${{ env.nix-conf }}
64+
- id: install-jq
65+
run: nix profile install '${{ env.flake }}#pkgs.x86_64-linux.jq'
66+
- id: get-attrs
67+
run: |
68+
function summary() {
69+
printf '%s\n' "${*}" >> "$GITHUB_STEP_SUMMARY"
70+
}
71+
72+
summary "# CI"
73+
TMP="$(mktemp -d)"
74+
# host packages
75+
nix eval --json '${{ env.flake }}#hosts' | jq -c '
76+
to_entries
77+
| map({
78+
name: .key,
79+
evalOnly: false,
80+
hostPlatform: .value.hostPlatform,
81+
large: .value.large,
82+
attr: "packages.\(.value.hostPlatform).\(.key)"
83+
})
84+
| map(
85+
if .hostPlatform == "x86_64-linux" then .runsOn="ubuntu-latest"
86+
elif .hostPlatform == "aarch64-linux" then .runsOn="ubuntu-latest"
87+
elif .hostPlatform == "x86_64-darwin" then .runsOn="macos-latest"
88+
else .evalOnly=true | .runsOn="ubuntu-latest"
89+
end
90+
)
91+
| map(if .large then .evalOnly=true end)
92+
' >"$TMP/hostAttrs.json"
93+
94+
# handle not being able to build aarch64-linux attrs when the ssh key
95+
# is missing
96+
if [[ "${has_aarch64_ssh_key}" != 'true' ]]; then
97+
summary \
98+
"- ⚠️ AArch64 builder SSH key is unavailable, all \`aarch64-linux\` attrs will be eval-only"
99+
old_host_attrs="$(<"$TMP/hostAttrs.json")"
100+
jq -c \
101+
'map(if .hostPlatform == "aarch64-linux" then .evalOnly=true end)' \
102+
<<<"$old_host_attrs" >"$TMP/hostAttrs.json"
103+
fi
104+
105+
# join shell (if any) and host attrs
106+
jq -c -s add "$TMP/hostAttrs.json" >"$TMP/attrs.json"
107+
108+
# warn about eval-only attrs
109+
read -r -a evalOnlyAttrs < \
110+
<(jq -c -r 'map(select(.evalOnly) | .name) | @sh' "$TMP/attrs.json" | tr -d \')
111+
if [[ "${#evalOnlyAttrs[@]}" -ne 0 ]]; then
112+
printf -v attrs "\`%s\`, " "${evalOnlyAttrs[@]}"
113+
summary \
114+
"- ⚠️ The following attributes will only be evaluated: ${attrs%, }"
115+
fi
116+
117+
# add all to-build attrs to the summary
118+
read -r -a buildAttrs < \
119+
<(jq -c -r 'map(select(.evalOnly | not) | .name) | @sh' "$TMP/attrs.json" | tr -d \')
120+
if [[ "${#buildAttrs[@]}" -ne 0 ]]; then
121+
printf -v attrs "\`%s\`, " "${buildAttrs[@]}"
122+
summary \
123+
"- ✅ The following attributes will be built: ${attrs%, }"
124+
fi
125+
126+
# check for dupes
127+
duplicate_count="$(jq -r '
128+
group_by([.name, .attr]) | map(select(length>1)) | length
129+
' "$TMP/attrs.json")"
130+
if [[ "$duplicate_count" -ne 0 ]]; then
131+
summary \
132+
"- ‼️ Duplicate entries in \`attrs.json\`: \`$(cat "$TMP/attrs.json")\`"
133+
exit 1
134+
fi
135+
136+
# split build and evalOnly attrs
137+
jq -c 'map(select(.evalOnly))' <"$TMP/attrs.json" >"$TMP/eval.json"
138+
jq -c 'map(select(.evalOnly | not))' <"$TMP/attrs.json" >"$TMP/build.json"
139+
140+
echo "build=$(<"$TMP/build.json")" >>"$GITHUB_OUTPUT"
141+
echo "eval=$(<"$TMP/eval.json")" >>"$GITHUB_OUTPUT"
142+
143+
eval:
144+
name: eval ${{ matrix.attrs.name }}
145+
runs-on: ${{ matrix.attrs.runsOn }}
146+
needs: [get-attrs]
147+
strategy:
148+
fail-fast: false
149+
matrix:
150+
attrs: ${{ fromJson(needs.get-attrs.outputs.eval) }}
151+
env:
152+
system: ${{ matrix.attrs.hostPlatform }}
153+
steps:
154+
- uses: DeterminateSystems/nix-installer-action@v10
155+
with:
156+
extra-conf: ${{ env.nix-conf }}
157+
- uses: cachix/cachix-action@v14
158+
with:
159+
name: bjw-s
160+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
161+
extraPullNames: nix-community
162+
installCommand: ${{ env.cachix-install }}
163+
- name: eval
164+
if: ${{ matrix.attrs.evalOnly }}
165+
run: |
166+
nix eval --raw '${{ env.flake }}#${{ matrix.attrs.attr }}'
167+
168+
build:
169+
name: build ${{ matrix.attrs.name }}
170+
runs-on: ${{ matrix.attrs.runsOn }}
171+
needs: [get-attrs]
172+
strategy:
173+
fail-fast: false
174+
matrix:
175+
attrs: ${{ fromJson(needs.get-attrs.outputs.build) }}
176+
env:
177+
aarch64-ssh-key: ${{ secrets.AARCH64_BUILDER_KEY }}
178+
system: ${{ matrix.attrs.hostPlatform }}
179+
steps:
180+
- uses: DeterminateSystems/nix-installer-action@v10
181+
with:
182+
extra-conf: ${{ env.nix-conf }}
183+
- uses: cachix/cachix-action@v14
184+
with:
185+
name: bjw-s
186+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
187+
extraPullNames: nix-community
188+
installCommand: ${{ env.cachix-install }}
189+
- name: setup-aarch64-ssh
190+
if: ${{ env.system == 'aarch64-linux' }}
191+
run: |
192+
mkdir -p ~/.ssh
193+
echo '${{ env.aarch64-ssh-config }}' > ~/.ssh/config
194+
echo '${{ env.aarch64-ssh-known-host }}' >> ~/.ssh/known_hosts
195+
echo '${{ env.aarch64-ssh-key }}' > ~/.ssh/id_ed25519
196+
chmod 0600 ~/.ssh/*
197+
- name: build
198+
run: |
199+
declare -a args=(
200+
'--no-nom'
201+
'--skip-cached'
202+
'--systems=${{ env.system }}'
203+
'--option' 'accept-flake-config' 'true'
204+
'--retries=3'
205+
)
206+
[[ '${{ env.system }}' == 'aarch64-linux' ]] && args+=('--remote=${{ env.aarch64-host }}')
207+
args+=('--flake=${{ env.flake }}#${{ matrix.attrs.attr }}')
208+
nix run '${{ env.flake }}#nix-fast-build' -- "${args[@]}"
209+
210+
check:
211+
runs-on: ubuntu-latest
212+
needs: [flake-check, flake-show, build, eval]
213+
if: always()
214+
steps:
215+
- name: Check matrix status
216+
if: >-
217+
${{
218+
contains(needs.*.result, 'failure')
219+
|| contains(needs.*.result, 'cancelled')
220+
}}
221+
run: exit 1

0 commit comments

Comments
 (0)