Skip to content

Commit 5e1158a

Browse files
committed
fixup! ci: Auto-determine checks to run
1 parent 104ae88 commit 5e1158a

File tree

4 files changed

+290
-89
lines changed

4 files changed

+290
-89
lines changed

.github/workflows/build.yaml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,19 @@ on:
88
push:
99

1010
jobs:
11-
build:
12-
name: 'PHP ${{ matrix.php.branch }}'
11+
prepare-ci:
12+
name: 'Prepare actions'
1313
runs-on: ubuntu-20.04
14-
strategy:
15-
matrix:
16-
php:
17-
- branch: '8.1'
18-
- branch: '8.0'
19-
- branch: '7.4'
20-
- branch: '7.3'
21-
- branch: '7.2'
22-
- branch: '7.1'
23-
- branch: '7.0'
24-
- branch: '5.6'
25-
# We want to fix failures individually.
26-
fail-fast: false
2714
steps:
2815
- uses: actions/checkout@v2
2916

3017
- name: Install Nix
3118
uses: cachix/install-nix-action@v14
3219

33-
- name: Set up Nix cache
34-
uses: cachix/cachix-action@v10
35-
with:
36-
name: fossar
37-
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
38-
39-
- run: nix-shell run-flake-checks.nix --argstr branch "${{ matrix.php.branch }}"
20+
- name: Generate actions
21+
run: nix-shell .github/workflows/workflow-from-flake-checks.nix
22+
test:
23+
needs:
24+
- prepare-ci
25+
uses: ./.github/workflows/test.yaml
26+
secrets: inherit

.github/workflows/test.yaml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"jobs": {
3+
"test": {
4+
"name": "PHP ${{ matrix.php.branch }}",
5+
"runs-on": "${{ matrix.os.image }}",
6+
"steps": [
7+
{
8+
"uses": "actions/checkout@v2"
9+
},
10+
{
11+
"name": "Install Nix",
12+
"uses": "cachix/install-nix-action@v14"
13+
},
14+
{
15+
"name": "Set up Nix cache",
16+
"uses": "cachix/cachix-action@v10",
17+
"with": {
18+
"authToken": "${{ secrets.CACHIX_AUTH_TOKEN }}",
19+
"name": "fossar"
20+
}
21+
},
22+
{
23+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
24+
"name": "Check that composer PHAR works",
25+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-composer-phar"
26+
},
27+
{
28+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
29+
"name": "Build Imagick extension",
30+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-imagick"
31+
},
32+
{
33+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\"]'), matrix.php.attr) }}",
34+
"name": "Build MySQL extension",
35+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-mysql"
36+
},
37+
{
38+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
39+
"name": "Validate php.extensions.mysqli default unix socket path",
40+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-mysqli-socket-path"
41+
},
42+
{
43+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
44+
"name": "Validate php.extensions.pdo_mysql default unix socket path",
45+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-pdo_mysql-socket-path"
46+
},
47+
{
48+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
49+
"name": "Build PHP",
50+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-php"
51+
},
52+
{
53+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
54+
"name": "Build Redis extension",
55+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-redis"
56+
},
57+
{
58+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\"]'), matrix.php.attr) }}",
59+
"name": "Build Redis 3 extension",
60+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-redis3"
61+
},
62+
{
63+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
64+
"name": "Build Tidy extension",
65+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-tidy"
66+
},
67+
{
68+
"if": "${{ contains(fromJSON('[\"aarch64-darwin\",\"aarch64-linux\",\"i686-linux\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\"]'), matrix.php.attr) }}",
69+
"name": "Build Xdebug extension",
70+
"run": "nix-build -A outputs.checks.${{ matrix.os.platform }}.${{ matrix.php.attr }}-xdebug"
71+
}
72+
],
73+
"strategy": {
74+
"fail-fast": false,
75+
"matrix": {
76+
"os": [
77+
{
78+
"image": "ubuntu-20.04",
79+
"platform": "x86_64-linux"
80+
}
81+
],
82+
"php": [
83+
{
84+
"attr": "php56",
85+
"branch": "5.6"
86+
},
87+
{
88+
"attr": "php70",
89+
"branch": "7.0"
90+
},
91+
{
92+
"attr": "php71",
93+
"branch": "7.1"
94+
},
95+
{
96+
"attr": "php72",
97+
"branch": "7.2"
98+
},
99+
{
100+
"attr": "php73",
101+
"branch": "7.3"
102+
},
103+
{
104+
"attr": "php74",
105+
"branch": "7.4"
106+
},
107+
{
108+
"attr": "php80",
109+
"branch": "8.0"
110+
},
111+
{
112+
"attr": "php81",
113+
"branch": "8.1"
114+
}
115+
]
116+
}
117+
}
118+
}
119+
},
120+
"name": "Test",
121+
"on": {
122+
"workflow_call": {
123+
"secrets": {
124+
"CACHIX_AUTH_TOKEN": {
125+
"required": true
126+
}
127+
}
128+
}
129+
}
130+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Runs Nix flake checks individually with group markers for GitHub Actions.
2+
# Invoke with `nix-shell workflow-from-flake-checks.nix`
3+
4+
let
5+
self = import ../..;
6+
7+
pkgs = self.inputs.nixpkgs.legacyPackages.${builtins.currentSystem};
8+
inherit (self.inputs.nixpkgs) lib;
9+
10+
checkAttrs =
11+
lib.foldl'
12+
(
13+
acc:
14+
{
15+
name,
16+
value,
17+
}:
18+
19+
acc // {
20+
"${name}" = {
21+
inherit (value) description;
22+
platforms = acc.${name}.platforms or {} // { "${value.platform}" = null; };
23+
phps = acc.${name}.phps or {} // { "${value.php}" = null; };
24+
};
25+
}
26+
)
27+
{}
28+
(
29+
builtins.concatLists (
30+
lib.mapAttrsToList
31+
(
32+
platform:
33+
checks:
34+
35+
lib.mapAttrsToList
36+
(
37+
attr:
38+
check:
39+
40+
let
41+
match = builtins.match "(php[0-9]+)-(.+)" attr;
42+
in
43+
{
44+
name = builtins.head (builtins.tail match);
45+
value = {
46+
inherit (check) description;
47+
inherit platform;
48+
php = builtins.head match;
49+
};
50+
}
51+
)
52+
checks
53+
)
54+
self.outputs.checks
55+
)
56+
);
57+
58+
packages = self.outputs.packages.${builtins.currentSystem};
59+
phpPackages = builtins.filter (name: builtins.match "php[0-9]+" name != null) (builtins.attrNames packages);
60+
61+
workflow = {
62+
name = "Test";
63+
64+
on = {
65+
workflow_call = {
66+
secrets = {
67+
CACHIX_AUTH_TOKEN = {
68+
required = true;
69+
};
70+
};
71+
};
72+
};
73+
74+
jobs = {
75+
test = {
76+
name = "PHP \${{ matrix.php.branch }}";
77+
runs-on = "\${{ matrix.os.image }}";
78+
steps = [
79+
{
80+
uses = "actions/checkout@v2";
81+
}
82+
{
83+
name = "Install Nix";
84+
uses = "cachix/install-nix-action@v14";
85+
}
86+
{
87+
name = "Set up Nix cache";
88+
uses = "cachix/cachix-action@v10";
89+
"with" = {
90+
authToken = "\${{ secrets.CACHIX_AUTH_TOKEN }}";
91+
name = "fossar";
92+
};
93+
}
94+
]
95+
++ lib.mapAttrsToList
96+
(
97+
attr:
98+
check:
99+
100+
{
101+
name = check.description;
102+
"if" = "\${{ contains(fromJSON('${lib.escape [ "\\" "'" ] (builtins.toJSON (builtins.attrNames check.platforms))}'), matrix.os.platform) && contains(fromJSON('${lib.escape [ "\\" "'" ] (builtins.toJSON (builtins.attrNames check.phps))}'), matrix.php.attr) }}";
103+
run = "nix-build -A outputs.checks.\${{ matrix.os.platform }}.\${{ matrix.php.attr }}-${attr}";
104+
}
105+
)
106+
checkAttrs
107+
;
108+
strategy = {
109+
# We want to fix failures individually.
110+
fail-fast = false;
111+
matrix = {
112+
os = [
113+
{
114+
image = "ubuntu-20.04";
115+
platform = "x86_64-linux";
116+
}
117+
];
118+
php =
119+
builtins.map
120+
(
121+
phpAttr:
122+
123+
{
124+
branch = lib.versions.majorMinor packages.${phpAttr}.version;
125+
attr = phpAttr;
126+
}
127+
)
128+
phpPackages;
129+
};
130+
};
131+
};
132+
};
133+
};
134+
in
135+
136+
pkgs.stdenv.mkDerivation {
137+
name = "workflow-from-flake-checks";
138+
139+
buildCommand = ''
140+
echo 'Please run `nix-shell workflow-from-flake-checks.nix`, `nix-build` cannot be used.' > /dev/stderr
141+
exit 1
142+
'';
143+
144+
shellHook =
145+
''
146+
set -o errexit
147+
echo ${lib.escapeShellArgs [ (builtins.toJSON workflow) ]} | ${pkgs.jq}/bin/jq . > .github/workflows/test.yaml
148+
exit 0
149+
''
150+
;
151+
}

run-flake-checks.nix

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)