1
1
<?php
2
2
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
+ ];
4
10
5
11
function get_branch_commit_cache_file_path (): string {
6
12
return dirname (__DIR__ ) . '/branch-commit-cache.json ' ;
7
13
}
8
14
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
-
21
15
function get_branches () {
22
16
$ branch_commit_cache_file = get_branch_commit_cache_file_path ();
23
17
$ branch_commit_map = [];
@@ -27,19 +21,19 @@ function get_branches() {
27
21
28
22
$ changed_branches = [];
29
23
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 ' ] ));
32
26
33
27
if ($ previous_commit_hash !== $ current_commit_hash ) {
34
28
$ changed_branches [] = $ branch ;
35
29
}
36
30
37
- $ branch_commit_map [$ branch ] = $ current_commit_hash ;
31
+ $ branch_commit_map [$ branch[ ' ref ' ] ] = $ current_commit_hash ;
38
32
}
39
33
40
34
file_put_contents ($ branch_commit_cache_file , json_encode ($ branch_commit_map ));
41
35
42
- return get_branch_matrix ( $ changed_branches) ;
36
+ return $ changed_branches ;
43
37
}
44
38
45
39
function get_matrix_include (array $ branches ) {
@@ -100,7 +94,7 @@ function get_windows_matrix_include(array $branches) {
100
94
return $ jobs ;
101
95
}
102
96
103
- function get_version (): array {
97
+ function get_current_version (): array {
104
98
$ file = dirname (__DIR__ ) . '/main/php_version.h ' ;
105
99
$ content = file_get_contents ($ file );
106
100
preg_match ('(^#define PHP_MAJOR_VERSION (?<num>\d+)$)m ' , $ content , $ matches );
@@ -118,13 +112,14 @@ function get_version(): array {
118
112
}
119
113
$ branch = $ argv [3 ] ?? 'master ' ;
120
114
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 ()]];
122
118
$ matrix_include = get_matrix_include ($ branches );
123
119
$ windows_matrix_include = get_windows_matrix_include ($ branches );
124
120
125
121
$ f = fopen (getenv ('GITHUB_OUTPUT ' ), 'a ' );
126
122
fwrite ($ f , 'branches= ' . json_encode ($ branches , JSON_UNESCAPED_SLASHES ) . "\n" );
127
123
fwrite ($ f , 'matrix-include= ' . json_encode ($ matrix_include , JSON_UNESCAPED_SLASHES ) . "\n" );
128
124
fwrite ($ 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" );
130
125
fclose ($ f );
0 commit comments