Skip to content

Commit 3085e73

Browse files
authored
Add nix eval fallback to -env closure discovery (#242)
When Hydra resolves builds from cache, it creates only aggregate "required" check-runs but not individual per-build check-runs. This causes the GHA upload workflow to discover zero -env closures and skip all container uploads. Add a fallback path: when no Hydra check-runs ending in "-env" are found, evaluate the store paths directly from the flake using nix eval with extra/discover-env.nix. This ensures containers are always uploaded regardless of Hydra's check-run behavior. Also install Nix and checkout the repo in the Discover step to support the fallback evaluation.
1 parent 0e060b5 commit 3085e73

2 files changed

Lines changed: 53 additions & 5 deletions

File tree

.github/workflows/main.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,40 @@ jobs:
3131
outputs:
3232
matrix: ${{ steps.set-matrix.outputs.matrix }}
3333
steps:
34-
- name: Discover Hydra build check-runs
34+
- name: Install Nix (for fallback discovery)
35+
uses: cachix/install-nix-action@v20
36+
with:
37+
extra_nix_config: |
38+
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk=
39+
substituters = https://cache.iog.io/ https://cache.zw3rk.com/ https://cache.nixos.org/
40+
nix_path: nixpkgs=channel:nixos-unstable
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
- name: Discover devShell -env closures
3544
id: set-matrix
3645
run: |
37-
# Group the output by platform.
46+
PLATFORM="${{ inputs.platform }}"
47+
48+
# Primary: discover from Hydra check-runs (fastest path).
49+
# Each Hydra build check-run has the Nix store path in output.summary.
3850
RUNS=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/check-runs" --paginate)
39-
echo "checks..."
40-
FILTERED=$(jq -c -r '.check_runs[] | select(.name | endswith("-env")) | select(.name | startswith("${{ inputs.platform }}")) | { "config": .name, "build_path": .output.summary, "short_name": .name | sub("${{ inputs.platform }}\\.";"") }' <<< "$RUNS")
41-
jq . <<< "$FILTERED"
51+
echo "Checking Hydra check-runs for -env closures..."
52+
FILTERED=$(jq -c -r '.check_runs[] | select(.name | endswith("-env")) | select(.name | startswith("'"$PLATFORM"'")) | { "config": .name, "build_path": .output.summary, "short_name": .name | sub("'"$PLATFORM"'\\.";"") }' <<< "$RUNS")
4253
MATRIX=$(jq --slurp -c -r '.' <<< "$FILTERED")
54+
55+
if [ "$MATRIX" != "[]" ]; then
56+
echo "Found $(echo "$MATRIX" | jq length) -env closures from Hydra check-runs."
57+
else
58+
# Fallback: evaluate store paths directly from the flake.
59+
# When Hydra resolves builds from cache, it may not create
60+
# individual GitHub check-runs — only the aggregate "required".
61+
# In that case, we compute the -env store paths ourselves.
62+
echo "::warning::No -env check-runs found. Evaluating store paths from flake..."
63+
MATRIX=$(nix eval ".#hydraJobs.${PLATFORM}" --json \
64+
--apply "import ./extra/discover-env.nix \"${PLATFORM}\"")
65+
echo "Evaluated $(echo "$MATRIX" | jq length) -env closures from flake."
66+
fi
67+
4368
jq . <<< "$MATRIX"
4469
echo "creating result matrix."
4570
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT

extra/discover-env.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# extra/discover-env.nix — Discover -env closure store paths from the flake.
2+
#
3+
# Copyright 2026 Input Output Group
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Used by the GHA upload workflow as a fallback when Hydra does not create
7+
# individual GitHub check-runs for cached builds. Evaluates the flake's
8+
# hydraJobs and returns a JSON array of {config, build_path, short_name}
9+
# for every -env attribute on the given platform.
10+
#
11+
# Usage:
12+
# nix eval ".#hydraJobs.<platform>" --json --apply "import ./extra/discover-env.nix \"<platform>\""
13+
#
14+
platform: jobs:
15+
let
16+
envNames = builtins.filter
17+
(n: builtins.match ".*-env" n != null)
18+
(builtins.attrNames jobs);
19+
in map (name: {
20+
config = platform + "." + name;
21+
build_path = builtins.unsafeDiscardStringContext (toString jobs.${name});
22+
short_name = name;
23+
}) envNames

0 commit comments

Comments
 (0)