-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathrelease.php
executable file
·146 lines (108 loc) · 4.26 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env php
<?php
declare(strict_types=1);
/*
* This file is part of the Symfony1 package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (PHP_VERSION_ID < 80300) {
echo 'PHP 8.3 required'.PHP_EOL;
exit(1);
}
if (!isset($argv[1])) {
throw new InvalidArgumentException('You must specify the version: v1.x.x or next.');
}
$version = $argv[1];
exec('git tag -l', $tags, $resultCode);
if ($resultCode > 0 || 0 === count($tags)) {
throw new RuntimeException('Reading tag failed.');
}
$latestVersionNumber = $tags[0];
foreach ($tags as $tag) {
if (version_compare($latestVersionNumber, $tag) < 0) {
$latestVersionNumber = $tag;
}
}
if ('next' !== $version) {
if (!preg_match('/^v1\.([5-9]|\d{2,})\.\d+$/', $version)) {
throw new InvalidArgumentException(sprintf('The format of the specified version number is incorrect: "%s"', $version));
}
if (in_array($version, $tags)) {
throw new InvalidArgumentException(sprintf('The specified version number already exists: "%s"', $version));
}
[$latestMajorPart, $latestMinorPart, $latestPatchPart] = explode('.', $latestVersionNumber);
[$versionMajorPart, $versionMinorPart, $versionPatchPart] = explode('.', $version);
// This cannot be due to regexp. Just double check.
if ($latestMajorPart !== $versionMajorPart) {
throw new InvalidArgumentException(sprintf('The specified version number can\'t change major: "%s"', $version));
}
// changed minor or patch
if ($latestMinorPart !== $versionMinorPart) {
if ('0' !== $versionPatchPart) {
throw new InvalidArgumentException(sprintf('The specified version number should be: "%s.%s.0"', $versionMajorPart, $versionMinorPart));
}
} elseif ($latestPatchPart !== $versionPatchPart) {
$latestPatchPartInt = (int) $latestPatchPart;
$versionPatchPartInt = (int) $versionPatchPart;
$nextPatchPartInt = $latestPatchPartInt + 1;
if ($nextPatchPartInt !== $versionPatchPartInt) {
throw new InvalidArgumentException(sprintf('Don\'t skip patch version. The specified version number should be: "%s.%s.%d"', $versionMajorPart, $versionMinorPart, $nextPatchPartInt));
}
}
} else {
[$latestMajorPart, $latestMinorPart, $latestPatchPart] = explode('.', $latestVersionNumber);
$nextPatchPart = (int) $latestPatchPart + 1;
$version = sprintf('%s.%s.%d', $latestMajorPart, $latestMinorPart, $nextPatchPart);
}
$rawVersion = substr($version, 1);
echo sprintf("Prepare symfony version \"%s\".\n", $rawVersion);
/**
* prepare sfCoreAutoload class.
*/
$file = __DIR__.'/../lib/autoload/sfCoreAutoload.class.php';
$content = file_get_contents($file);
$content = preg_replace('/^define\(.*SYMFONY_VERSION.*$/m', 'define(\'SYMFONY_VERSION\', \''.$rawVersion.'\');', $content, -1, $count);
if (1 !== $count) {
throw new RuntimeException('Preparing sfCoreAutoload failed, SYMFONY_VERSION constant not found.');
}
file_put_contents($file, $content);
/**
* prepare CHANGELOG.md.
*/
$file = __DIR__.'/../CHANGELOG.md';
$content = file_get_contents($file);
$nextVersionHeader = <<<'EOL'
xx/xx/xxxx: Version 1.5.xx
--------------------------
EOL;
$changelogHeader = sprintf('%s: Version %s', date('d/m/Y'), $rawVersion);
$content = preg_replace('/^xx\/xx\/xxxx.*$/m', $nextVersionHeader.$changelogHeader, $content, -1, $count);
if (1 !== $count) {
throw new RuntimeException('Preparing CHANGELOG.md failed. Template line not found.');
}
file_put_contents($file, $content);
/*
* content prepare end
*/
echo "Please check the changes before commit and tagging.\n";
passthru('git diff');
echo "Is everything ok? (y/N)\n";
$answer = readline();
if ('y' !== strtolower($answer)) {
echo "Revert changes.\n";
exec('git checkout lib/autoload/sfCoreAutoload.class.php');
exec('git checkout CHANGELOG.md');
echo "Stopped.\n";
exit(1);
}
chdir(__DIR__.'/..');
exec('git add lib/autoload/sfCoreAutoload.class.php');
exec('git add CHANGELOG.md');
exec('git commit -m "Prepare release '.$rawVersion.'"');
exec('git tag -a '.$version.' -m "Release '.$rawVersion.'"');
exec('git push origin '.$version);
exit(0);