|
| 1 | +#!/usr/bin/env php |
1 | 2 | <?php |
2 | 3 |
|
3 | 4 | /* |
|
12 | 13 | require_once __DIR__.'/../vendor/autoload.php'; |
13 | 14 |
|
14 | 15 | if (!isset($argv[1])) { |
15 | | - throw new \InvalidArgumentException('You must provide version.'); |
| 16 | + throw new \InvalidArgumentException('You must specify the version: v1.x.x or next.'); |
16 | 17 | } |
17 | 18 |
|
18 | 19 | $version = $argv[1]; |
19 | 20 |
|
20 | | -echo sprintf("Releasing symfony version \"%s\".\n", $version); |
| 21 | +exec('git tag -l', $tags, $resultCode); |
| 22 | + |
| 23 | +if ($resultCode > 0 || count($tags) === 0) { |
| 24 | + throw new \RuntimeException('Reading tag failed.'); |
| 25 | +} |
| 26 | + |
| 27 | +$latestVersionNumber = $tags[0]; |
| 28 | +foreach ($tags as $tag) { |
| 29 | + if (version_compare($latestVersionNumber, $tag) < 0) { |
| 30 | + $latestVersionNumber = $tag; |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +if ($version !== 'next') { |
| 35 | + if (!preg_match('/^v1\.([5-9]|\d{2,})\.\d+$/', $version)) { |
| 36 | + throw new \InvalidArgumentException(sprintf('The format of the specified version number is incorrect: "%s"', $version)); |
| 37 | + } |
| 38 | + |
| 39 | + if (in_array($version, $tags)) { |
| 40 | + throw new \InvalidArgumentException(sprintf('The specified version number already exists: "%s"', $version)); |
| 41 | + } |
| 42 | + |
| 43 | + [$latestMajorPart, $latestMinorPart, $latestPatchPart] = explode('.', $latestVersionNumber); |
| 44 | + [$versionMajorPart, $versionMinorPart, $versionPatchPart] = explode('.', $version); |
| 45 | + |
| 46 | + // This cannot be due to regexp. Just double check. |
| 47 | + if ($latestMajorPart !== $versionMajorPart) { |
| 48 | + throw new \InvalidArgumentException(sprintf('The specified version number can\'t change major: "%s"', $version)); |
| 49 | + } |
| 50 | + |
| 51 | + // changed minor or patch |
| 52 | + if ($latestMinorPart !== $versionMinorPart) { |
| 53 | + if ($versionPatchPart !== '0') { |
| 54 | + throw new \InvalidArgumentException(sprintf('The specified version number should be: "%s.%s.0"', $versionMajorPart, $versionMinorPart)); |
| 55 | + } |
| 56 | + } elseif ($latestPatchPart !== $versionPatchPart) { |
| 57 | + $latestPatchPartInt = (int) $latestPatchPart; |
| 58 | + $versionPatchPartInt = (int) $versionPatchPart; |
| 59 | + |
| 60 | + $nextPatchPartInt = $latestPatchPartInt+1; |
| 61 | + |
| 62 | + if ($nextPatchPartInt !== $versionPatchPartInt) { |
| 63 | + throw new \InvalidArgumentException(sprintf('Don\'t skip patch version. The specified version number should be: "%s.%s.%d"', $versionMajorPart, $versionMinorPart, $nextPatchPartInt)); |
| 64 | + } |
| 65 | + } |
| 66 | +} else { |
| 67 | + [$latestMajorPart, $latestMinorPart, $latestPatchPart] = explode('.', $latestVersionNumber); |
| 68 | + $nextPatchPart = (int) $latestPatchPart + 1; |
| 69 | + $version = sprintf('%s.%s.%d', $latestMajorPart, $latestMinorPart, $nextPatchPart); |
| 70 | +} |
| 71 | + |
| 72 | +$rawVersion = substr($version, 1); |
| 73 | + |
| 74 | +echo sprintf("Prepare symfony version \"%s\".\n", $rawVersion); |
21 | 75 |
|
22 | 76 | exit(0); |
0 commit comments