Skip to content

Commit 1b245c7

Browse files
jtojnardrupol
authored andcommitted
ci: Auto-determine checks to run
This will allow us to support multiple platforms easily.
1 parent 9c82c8a commit 1b245c7

File tree

4 files changed

+296
-64
lines changed

4 files changed

+296
-64
lines changed

.github/workflows/build.yaml

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,19 @@ on:
77
pull_request:
88

99
jobs:
10-
build:
11-
name: 'PHP ${{ matrix.php.branch }}'
10+
prepare-ci:
11+
name: 'Prepare actions'
1212
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
php:
16-
- branch: '8.2'
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
2713
steps:
2814
- uses: actions/checkout@v3
2915

3016
- name: Install Nix
3117
uses: cachix/install-nix-action@v18
3218

33-
- name: Set up Nix cache
34-
uses: cachix/cachix-action@v12
35-
with:
36-
name: fossar
37-
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
38-
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 "major=$major" >> $GITHUB_OUTPUT
47-
echo "attr=$attr" >> $GITHUB_OUTPUT
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
19+
- name: Generate actions
20+
run: nix-shell .github/workflows/workflow-from-flake-checks.nix
21+
test:
22+
needs:
23+
- prepare-ci
24+
uses: ./.github/workflows/test.yaml
25+
secrets: inherit

.github/workflows/test.yaml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"jobs": {
3+
"test": {
4+
"name": "PHP ${{ matrix.php.branch }}",
5+
"runs-on": "${{ matrix.os.image }}",
6+
"steps": [
7+
{
8+
"uses": "actions/checkout@v3"
9+
},
10+
{
11+
"name": "Install Nix",
12+
"uses": "cachix/install-nix-action@v18"
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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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\",\"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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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\",\"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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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\",\"x86_64-darwin\",\"x86_64-linux\"]'), matrix.os.platform) && contains(fromJSON('[\"php56\",\"php70\",\"php71\",\"php72\",\"php73\",\"php74\",\"php80\",\"php81\",\"php82\"]'), 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-latest",
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+
"attr": "php82",
117+
"branch": "8.2"
118+
}
119+
]
120+
}
121+
}
122+
}
123+
},
124+
"name": "Test",
125+
"on": {
126+
"workflow_call": {
127+
"secrets": {
128+
"CACHIX_AUTH_TOKEN": {
129+
"required": true
130+
}
131+
}
132+
}
133+
}
134+
}
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@v3";
81+
}
82+
{
83+
name = "Install Nix";
84+
uses = "cachix/install-nix-action@v18";
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-latest";
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 .github/workflows/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+
}

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;

0 commit comments

Comments
 (0)