PruneTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * This file allows for tests to be skipped.
  4. * For now conditions are simple.
  5. * We check if changes in the source with respect to the configured branch are limited to framework files,
  6. * if that is the case and the current framework isn't one with changed files then we skip it.
  7. */
  8. $branch ="2.4";
  9. function stderr($message)
  10. {
  11. fwrite(STDERR, $message . "\n");
  12. }
  13. $currentFramework = getenv('FRAMEWORK');
  14. if ($currentFramework === 'Codeception') {
  15. stderr('Codeception tests are always executed');
  16. die();
  17. }
  18. $files = [];
  19. exec("git diff --name-only $branch", $files);
  20. // Regexes for frameworks:
  21. $regexes = [
  22. 'Yii2' => '/.*Yii2.*/',
  23. 'Lumen' => '/.*(Lumen|LaravelCommon).*/',
  24. 'Laravel' => '/.*Laravel.*/',
  25. 'Phalcon' => '/.*Phalcon.*/',
  26. 'Symfony' => '/.*Symfony.*/',
  27. 'Yii1' => '/.*Yii1.*/',
  28. 'ZendExpressive' => '/.*ZendExpressive.*/',
  29. 'Zend1' => '/.*ZF1.*/',
  30. 'Zend2' => '/.*ZF2.*/',
  31. ];
  32. // First check if changes include files that are not framework files.
  33. $frameworkOnly = true;
  34. $frameworks = [];
  35. foreach ($files as $file) {
  36. $match = false;
  37. foreach ($regexes as $framework => $regex) {
  38. if (preg_match($regex, $file)) {
  39. $match = true;
  40. $frameworks[$framework] = $framework;
  41. break;
  42. }
  43. }
  44. if (!$match) {
  45. $frameworkOnly = false;
  46. break;
  47. }
  48. }
  49. if ($frameworkOnly) {
  50. stderr('Changes limited to frameworks: ' . implode(', ', $frameworks));
  51. if (!isset($frameworks[$currentFramework])) {
  52. stderr("Skipping test for framework: $currentFramework");
  53. echo "export FRAMEWORK=\n";
  54. echo "export PECL=\n";
  55. echo "export FXP=\n";
  56. echo "export CI_USER_TOKEN=\n";
  57. }
  58. }