builds 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/env php
  2. <?php
  3. define('LATEST_RELEASE', '^4.7');
  4. define('DEVELOP_BRANCH', 'dev-develop');
  5. define('NEXT_MINOR', '^4.8-dev');
  6. define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
  7. /*
  8. * --------------------------------------------------------------------
  9. * Stability Toggle
  10. * --------------------------------------------------------------------
  11. * Use this script to toggle the CodeIgniter dependency between the
  12. * latest stable release and the most recent development update.
  13. *
  14. * Usage: php builds [release|development|next]
  15. */
  16. $branch = $argv[1] ?? '';
  17. // Determine the requested stability
  18. if ($branch === '' || ! in_array($branch, ['release', 'development', 'next'], true)) {
  19. echo 'Usage: php builds [release|development|next]' . PHP_EOL;
  20. exit;
  21. }
  22. $modified = [];
  23. // Locate each file and update it for the requested stability
  24. $file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';
  25. if (is_file($file)) {
  26. $contents = file_get_contents($file);
  27. if ((string) $contents !== '') {
  28. $array = json_decode($contents, true);
  29. if (is_array($array)) {
  30. if ($branch !== 'release') {
  31. $array['minimum-stability'] = 'dev';
  32. $array['prefer-stable'] = true;
  33. $array['repositories'] ??= [];
  34. $found = false;
  35. foreach ($array['repositories'] as $repository) {
  36. if ($repository['url'] === GITHUB_URL) {
  37. $found = true;
  38. break;
  39. }
  40. }
  41. if (! $found) {
  42. $array['repositories'][] = [
  43. 'type' => 'vcs',
  44. 'url' => GITHUB_URL,
  45. ];
  46. }
  47. $array['require']['codeigniter4/codeigniter4'] = $branch === 'next' ? NEXT_MINOR : DEVELOP_BRANCH;
  48. unset($array['require']['codeigniter4/framework']);
  49. } else {
  50. unset($array['minimum-stability']);
  51. if (isset($array['repositories'])) {
  52. foreach ($array['repositories'] as $i => $repository) {
  53. if ($repository['url'] === GITHUB_URL) {
  54. unset($array['repositories'][$i]);
  55. break;
  56. }
  57. }
  58. if ($array['repositories'] === []) {
  59. unset($array['repositories']);
  60. }
  61. }
  62. $array['require']['codeigniter4/framework'] = LATEST_RELEASE;
  63. unset($array['require']['codeigniter4/codeigniter4']);
  64. }
  65. file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
  66. $modified[] = $file;
  67. } else {
  68. echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
  69. }
  70. } else {
  71. echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
  72. }
  73. }
  74. $files = [
  75. __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
  76. __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.dist.xml',
  77. __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml',
  78. ];
  79. foreach ($files as $file) {
  80. if (is_file($file)) {
  81. $contents = file_get_contents($file);
  82. if ($branch !== 'release') {
  83. $contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
  84. } else {
  85. $contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
  86. }
  87. file_put_contents($file, $contents);
  88. $modified[] = $file;
  89. }
  90. }
  91. if ($modified === []) {
  92. echo 'No files modified.' . PHP_EOL;
  93. } else {
  94. echo 'The following files were modified:' . PHP_EOL;
  95. foreach ($modified as $file) {
  96. echo " * {$file}" . PHP_EOL;
  97. }
  98. }
  99. echo 'Run `composer update` to sync changes with your vendor folder.' . PHP_EOL;
  100. echo 'Don\'t forget to update the project files in app folder from "vendor/codeigniter4/*/app/".' . PHP_EOL;