release.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. if (!isset($argv[1]) || $argv[1] == '--help') {
  3. echo "Usage: php .scripts/release.php <semver>\n";
  4. exit;
  5. }
  6. $version = $argv[1];
  7. // Verify that $version is a valid semver string
  8. // Performing check according to: https://getcomposer.org/doc/04-schema.md#version
  9. $regexp = '/^[0-9]+\.[0-9]+\.[0-9]+(?:-(?:dev|rc\.[0-9]+))?$/';
  10. if (!preg_match($regexp, $version, $matches)) {
  11. echo "Bad version format. You must follow the format of X.Y.Z with an optional suffix of -dev,"
  12. . " or -rc.N (where N is a number).\n";
  13. exit(1);
  14. }
  15. require_once dirname(__DIR__) . '/vendor/autoload.php';
  16. function run_commands($commands) {
  17. foreach ($commands as $command) {
  18. echo "$command\n";
  19. passthru($command, $return_val);
  20. if ($return_val !== 0) {
  21. echo "Error executing command! Interrupting!\n";
  22. exit(2);
  23. }
  24. }
  25. }
  26. $elgg_path = dirname(__DIR__);
  27. $branch = "release-$version";
  28. // Setup. Version checks are here so we fail early if any deps are missing
  29. run_commands([
  30. "tx --version",
  31. "git --version",
  32. "npm --version",
  33. "node --version",
  34. "sphinx-build --version",
  35. "cd $elgg_path",
  36. "git checkout -B $branch",
  37. ]);
  38. // Update translations
  39. run_commands([
  40. "tx pull -af --minimum-perc=95",
  41. ]);
  42. // Clean translations
  43. $cleaner = new Elgg\I18n\ReleaseCleaner();
  44. $cleaner->cleanInstallation(dirname(__DIR__));
  45. foreach ($cleaner->log as $msg) {
  46. echo "ReleaseCleaner: $msg\n";
  47. }
  48. run_commands([
  49. "sphinx-build -b gettext docs docs/locale/pot",
  50. "sphinx-intl build --locale-dir=docs/locale/",
  51. "git add .",
  52. "git commit -am \"chore(i18n): update translations\"",
  53. ]);
  54. // Update version in composer.json
  55. $encoding = new \Elgg\Json\EmptyKeyEncoding();
  56. $composer_path = "$elgg_path/composer.json";
  57. $composer_config = $encoding->decode(file_get_contents($composer_path));
  58. $composer_config->version = $version;
  59. $json = $encoding->encode($composer_config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
  60. file_put_contents($composer_path, $json);
  61. // Generate changelog
  62. run_commands(array(
  63. "npm install && npm update",
  64. "node .scripts/write-changelog.js",
  65. "git add .",
  66. "git commit -am \"chore(release): v$version\"",
  67. ));