1
1
<?php
2
2
3
- const BRANCHES = ['master ' , 'PHP-8.4 ' , 'PHP-8.3 ' , 'PHP-8.2 ' , 'PHP-8.1 ' ];
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
+ ];
4
10
5
11
function get_branch_commit_cache_file_path (): string {
6
12
return dirname (__DIR__ ) . '/branch-commit-cache.json ' ;
@@ -15,21 +21,31 @@ function get_branches() {
15
21
16
22
$ changed_branches = [];
17
23
foreach (BRANCHES as $ branch ) {
18
- $ previous_commit_hash = $ branch_commit_map [$ branch ] ?? null ;
19
- $ 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 ' ] ));
20
26
21
27
if ($ previous_commit_hash !== $ current_commit_hash ) {
22
28
$ changed_branches [] = $ branch ;
23
29
}
24
30
25
- $ branch_commit_map [$ branch ] = $ current_commit_hash ;
31
+ $ branch_commit_map [$ branch[ ' ref ' ] ] = $ current_commit_hash ;
26
32
}
27
33
28
34
file_put_contents ($ branch_commit_cache_file , json_encode ($ branch_commit_map ));
29
35
30
36
return $ changed_branches ;
31
37
}
32
38
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 ];
47
+ }
48
+
33
49
$ trigger = $ argv [1 ] ?? 'schedule ' ;
34
50
$ attempt = (int ) ($ argv [2 ] ?? 1 );
35
51
$ monday = date ('w ' , time ()) === '1 ' ;
@@ -40,7 +56,9 @@ function get_branches() {
40
56
@unlink (get_branch_commit_cache_file_path ());
41
57
}
42
58
$ branch = $ argv [3 ] ?? 'master ' ;
43
- $ branches = $ branch === 'master ' ? get_branches () : [$ branch ];
59
+ $ branches = $ branch === 'master '
60
+ ? get_branches ()
61
+ : [['ref ' => $ branch , 'version ' => get_current_version ()]];
44
62
45
63
$ f = fopen (getenv ('GITHUB_OUTPUT ' ), 'a ' );
46
64
fwrite ($ f , 'branches= ' . json_encode ($ branches , JSON_UNESCAPED_SLASHES ) . "\n" );
0 commit comments