Skip to content

Commit 345e9ec

Browse files
committed
feat: do not return empty matrices if no package has to be built
1 parent e72d3e0 commit 345e9ec

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

.github/workflows/nix-build.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,21 @@ jobs:
3434
matrix: ${{ fromJSON(needs.nix-eval.outputs.matrix).aarch64_linux }}
3535
steps:
3636
- name: Checkout Repo
37+
if: ${{ matrix.attr != '' }}
3738
uses: actions/checkout@v4
3839
- name: Install nix (ephemeral)
39-
if: ${{ matrix.runs_on.group != 'self-hosted-runners-nix' }}
40+
if: ${{ matrix.attr != '' && matrix.runs_on.group != 'self-hosted-runners-nix' }}
4041
uses: ./.github/actions/nix-install-ephemeral
4142
with:
4243
push-to-cache: 'true'
4344
env:
4445
DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }}
4546
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
4647
- name: Install nix (self-hosted)
47-
if: ${{ matrix.runs_on.group == 'self-hosted-runners-nix' }}
48+
if: ${{ matrix.attr != '' && matrix.runs_on.group == 'self-hosted-runners-nix' }}
4849
uses: ./.github/actions/nix-install-self-hosted
4950
- name: nix build
51+
if: ${{ matrix.attr != '' }}
5052
shell: bash
5153
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
5254

@@ -55,18 +57,21 @@ jobs:
5557
${{ matrix.name }}${{ matrix.postgresql_version && format(' - Postgres {0}', matrix.postgresql_version) || '' }}
5658
(aarch64-darwin)
5759
needs: nix-eval
58-
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
60+
runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
5961
if: ${{ fromJSON(needs.nix-eval.outputs.matrix).aarch64_darwin != null }}
6062
strategy:
6163
fail-fast: false
6264
max-parallel: 5
6365
matrix: ${{ fromJSON(needs.nix-eval.outputs.matrix).aarch64_darwin }}
6466
steps:
6567
- name: Checkout Repo
68+
if: ${{ matrix.attr != '' }}
6669
uses: actions/checkout@v4
6770
- name: Install nix
71+
if: ${{ matrix.attr != '' }}
6872
uses: ./.github/actions/nix-install-self-hosted
6973
- name: nix build
74+
if: ${{ matrix.attr != '' }}
7075
shell: bash
7176
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
7277

@@ -75,23 +80,26 @@ jobs:
7580
${{ matrix.name }}${{ matrix.postgresql_version && format(' - Postgres {0}', matrix.postgresql_version) || '' }}
7681
(x86_64-linux)
7782
needs: nix-eval
78-
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
83+
runs-on: ${{ matrix.attr != '' && matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
7984
if: ${{ fromJSON(needs.nix-eval.outputs.matrix).x86_64_linux != null }}
8085
strategy:
8186
fail-fast: false
8287
max-parallel: 5
8388
matrix: ${{ fromJSON(needs.nix-eval.outputs.matrix).x86_64_linux }}
8489
steps:
8590
- name: Checkout Repo
91+
if: ${{ matrix.attr != '' }}
8692
uses: actions/checkout@v4
8793
- name: Install nix
94+
if: ${{ matrix.attr != '' }}
8895
uses: ./.github/actions/nix-install-ephemeral
8996
with:
9097
push-to-cache: 'true'
9198
env:
9299
DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }}
93100
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
94101
- name: nix build
102+
if: ${{ matrix.attr != '' }}
95103
shell: bash
96104
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
97105

nix/packages/github-matrix/github_matrix.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Optional,
1818
Set,
1919
TypedDict,
20+
get_args,
2021
)
2122

2223
System = Literal["x86_64-linux", "aarch64-linux", "aarch64-darwin"]
@@ -252,10 +253,23 @@ def clean_package_for_output(pkg: NixEvalJobsOutput) -> GitHubActionPackage:
252253
grouped_by_system[pkg["system"]].append(clean_package_for_output(pkg))
253254

254255
# Create output with system-specific matrices
256+
# Ensure that we have at least one entry per system
255257
gh_output = {}
256258
for system, packages in grouped_by_system.items():
257259
gh_output[system.replace("-", "_")] = {"include": packages}
258260

261+
for system in get_args(System):
262+
if system not in gh_output:
263+
gh_output[system.replace("-", "_")] = {
264+
"include": [
265+
{
266+
"attr": "",
267+
"name": "skipped",
268+
"system": system,
269+
"runs_on": {"labels": "ubuntu-latest"},
270+
}
271+
]
272+
}
259273
print(
260274
f"debug: Generated GitHub Actions matrix: {json.dumps(gh_output, indent=2)}",
261275
file=sys.stderr,

0 commit comments

Comments
 (0)