11<?php
22
3- const BRANCHES = ['master ' , 'PHP-8.3 ' , 'PHP-8.2 ' , 'PHP-8.1 ' , 'PHP-8.0 ' ];
3+ const 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+ ['name ' => 'PHP-8.0 ' , 'ref ' => 'PHP-8.0 ' , 'version ' => ['major ' => 8 , 'minor ' => 0 ]],
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,19 +21,19 @@ 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
4539function get_matrix_include (array $ branches ) {
@@ -100,7 +94,7 @@ function get_windows_matrix_include(array $branches) {
10094 return $ jobs ;
10195}
10296
103- function get_version (): array {
97+ function get_current_version (): array {
10498 $ file = dirname (__DIR__ ) . '/main/php_version.h ' ;
10599 $ content = file_get_contents ($ file );
106100 preg_match ('(^#define PHP_MAJOR_VERSION (?<num>\d+)$)m ' , $ content , $ matches );
@@ -118,13 +112,14 @@ function get_version(): array {
118112}
119113$ branch = $ argv [3 ] ?? 'master ' ;
120114
121- $ branches = $ branch === 'master ' ? get_branches () : get_branch_matrix ([$ branch ]);
115+ $ branches = $ branch === 'master '
116+ ? get_branches ()
117+ : [['name ' => strtoupper ($ branch ), 'ref ' => $ branch , 'version ' => get_current_version ()]];
122118$ matrix_include = get_matrix_include ($ branches );
123119$ windows_matrix_include = get_windows_matrix_include ($ branches );
124120
125121$ f = fopen (getenv ('GITHUB_OUTPUT ' ), 'a ' );
126122fwrite ($ f , 'branches= ' . json_encode ($ branches , JSON_UNESCAPED_SLASHES ) . "\n" );
127123fwrite ($ f , 'matrix-include= ' . json_encode ($ matrix_include , JSON_UNESCAPED_SLASHES ) . "\n" );
128124fwrite ($ f , 'windows-matrix-include= ' . json_encode ($ windows_matrix_include , JSON_UNESCAPED_SLASHES ) . "\n" );
129- fwrite ($ f , 'version= ' . json_encode (get_version (), JSON_UNESCAPED_SLASHES ) . "\n" );
130125fclose ($ f );
0 commit comments