Skip to content

Commit

Permalink
Merge branch 'PHP-8.2' into PHP-8.3
Browse files Browse the repository at this point in the history
* PHP-8.2:
  Backport nightly.yml and nightly_matrix.php to PHP-8.1
  • Loading branch information
iluuu1994 committed Oct 29, 2024
2 parents e039aff + 9ad99bb commit fe93cd4
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 115 deletions.
143 changes: 102 additions & 41 deletions .github/nightly_matrix.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
<?php

const BRANCHES = ['master', 'PHP-8.3', 'PHP-8.2', 'PHP-8.1', 'PHP-8.0'];
const BRANCHES = [
['name' => 'master', 'ref' => 'master', 'version' => ['major' => 8, 'minor' => 5]],
['name' => 'PHP-8.4', 'ref' => 'PHP-8.4', 'version' => ['major' => 8, 'minor' => 4]],
['name' => 'PHP-8.3', 'ref' => 'PHP-8.3', 'version' => ['major' => 8, 'minor' => 3]],
['name' => 'PHP-8.2', 'ref' => 'PHP-8.2', 'version' => ['major' => 8, 'minor' => 2]],
['name' => 'PHP-8.1', 'ref' => 'PHP-8.1', 'version' => ['major' => 8, 'minor' => 1]],
];

function get_branch_commit_cache_file_path(): string {
return dirname(__DIR__) . '/branch-commit-cache.json';
}

function get_branch_matrix(array $branches) {
$result = array_map(function ($branch) {
$branch_key = strtoupper(str_replace('.', '', $branch));
return [
'name' => $branch_key,
'ref' => $branch,
];
}, $branches);

return $result;
}

function get_branches() {
$branch_commit_cache_file = get_branch_commit_cache_file_path();
$branch_commit_map = [];
Expand All @@ -27,19 +21,19 @@ function get_branches() {

$changed_branches = [];
foreach (BRANCHES as $branch) {
$previous_commit_hash = $branch_commit_map[$branch] ?? null;
$current_commit_hash = trim(shell_exec('git rev-parse origin/' . $branch));
$previous_commit_hash = $branch_commit_map[$branch['ref']] ?? null;
$current_commit_hash = trim(shell_exec('git rev-parse origin/' . $branch['ref']));

if ($previous_commit_hash !== $current_commit_hash) {
$changed_branches[] = $branch;
}

$branch_commit_map[$branch] = $current_commit_hash;
$branch_commit_map[$branch['ref']] = $current_commit_hash;
}

file_put_contents($branch_commit_cache_file, json_encode($branch_commit_map));

return get_branch_matrix($changed_branches);
return $changed_branches;
}

function get_matrix_include(array $branches) {
Expand All @@ -55,29 +49,27 @@ function get_matrix_include(array $branches) {
'test_function_jit' => false,
'asan' => true,
];
if ($branch['ref'] !== 'PHP-8.0') {
$jobs[] = [
'name' => '_REPEAT',
'branch' => $branch,
'debug' => true,
'zts' => false,
'run_tests_parameters' => '--repeat 2',
'timeout_minutes' => 360,
'test_function_jit' => true,
'asan' => false,
];
$jobs[] = [
'name' => '_VARIATION',
'branch' => $branch,
'debug' => true,
'zts' => true,
'configuration_parameters' => "CFLAGS='-DZEND_RC_DEBUG=1 -DPROFITABILITY_CHECKS=0 -DZEND_VERIFY_FUNC_INFO=1'",
$jobs[] = [
'name' => '_REPEAT',
'branch' => $branch,
'debug' => true,
'zts' => false,
'run_tests_parameters' => '--repeat 2',
'timeout_minutes' => 360,
'test_function_jit' => true,
'asan' => false,
];
$jobs[] = [
'name' => '_VARIATION',
'branch' => $branch,
'debug' => true,
'zts' => true,
'configuration_parameters' => "CFLAGS='-DZEND_RC_DEBUG=1 -DPROFITABILITY_CHECKS=0 -DZEND_VERIFY_FUNC_INFO=1 -DZEND_VERIFY_TYPE_INFERENCE'",
'run_tests_parameters' => '-d zend_test.observer.enabled=1 -d zend_test.observer.show_output=0',
'timeout_minutes' => 360,
'test_function_jit' => true,
'asan' => false,
];
}
'timeout_minutes' => 360,
'test_function_jit' => true,
'asan' => false,
];
}
return $jobs;
}
Expand All @@ -101,19 +93,88 @@ function get_windows_matrix_include(array $branches) {
return $jobs;
}

function get_macos_matrix_include(array $branches) {
$jobs = [];
foreach ($branches as $branch) {
foreach([true, false] as $debug) {
foreach([true, false] as $zts) {
$jobs[] = [
'branch' => $branch,
'debug' => $debug,
'zts' => $zts,
'os' => '13',
'arch' => 'X64',
'test_jit' => true,
];
if ($branch['version']['minor'] >= 4 || $branch['version']['major'] >= 9) {
$jobs[] = [
'branch' => $branch,
'debug' => $debug,
'zts' => $zts,
'os' => '14',
'arch' => 'ARM64',
'test_jit' => !$zts,
];
}
}
}
}
return $jobs;
}

function get_alpine_matrix_include(array $branches) {
$jobs = [];
foreach ($branches as $branch) {
if ([$branch['version']['major'], $branch['version']['minor']] < [8, 4]) {
continue;
}
$jobs[] = [
'name' => '_ASAN_UBSAN',
'branch' => $branch,
'debug' => true,
'zts' => true,
'asan' => true,
'test_jit' => true,
'configuration_parameters' => "CFLAGS='-fsanitize=undefined,address -fno-sanitize=function -DZEND_TRACK_ARENA_ALLOC' LDFLAGS='-fsanitize=undefined,address -fno-sanitize=function' CC=clang-17 CXX=clang++-17",
'run_tests_parameters' => '--asan -x',
];
}
return $jobs;
}

function get_current_version(): array {
$file = dirname(__DIR__) . '/main/php_version.h';
$content = file_get_contents($file);
preg_match('(^#define PHP_MAJOR_VERSION (?<num>\d+)$)m', $content, $matches);
$major = $matches['num'];
preg_match('(^#define PHP_MINOR_VERSION (?<num>\d+)$)m', $content, $matches);
$minor = $matches['num'];
return ['major' => $major, 'minor' => $minor];
}

$trigger = $argv[1] ?? 'schedule';
$attempt = (int) ($argv[2] ?? 1);
$discard_cache = ($trigger === 'schedule' && $attempt !== 1) || $trigger === 'workflow_dispatch';
$monday = date('w', time()) === '1';
$discard_cache = $monday
|| ($trigger === 'schedule' && $attempt !== 1)
|| $trigger === 'workflow_dispatch';
if ($discard_cache) {
@unlink(get_branch_commit_cache_file_path());
}
$branch = $argv[3] ?? 'master';

$branches = get_branches();
$branches = $branch === 'master'
? get_branches()
: [['name' => strtoupper($branch), 'ref' => $branch, 'version' => get_current_version()]];
$matrix_include = get_matrix_include($branches);
$windows_matrix_include = get_windows_matrix_include($branches);
$macos_matrix_include = get_macos_matrix_include($branches);
$alpine_matrix_include = get_alpine_matrix_include($branches);

$f = fopen(getenv('GITHUB_OUTPUT'), 'a');
fwrite($f, 'branches=' . json_encode($branches, JSON_UNESCAPED_SLASHES) . "\n");
fwrite($f, 'matrix-include=' . json_encode($matrix_include, JSON_UNESCAPED_SLASHES) . "\n");
fwrite($f, 'windows-matrix-include=' . json_encode($windows_matrix_include, JSON_UNESCAPED_SLASHES) . "\n");
fwrite($f, 'macos-matrix-include=' . json_encode($macos_matrix_include, JSON_UNESCAPED_SLASHES) . "\n");
fwrite($f, 'alpine-matrix-include=' . json_encode($alpine_matrix_include, JSON_UNESCAPED_SLASHES) . "\n");
fclose($f);
Loading

0 comments on commit fe93cd4

Please sign in to comment.