xref: /php-src/.github/nightly_matrix.php (revision e7462bff)
1<?php
2
3const BRANCHES = [
4    ['name' => 'master', 'ref' => 'master', 'version' => ['major' => 8, 'minor' => 4]],
5    ['name' => 'PHP-8.3', 'ref' => 'PHP-8.3', 'version' => ['major' => 8, 'minor' => 3]],
6    ['name' => 'PHP-8.2', 'ref' => 'PHP-8.2', 'version' => ['major' => 8, 'minor' => 2]],
7    ['name' => 'PHP-8.1', 'ref' => 'PHP-8.1', 'version' => ['major' => 8, 'minor' => 1]],
8];
9
10function get_branch_commit_cache_file_path(): string {
11    return dirname(__DIR__) . '/branch-commit-cache.json';
12}
13
14function get_branches() {
15    $branch_commit_cache_file = get_branch_commit_cache_file_path();
16    $branch_commit_map = [];
17    if (file_exists($branch_commit_cache_file)) {
18        $branch_commit_map = json_decode(file_get_contents($branch_commit_cache_file), JSON_THROW_ON_ERROR);
19    }
20
21    $changed_branches = [];
22    foreach (BRANCHES as $branch) {
23        $previous_commit_hash = $branch_commit_map[$branch['ref']] ?? null;
24        $current_commit_hash = trim(shell_exec('git rev-parse origin/' . $branch['ref']));
25
26        if ($previous_commit_hash !== $current_commit_hash) {
27            $changed_branches[] = $branch;
28        }
29
30        $branch_commit_map[$branch['ref']] = $current_commit_hash;
31    }
32
33    file_put_contents($branch_commit_cache_file, json_encode($branch_commit_map));
34
35    return $changed_branches;
36}
37
38function get_matrix_include(array $branches) {
39    $jobs = [];
40    foreach ($branches as $branch) {
41        $jobs[] = [
42            'name' => '_ASAN_UBSAN',
43            'branch' => $branch,
44            'debug' => true,
45            'zts' => true,
46            'configuration_parameters' => "CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC' LDFLAGS='-fsanitize=undefined,address'",
47            'run_tests_parameters' => '--asan',
48            'test_function_jit' => false,
49            'asan' => true,
50        ];
51        $jobs[] = [
52            'name' => '_REPEAT',
53            'branch' => $branch,
54            'debug' => true,
55            'zts' => false,
56            'run_tests_parameters' => '--repeat 2',
57            'timeout_minutes' => 360,
58            'test_function_jit' => true,
59            'asan' => false,
60        ];
61        $jobs[] = [
62            'name' => '_VARIATION',
63            'branch' => $branch,
64            'debug' => true,
65            'zts' => true,
66            'configuration_parameters' => "CFLAGS='-DZEND_RC_DEBUG=1 -DPROFITABILITY_CHECKS=0 -DZEND_VERIFY_FUNC_INFO=1 -DZEND_VERIFY_TYPE_INFERENCE'",
67                'run_tests_parameters' => '-d zend_test.observer.enabled=1 -d zend_test.observer.show_output=0',
68            'timeout_minutes' => 360,
69            'test_function_jit' => true,
70            'asan' => false,
71        ];
72    }
73    return $jobs;
74}
75
76function get_windows_matrix_include(array $branches) {
77    $jobs = [];
78    foreach ($branches as $branch) {
79        $jobs[] = [
80            'branch' => $branch,
81            'x64' => true,
82            'zts' => true,
83            'opcache' => true,
84        ];
85        $jobs[] = [
86            'branch' => $branch,
87            'x64' => false,
88            'zts' => false,
89            'opcache' => false,
90        ];
91    }
92    return $jobs;
93}
94
95function get_macos_matrix_include(array $branches) {
96    $jobs = [];
97    foreach ($branches as $branch) {
98        foreach([true, false] as $debug) {
99            foreach([true, false] as $zts) {
100                $jobs[] = [
101                    'branch' => $branch,
102                    'debug' => $debug,
103                    'zts' => $zts,
104                    'os' => $branch['name'] === 'master' ? '13' : '12',
105                    'arch' => 'X64',
106                    'test_jit' => true,
107                ];
108                if ($branch['version']['minor'] >= 4 || $branch['version']['major'] >= 9) {
109                    $jobs[] = [
110                        'branch' => $branch,
111                        'debug' => $debug,
112                        'zts' => $zts,
113                        'os' => '14',
114                        'arch' => 'ARM64',
115                        'test_jit' => !$zts,
116                    ];
117                }
118            }
119        }
120    }
121    return $jobs;
122}
123
124function get_current_version(): array {
125    $file = dirname(__DIR__) . '/main/php_version.h';
126    $content = file_get_contents($file);
127    preg_match('(^#define PHP_MAJOR_VERSION (?<num>\d+)$)m', $content, $matches);
128    $major = $matches['num'];
129    preg_match('(^#define PHP_MINOR_VERSION (?<num>\d+)$)m', $content, $matches);
130    $minor = $matches['num'];
131    return ['major' => $major, 'minor' => $minor];
132}
133
134$trigger = $argv[1] ?? 'schedule';
135$attempt = (int) ($argv[2] ?? 1);
136$discard_cache = ($trigger === 'schedule' && $attempt !== 1) || $trigger === 'workflow_dispatch';
137if ($discard_cache) {
138    @unlink(get_branch_commit_cache_file_path());
139}
140$branch = $argv[3] ?? 'master';
141
142$branches = $branch === 'master'
143    ? get_branches()
144    : [['name' => strtoupper($branch), 'ref' => $branch, 'version' => get_current_version()]];
145$matrix_include = get_matrix_include($branches);
146$windows_matrix_include = get_windows_matrix_include($branches);
147$macos_matrix_include = get_macos_matrix_include($branches);
148
149$f = fopen(getenv('GITHUB_OUTPUT'), 'a');
150fwrite($f, 'branches=' . json_encode($branches, JSON_UNESCAPED_SLASHES) . "\n");
151fwrite($f, 'matrix-include=' . json_encode($matrix_include, JSON_UNESCAPED_SLASHES) . "\n");
152fwrite($f, 'windows-matrix-include=' . json_encode($windows_matrix_include, JSON_UNESCAPED_SLASHES) . "\n");
153fwrite($f, 'macos-matrix-include=' . json_encode($macos_matrix_include, JSON_UNESCAPED_SLASHES) . "\n");
154fclose($f);
155