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