Skip to content

Commit 59ea118

Browse files
committed
ci: Auto-determine checks to run
This will allow us to support multiple platforms easily.
1 parent a9e2c0e commit 59ea118

File tree

3 files changed

+70
-42
lines changed

3 files changed

+70
-42
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,4 @@ jobs:
3636
name: fossar
3737
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
3838

39-
- name: Set job parameters
40-
id: params
41-
run: |
42-
branch=${{ matrix.php.branch }}
43-
major=${branch%%.*}
44-
minor=${branch#*.}
45-
attr=php$major$minor
46-
echo "::set-output name=major::$major"
47-
echo "::set-output name=attr::$attr"
48-
49-
- name: Build PHP
50-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-php
51-
52-
- name: Build Imagick extension
53-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-imagick
54-
55-
- name: Build Redis extension
56-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-redis
57-
58-
- name: Build Redis 3 extension
59-
if: ${{ steps.params.outputs.major < 8 }}
60-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-redis3
61-
62-
- name: Build MySQL extension
63-
if: ${{ steps.params.outputs.major < 7 }}
64-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-mysql
65-
66-
- name: Build Xdebug extension
67-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-xdebug
68-
69-
- name: Build Tidy extension
70-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-tidy
71-
72-
- name: Check that composer PHAR works
73-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-composer-phar
74-
75-
- name: Validate php.extensions.mysqli default unix socket path
76-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-mysqli-socket-path
77-
78-
- name: Validate php.extensions.pdo_mysql default unix socket path
79-
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-pdo_mysql-socket-path
39+
- run: nix-shell run-flake-checks.nix --argstr branch "${{ matrix.php.branch }}"

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
}:
6767

6868
drv // {
69-
description = "PHP ${phpVersion}${description}";
69+
inherit description;
70+
phpBranch = phpVersion;
7071
}
7172
)
7273
supportedChecks;

run-flake-checks.nix

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Runs Nix flake checks individually with group markers for GitHub Actions.
2+
# Invoke with `nix-shell run-flake-checks.nix --argstr branch "8.1"`
3+
{
4+
# PHP attribute to run checks for. `null` for all checks.
5+
branch ? null,
6+
}:
7+
8+
let
9+
self = import ./.;
10+
11+
pkgs = self.inputs.nixpkgs.legacyPackages.${builtins.currentSystem};
12+
inherit (self.inputs.nixpkgs) lib;
13+
14+
checks = self.outputs.checks.${builtins.currentSystem};
15+
16+
phpName =
17+
assert lib.assertMsg (builtins.match "[0-9]+.[0-9]+" branch != null) "Branch name “${builtins.toString branch}” does not match a version number.";
18+
19+
"php${lib.versions.major branch}${lib.versions.minor branch}";
20+
21+
relevantChecks =
22+
if branch == null
23+
then checks
24+
else lib.filterAttrs (key: value: lib.hasPrefix "${phpName}-" key) checks;
25+
in
26+
27+
assert lib.assertMsg (relevantChecks != { }) "No checks found for branch “${builtins.toString branch}”.";
28+
29+
pkgs.stdenv.mkDerivation {
30+
name = "run-flake-checks";
31+
32+
buildCommand = ''
33+
echo 'Please run `nix-shell run-flake-checks.nix`, `nix-build` cannot be used.' > /dev/stderr
34+
exit 1
35+
'';
36+
37+
shellHook =
38+
''
39+
set -o errexit
40+
''
41+
+ builtins.concatStringsSep
42+
"\n"
43+
(
44+
lib.mapAttrsToList
45+
(
46+
name:
47+
value:
48+
49+
let
50+
description =
51+
lib.optionalString (branch == null) "PHP ${value.phpBranch} – "
52+
+ value.description;
53+
in
54+
''
55+
echo "::group::${description}"
56+
echo Run nix-build -A outputs.checks.${builtins.currentSystem}.${name}
57+
nix-build --no-out-link -A outputs.checks.${builtins.currentSystem}.${name}
58+
echo "::endgroup::"
59+
''
60+
)
61+
relevantChecks
62+
)
63+
+ ''
64+
exit 0
65+
''
66+
;
67+
}

0 commit comments

Comments
 (0)