ci: nested matrix build

This commit is contained in:
Matt Sturgeon 2025-05-25 23:20:50 +01:00
parent ce432ab608
commit ed2c309964
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 79 additions and 36 deletions

View file

@ -6,13 +6,8 @@ on:
name: name:
required: true required: true
type: string type: string
system: builds:
required: true description: "json array of builds: [ { system, runner, attr } ]"
type: string
os:
required: true
type: string
attr:
required: true required: true
type: string type: string
timeout: timeout:
@ -22,13 +17,16 @@ on:
jobs: jobs:
build: build:
name: ${{ inputs.name }} name: ${{ inputs.name }} (${{ matrix.attr }})
runs-on: runs-on:
- ${{ inputs.os }} - ${{ matrix.runner }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(inputs.builds) }}
timeout-minutes: ${{ inputs.timeout }} timeout-minutes: ${{ inputs.timeout }}
steps: steps:
- name: Free disk space - name: Free disk space
if: endsWith( '-linux', inputs.system ) if: endsWith( '-linux', matrix.system )
uses: wimpysworld/nothing-but-nix@main uses: wimpysworld/nothing-but-nix@main
with: with:
# Options: holster, carve, cleave (default), rampage # Options: holster, carve, cleave (default), rampage
@ -42,9 +40,9 @@ jobs:
with: with:
name: nix-community name: nix-community
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Build ${{ inputs.attr }} - name: Build ${{ matrix.attr }}
env: env:
attr: ${{ inputs.attr }} attr: ${{ matrix.attr }}
run: | run: |
nix build ".#$attr" \ nix build ".#$attr" \
--abort-on-warn \ --abort-on-warn \

View file

@ -39,7 +39,5 @@ jobs:
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }} matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
secrets: inherit secrets: inherit
with: with:
name: ${{ matrix.name }} (${{ matrix.system }}) name: ${{ matrix.name }}
system: ${{ matrix.system }} builds: ${{ toJSON(matrix.builds) }}
os: ${{ join( matrix.os, ' ' ) }} # FIXME: os is an array!
attr: ${{ matrix.attr }}

View file

@ -15,24 +15,71 @@
}; };
# Output a build matrix for CI # Output a build matrix for CI
flake.githubActions = inputs.nix-github-actions.lib.mkGithubMatrix { flake.githubActions.matrix =
checks = builtins.mapAttrs ( let
system: lib.filterAttrs (name: v: !lib.strings.hasPrefix "test-" name) systemsByPrio = [
# lib.flip lib.pipe [ "x86_64-linux"
# lib.attrsToList "aarch64-linux"
# # Group the "test-N" tests back into one drv "x86_64-darwin"
# # FIXME: drop the entire test-grouping system "aarch64-darwin"
# (builtins.groupBy ({ name, value }: if lib.strings.hasPrefix "test-" name then "test" else name)) ];
# (builtins.mapAttrs ( githubPlatforms = {
# group: tests: "x86_64-linux" = "ubuntu-24.04";
# let "x86_64-darwin" = "macos-13";
# pkgs = inputs.nixpkgs.legacyPackages.${system}; "aarch64-darwin" = "macos-14";
# singleton = (builtins.head tests).value; "aarch64-linux" = "ubuntu-24.04-arm";
# joined = pkgs.linkFarm group (builtins.listToAttrs tests);
# in
# if builtins.length tests > 1 then joined else singleton
# ))
# ]
) self.checks;
}; };
toGithubBuild = system: {
inherit system;
runner = githubPlatforms.${system} or (throw "System not supported by GitHub Actions: ${system}");
};
getPrimaryBuild =
platforms:
let
systems = builtins.catAttrs "system" platforms;
system = lib.lists.findFirst (
system: builtins.elem system systems
) (throw "No supported system found!") systemsByPrio;
in
toGithubBuild system;
in
lib.pipe self.checks [
(lib.mapAttrsRecursiveCond (x: !lib.isDerivation x) (
loc: _: {
_type = "check";
build = toGithubBuild (builtins.head loc);
name = lib.attrsets.showAttrPath (builtins.tail loc);
}
))
(lib.collect (lib.isType "check"))
(lib.groupBy' (acc: x: acc ++ [ x.build ]) [ ] (x: x.attr))
(lib.mapAttrsToList (attr: builds: { inherit attr builds; }))
# Only build one one system for non-test attrs
# TODO: this is very heavy handed, maybe we want some exceptions?
(map (
matrix:
matrix
// lib.optionalAttrs (!lib.strings.hasPrefix "test-" matrix.name) {
builds = [
(getPrimaryBuild matrix.builds)
];
}
))
# Inject per-system attr
(map (
matrix:
matrix
// {
builds = map (
build:
build
// {
attr = "checks.${build.system}.${matrix.name}";
}
) matrix.builds;
}
))
];
} }