xref: /PHP-8.1/.github/nightly_matrix.php (revision 902d39d5)
1<?php
2
3const BRANCHES = ['master', 'PHP-8.1', 'PHP-8.0'];
4
5function get_branch_commit_cache_file_path(): string {
6    return dirname(__DIR__) . '/branch-commit-cache.json';
7}
8
9function get_branch_matrix(array $branches) {
10    $result = array_map(function ($branch) {
11        $branch_key = strtoupper(str_replace('.', '', $branch));
12        return [
13            'name' => $branch_key,
14            'ref' => $branch,
15        ];
16    }, $branches);
17
18    return $result;
19}
20
21function get_branches() {
22    $branch_commit_cache_file = get_branch_commit_cache_file_path();
23    $branch_commit_map = [];
24    if (file_exists($branch_commit_cache_file)) {
25        $branch_commit_map = json_decode(file_get_contents($branch_commit_cache_file), JSON_THROW_ON_ERROR);
26    }
27
28    $changed_branches = [];
29    foreach (BRANCHES as $branch) {
30        $previous_commit_hash = $branch_commit_map[$branch] ?? null;
31        $current_commit_hash = trim(shell_exec('git rev-parse origin/' . $branch));
32
33        if ($previous_commit_hash !== $current_commit_hash) {
34            $changed_branches[] = $branch;
35        }
36
37        $branch_commit_map[$branch] = $current_commit_hash;
38    }
39
40    file_put_contents($branch_commit_cache_file, json_encode($branch_commit_map));
41
42    return get_branch_matrix($changed_branches);
43}
44
45function get_matrix_include(array $branches) {
46    $jobs = [];
47    foreach ($branches as $branch) {
48        $jobs[] = [
49            'name' => '_ASAN_UBSAN',
50            'branch' => $branch,
51            'debug' => true,
52            'zts' => true,
53            'configuration_parameters' => "CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC' LDFLAGS='-fsanitize=undefined,address'",
54            'run_tests_parameters' => '--asan',
55            'test_function_jit' => false,
56        ];
57        if ($branch['ref'] !== 'PHP-8.0') {
58            $jobs[] = [
59                'name' => '_REPEAT',
60                'branch' => $branch,
61                'debug' => true,
62                'zts' => false,
63                'run_tests_parameters' => '--repeat 2',
64                'timeout_minutes' => 360,
65                'test_function_jit' => true,
66            ];
67            $jobs[] = [
68                'name' => '_VARIATION',
69                'branch' => $branch,
70                'debug' => true,
71                'zts' => true,
72                'configuration_parameters' => "CFLAGS='-DZEND_RC_DEBUG=1 -DPROFITABILITY_CHECKS=0 -DZEND_VERIFY_FUNC_INFO=1'",
73                'timeout_minutes' => 360,
74                'test_function_jit' => true,
75            ];
76        }
77    }
78    return $jobs;
79}
80
81function get_windows_matrix_include(array $branches) {
82    $jobs = [];
83    foreach ($branches as $branch) {
84        $jobs[] = [
85            'branch' => $branch,
86            'x64' => true,
87            'zts' => true,
88            'opcache' => true,
89        ];
90        $jobs[] = [
91            'branch' => $branch,
92            'x64' => false,
93            'zts' => false,
94            'opcache' => false,
95        ];
96    }
97    return $jobs;
98}
99
100$trigger = $argv[1] ?? 'schedule';
101$attempt = (int) ($argv[2] ?? 1);
102$discard_cache = ($trigger === 'schedule' && $attempt !== 1) || $trigger === 'workflow_dispatch';
103if ($discard_cache) {
104    @unlink(get_branch_commit_cache_file_path());
105}
106
107$branches = get_branches();
108$matrix_include = get_matrix_include($branches);
109$windows_matrix_include = get_windows_matrix_include($branches);
110
111echo '::set-output name=branches::' . json_encode($branches, JSON_UNESCAPED_SLASHES) . "\n";
112echo '::set-output name=matrix-include::' . json_encode($matrix_include, JSON_UNESCAPED_SLASHES) . "\n";
113echo '::set-output name=windows-matrix-include::' . json_encode($windows_matrix_include, JSON_UNESCAPED_SLASHES) . "\n";
114