build.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * This file is part of the Carbon package.
  4. *
  5. * (c) Brian Nesbitt <brian@nesbot.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. chdir(__DIR__);
  11. $currentBranch = 'master';
  12. if (preg_match('/On branch ([^\n]+)\n/', shell_exec('git status'), $match)) {
  13. $currentBranch = $match[1];
  14. }
  15. shell_exec('git fetch --all --tags --prune');
  16. $remotes = explode("\n", trim(shell_exec('git remote')));
  17. $tagsCommand = \count($remotes)
  18. ? 'git ls-remote --tags '.(\in_array('upstream', $remotes, true) ? 'upstream' : (\in_array('origin', $remotes, true) ? 'origin' : $remotes[0]))
  19. : 'git tag';
  20. $tags = array_map(function ($ref) {
  21. $ref = explode('refs/tags/', $ref);
  22. return $ref[1] ?? $ref[0];
  23. }, array_filter(explode("\n", trim(shell_exec($tagsCommand))), function ($ref) {
  24. return substr($ref, -3) !== '^{}';
  25. }));
  26. usort($tags, 'version_compare');
  27. $tag = isset($argv[1]) && !\in_array($argv[1], ['last', 'latest']) ? $argv[1] : end($tags);
  28. if (strtolower($tag) !== 'all') {
  29. if (!\in_array($tag, $tags, true)) {
  30. echo "Tag must be one of remote tags available:\n";
  31. foreach ($tags as $_tag) {
  32. echo " - $_tag\n";
  33. }
  34. echo "\"$tag\" does not match.\n";
  35. exit(1);
  36. }
  37. $tags = [$tag];
  38. }
  39. foreach ($tags as $tag) {
  40. $archive = "Carbon-$tag.zip";
  41. if (isset($argv[2]) && $argv[2] === 'missing' && file_exists($archive)) {
  42. continue;
  43. }
  44. $branch = "build-$tag";
  45. shell_exec('git stash');
  46. shell_exec("git branch -d $branch");
  47. shell_exec("git checkout tags/$tag -b $branch");
  48. $phpVersion = version_compare($tag, '2.0.0-dev', '<') ? '5.3.9' : '7.1.8';
  49. shell_exec("composer config platform.php $phpVersion");
  50. shell_exec('composer remove friendsofphp/php-cs-fixer --dev');
  51. shell_exec('composer remove kylekatarnls/multi-tester --dev');
  52. shell_exec('composer remove phpmd/phpmd --dev');
  53. shell_exec('composer remove phpstan/phpstan --dev');
  54. shell_exec('composer remove phpunit/phpunit --dev');
  55. shell_exec('composer remove squizlabs/php_codesniffer --dev');
  56. shell_exec('composer update --no-interaction --no-dev --optimize-autoloader');
  57. $zip = new ZipArchive();
  58. $zip->open($archive, ZipArchive::CREATE | ZipArchive::OVERWRITE);
  59. foreach (['src', 'vendor', 'Carbon', 'lazy'] as $directory) {
  60. if (is_dir($directory)) {
  61. $directory = realpath($directory);
  62. $base = \dirname($directory);
  63. $files = new RecursiveIteratorIterator(
  64. new RecursiveDirectoryIterator($directory),
  65. RecursiveIteratorIterator::LEAVES_ONLY
  66. );
  67. foreach ($files as $name => $file) {
  68. if (!$file->isDir()) {
  69. $filePath = $file->getRealPath();
  70. $zip->addFile($filePath, substr($filePath, \strlen($base) + 1));
  71. }
  72. }
  73. }
  74. }
  75. $autoload = 'autoload.php';
  76. file_put_contents($autoload, "<?php\n\n/**\n * @version $tag\n */\n\nrequire __DIR__.'/vendor/autoload.php';\n");
  77. $zip->addFile($autoload, $autoload);
  78. $zip->close();
  79. unlink($autoload);
  80. shell_exec('git checkout .');
  81. shell_exec("git checkout $currentBranch");
  82. shell_exec("git branch -d $branch");
  83. shell_exec('git stash pop');
  84. shell_exec('composer config platform.php 7.1.8');
  85. shell_exec('composer update --no-interaction');
  86. }
  87. exit(0);