11<?php
22
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+ ];
410
511function get_branch_commit_cache_file_path (): string {
612 return dirname (__DIR__ ) . '/branch-commit-cache.json ' ;
@@ -15,21 +21,31 @@ function get_branches() {
1521
1622 $ changed_branches = [];
1723 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 ' ] ));
2026
2127 if ($ previous_commit_hash !== $ current_commit_hash ) {
2228 $ changed_branches [] = $ branch ;
2329 }
2430
25- $ branch_commit_map [$ branch ] = $ current_commit_hash ;
31+ $ branch_commit_map [$ branch[ ' ref ' ] ] = $ current_commit_hash ;
2632 }
2733
2834 file_put_contents ($ branch_commit_cache_file , json_encode ($ branch_commit_map ));
2935
3036 return $ changed_branches ;
3137}
3238
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+
3349$ trigger = $ argv [1 ] ?? 'schedule ' ;
3450$ attempt = (int ) ($ argv [2 ] ?? 1 );
3551$ monday = date ('w ' , time ()) === '1 ' ;
@@ -40,7 +56,9 @@ function get_branches() {
4056 @unlink (get_branch_commit_cache_file_path ());
4157}
4258$ 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 ()]];
4462
4563$ f = fopen (getenv ('GITHUB_OUTPUT ' ), 'a ' );
4664fwrite ($ f , 'branches= ' . json_encode ($ branches , JSON_UNESCAPED_SLASHES ) . "\n" );
0 commit comments