11<?php
22
3- const BRANCHES = ['master ' , 'PHP-8.2 ' , 'PHP-8.1 ' , 'PHP-8.0 ' ];
3+ const BRANCHES = [
4+ ['ref ' => 'master ' , 'version ' => [8 , 5 ]],
5+ ['ref ' => 'PHP-8.4 ' , 'version ' => [8 , 4 ]],
6+ ['ref ' => 'PHP-8.3 ' , 'version ' => [8 , 3 ]],
7+ ['ref ' => 'PHP-8.2 ' , 'version ' => [8 , 2 ]],
8+ ['ref ' => 'PHP-8.1 ' , 'version ' => [8 , 1 ]],
9+ ];
410
511function get_branch_commit_cache_file_path (): string {
612 return dirname (__DIR__ ) . '/branch-commit-cache.json ' ;
713}
814
9- function 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-
2115function get_branches () {
2216 $ branch_commit_cache_file = get_branch_commit_cache_file_path ();
2317 $ branch_commit_map = [];
@@ -27,88 +21,45 @@ function get_branches() {
2721
2822 $ changed_branches = [];
2923 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 ));
24+ $ previous_commit_hash = $ branch_commit_map [$ branch[ ' ref ' ] ] ?? null ;
25+ $ current_commit_hash = trim (shell_exec ('git rev-parse origin/ ' . $ branch[ ' ref ' ] ));
3226
3327 if ($ previous_commit_hash !== $ current_commit_hash ) {
3428 $ changed_branches [] = $ branch ;
3529 }
3630
37- $ branch_commit_map [$ branch ] = $ current_commit_hash ;
31+ $ branch_commit_map [$ branch[ ' ref ' ] ] = $ current_commit_hash ;
3832 }
3933
4034 file_put_contents ($ branch_commit_cache_file , json_encode ($ branch_commit_map ));
4135
42- return get_branch_matrix ( $ changed_branches) ;
36+ return $ changed_branches ;
4337}
4438
45- function 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- 'run_tests_parameters ' => '-d zend_test.observer.enabled=1 -d zend_test.observer.show_output=0 ' ,
74- 'timeout_minutes ' => 360 ,
75- 'test_function_jit ' => true ,
76- ];
77- }
78- }
79- return $ jobs ;
80- }
81-
82- function get_windows_matrix_include (array $ branches ) {
83- $ jobs = [];
84- foreach ($ branches as $ branch ) {
85- $ jobs [] = [
86- 'branch ' => $ branch ,
87- 'x64 ' => true ,
88- 'zts ' => true ,
89- 'opcache ' => true ,
90- ];
91- $ jobs [] = [
92- 'branch ' => $ branch ,
93- 'x64 ' => false ,
94- 'zts ' => false ,
95- 'opcache ' => false ,
96- ];
97- }
98- return $ jobs ;
39+ function get_current_version (): array {
40+ $ file = dirname (__DIR__ ) . '/main/php_version.h ' ;
41+ $ content = file_get_contents ($ file );
42+ preg_match ('(^#define PHP_MAJOR_VERSION (?<num>\d+)$)m ' , $ content , $ matches );
43+ $ major = (int ) $ matches ['num ' ];
44+ preg_match ('(^#define PHP_MINOR_VERSION (?<num>\d+)$)m ' , $ content , $ matches );
45+ $ minor = (int ) $ matches ['num ' ];
46+ return [$ major , $ minor ];
9947}
10048
10149$ trigger = $ argv [1 ] ?? 'schedule ' ;
10250$ attempt = (int ) ($ argv [2 ] ?? 1 );
103- $ discard_cache = ($ trigger === 'schedule ' && $ attempt !== 1 ) || $ trigger === 'workflow_dispatch ' ;
51+ $ monday = date ('w ' , time ()) === '1 ' ;
52+ $ discard_cache = $ monday
53+ || ($ trigger === 'schedule ' && $ attempt !== 1 )
54+ || $ trigger === 'workflow_dispatch ' ;
10455if ($ discard_cache ) {
10556 @unlink (get_branch_commit_cache_file_path ());
10657}
58+ $ branch = $ argv [3 ] ?? 'master ' ;
59+ $ branches = $ branch === 'master '
60+ ? get_branches ()
61+ : [['ref ' => $ branch , 'version ' => get_current_version ()]];
10762
108- $ branches = get_branches ();
109- $ matrix_include = get_matrix_include ($ branches );
110- $ windows_matrix_include = get_windows_matrix_include ($ branches );
111-
112- echo '::set-output name=branches:: ' . json_encode ($ branches , JSON_UNESCAPED_SLASHES ) . "\n" ;
113- echo '::set-output name=matrix-include:: ' . json_encode ($ matrix_include , JSON_UNESCAPED_SLASHES ) . "\n" ;
114- echo '::set-output name=windows-matrix-include:: ' . json_encode ($ windows_matrix_include , JSON_UNESCAPED_SLASHES ) . "\n" ;
63+ $ f = fopen (getenv ('GITHUB_OUTPUT ' ), 'a ' );
64+ fwrite ($ f , 'branches= ' . json_encode ($ branches , JSON_UNESCAPED_SLASHES ) . "\n" );
65+ fclose ($ f );
0 commit comments