builds 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/usr/bin/env php
  2. <?php
  3. define('LATEST_RELEASE', '^4.0');
  4. define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
  5. /*
  6. * --------------------------------------------------------------------
  7. * Stability Toggle
  8. * --------------------------------------------------------------------
  9. * Use this script to toggle the CodeIgniter dependency between the
  10. * latest stable release and the most recent development update.
  11. *
  12. * Usage: php builds [release|development]
  13. */
  14. // Determine the requested stability
  15. if (empty($argv[1]) || ! in_array($argv[1], ['release', 'development']))
  16. {
  17. echo 'Usage: php builds [release|development]' . PHP_EOL;
  18. exit;
  19. }
  20. $dev = $argv[1] == 'development';
  21. $modified = [];
  22. /* Locate each file and update it for the requested stability */
  23. // Composer.json
  24. $file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';
  25. if (is_file($file))
  26. {
  27. // Make sure we can read it
  28. if ($contents = file_get_contents($file))
  29. {
  30. if ($array = json_decode($contents, true))
  31. {
  32. // Development
  33. if ($dev)
  34. {
  35. // Set 'minimum-stability'
  36. $array['minimum-stability'] = 'dev';
  37. $array['prefer-stable'] = true;
  38. // Make sure the repo is configured
  39. if (! isset($array['repositories']))
  40. {
  41. $array['repositories'] = [];
  42. }
  43. // Check for the CodeIgniter repo
  44. $found = false;
  45. foreach ($array['repositories'] as $repository)
  46. {
  47. if ($repository['url'] == GITHUB_URL)
  48. {
  49. $found = true;
  50. break;
  51. }
  52. }
  53. // Add the repo if it was not found
  54. if (! $found)
  55. {
  56. $array['repositories'][] = [
  57. 'type' => 'vcs',
  58. 'url' => GITHUB_URL,
  59. ];
  60. }
  61. // Define the "require"
  62. $array['require']['codeigniter4/codeigniter4'] = 'dev-develop';
  63. unset($array['require']['codeigniter4/framework']);
  64. }
  65. // Release
  66. else
  67. {
  68. // Clear 'minimum-stability'
  69. unset($array['minimum-stability']);
  70. // If the repo is configured then clear it
  71. if (isset($array['repositories']))
  72. {
  73. // Check for the CodeIgniter repo
  74. foreach ($array['repositories'] as $i => $repository)
  75. {
  76. if ($repository['url'] == GITHUB_URL)
  77. {
  78. unset($array['repositories'][$i]);
  79. break;
  80. }
  81. }
  82. if (empty($array['repositories']))
  83. {
  84. unset($array['repositories']);
  85. }
  86. }
  87. // Define the "require"
  88. $array['require']['codeigniter4/framework'] = LATEST_RELEASE;
  89. unset($array['require']['codeigniter4/codeigniter4']);
  90. }
  91. // Write out a new composer.json
  92. file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . PHP_EOL);
  93. $modified[] = $file;
  94. }
  95. else
  96. {
  97. echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
  98. }
  99. }
  100. else
  101. {
  102. echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
  103. }
  104. }
  105. // Paths config and PHPUnit XMLs
  106. $files = [
  107. __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
  108. __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist',
  109. __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml',
  110. ];
  111. foreach ($files as $file)
  112. {
  113. if (is_file($file))
  114. {
  115. $contents = file_get_contents($file);
  116. // Development
  117. if ($dev)
  118. {
  119. $contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
  120. }
  121. // Release
  122. else
  123. {
  124. $contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
  125. }
  126. file_put_contents($file, $contents);
  127. $modified[] = $file;
  128. }
  129. }
  130. if (empty($modified))
  131. {
  132. echo 'No files modified' . PHP_EOL;
  133. }
  134. else
  135. {
  136. echo 'The following files were modified:' . PHP_EOL;
  137. foreach ($modified as $file)
  138. {
  139. echo " * {$file}" . PHP_EOL;
  140. }
  141. echo 'Run `composer update` to sync changes with your vendor folder' . PHP_EOL;
  142. }