nightly_matrix.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. const BRANCHES = ['master', 'PHP-8.1', 'PHP-8.0'];
  3. function get_branch_commit_cache_file_path(): string {
  4. return dirname(__DIR__) . '/branch-commit-cache.json';
  5. }
  6. function get_branch_matrix(array $branches) {
  7. $result = array_map(function ($branch) {
  8. $branch_key = strtoupper(str_replace('.', '', $branch));
  9. return [
  10. 'name' => $branch_key,
  11. 'ref' => $branch,
  12. ];
  13. }, $branches);
  14. return $result;
  15. }
  16. function get_branches() {
  17. $branch_commit_cache_file = get_branch_commit_cache_file_path();
  18. $branch_commit_map = [];
  19. if (file_exists($branch_commit_cache_file)) {
  20. $branch_commit_map = json_decode(file_get_contents($branch_commit_cache_file), JSON_THROW_ON_ERROR);
  21. }
  22. $changed_branches = [];
  23. foreach (BRANCHES as $branch) {
  24. $previous_commit_hash = $branch_commit_map[$branch] ?? null;
  25. $current_commit_hash = trim(shell_exec('git rev-parse origin/' . $branch));
  26. if ($previous_commit_hash !== $current_commit_hash) {
  27. $changed_branches[] = $branch;
  28. }
  29. $branch_commit_map[$branch] = $current_commit_hash;
  30. }
  31. file_put_contents($branch_commit_cache_file, json_encode($branch_commit_map));
  32. return get_branch_matrix($changed_branches);
  33. }
  34. function get_matrix_include(array $branches) {
  35. $jobs = [];
  36. foreach ($branches as $branch) {
  37. $jobs[] = [
  38. 'name' => '_ASAN_UBSAN',
  39. 'branch' => $branch,
  40. 'debug' => true,
  41. 'zts' => true,
  42. 'configuration_parameters' => "CFLAGS='-fsanitize=undefined,address -DZEND_TRACK_ARENA_ALLOC' LDFLAGS='-fsanitize=undefined,address'",
  43. 'run_tests_parameters' => '--asan',
  44. 'timeout_minutes' => 480,
  45. ];
  46. if ($branch['ref'] !== 'PHP-8.0') {
  47. $jobs[] = [
  48. 'name' => '_REPEAT',
  49. 'branch' => $branch,
  50. 'debug' => true,
  51. 'zts' => false,
  52. 'run_tests_parameters' => '--repeat 2',
  53. 'timeout_minutes' => 360,
  54. ];
  55. $jobs[] = [
  56. 'name' => '_VARIATION',
  57. 'branch' => $branch,
  58. 'debug' => true,
  59. 'zts' => true,
  60. 'configuration_parameters' => "CFLAGS='-DZEND_RC_DEBUG=1 -DPROFITABILITY_CHECKS=0 -DZEND_VERIFY_FUNC_INFO=1'",
  61. 'timeout_minutes' => 360,
  62. ];
  63. }
  64. }
  65. return $jobs;
  66. }
  67. $trigger = $argv[1] ?? 'schedule';
  68. $attempt = (int) ($argv[2] ?? 1);
  69. $discard_cache = ($trigger === 'schedule' && $attempt !== 1) || $trigger === 'workflow_dispatch';
  70. if ($discard_cache) {
  71. @unlink(get_branch_commit_cache_file_path());
  72. }
  73. $branches = get_branches();
  74. $matrix_include = get_matrix_include($branches);
  75. echo '::set-output name=branches::' . json_encode($branches, JSON_UNESCAPED_SLASHES) . "\n";
  76. echo '::set-output name=matrix-include::' . json_encode($matrix_include, JSON_UNESCAPED_SLASHES) . "\n";