doc
1 year ago
lib
1 year ago
tests
1 year ago
.coveralls.yml
1 year ago
.git
1 year ago
.gitignore
1 year ago
.travis.yml
1 year ago
LICENSE.txt
1 year ago
README.md
1 year ago
build.php
1 year ago
composer.json
1 year ago
init.php
1 year ago
overview.md
1 year ago
phpunit.no_autoload.xml
1 year ago
phpunit.xml
1 year ago
release.php
1 year ago
test
1 year ago
release.php
122 lines
| 1 | #!/usr/bin/env php |
| 2 | <?php |
| 3 | |
| 4 | const VERSION_FILENAME = 'lib/WonderPush.php'; |
| 5 | const VERSION_REGEX = '/^(?P<prefix>\s*const\s*VERSION\s*=\s*(?P<quotes>[\'"]))(?P<version>.+)(?P<suffix>(?P=quotes)\s*;.*)$/m'; |
| 6 | $root = __DIR__; |
| 7 | |
| 8 | // |
| 9 | // Check git status |
| 10 | // |
| 11 | |
| 12 | echo "Checking the filesystem is clean…\n"; |
| 13 | $uncleanFiles = system('git status --porcelain'); |
| 14 | if ($uncleanFiles !== '') { |
| 15 | echo "Stash your changes before.\n"; |
| 16 | exit(1); |
| 17 | } |
| 18 | echo "\n"; |
| 19 | |
| 20 | // |
| 21 | // Check tests pass |
| 22 | // |
| 23 | |
| 24 | echo "Ensuring tests pass…\n"; |
| 25 | passthru("$root/test"); |
| 26 | echo "\n"; |
| 27 | |
| 28 | // |
| 29 | // Read current version |
| 30 | // |
| 31 | |
| 32 | $versionFileContent = file_get_contents(VERSION_FILENAME); |
| 33 | if (preg_match(VERSION_REGEX, $versionFileContent, $matches) !== 1) { |
| 34 | echo "Cannot find version!\n"; |
| 35 | exit(1); |
| 36 | } |
| 37 | $currentVersion = $matches['version']; |
| 38 | echo "Current version: $currentVersion\n"; |
| 39 | |
| 40 | // |
| 41 | // Ask new version |
| 42 | // |
| 43 | |
| 44 | /** @noinspection PhpComposerExtensionStubsInspection */ |
| 45 | $newVersion = readline('Enter new version: '); |
| 46 | echo "New version: $newVersion\n"; |
| 47 | echo "\n"; |
| 48 | |
| 49 | // |
| 50 | // Release |
| 51 | // |
| 52 | |
| 53 | echo "Making release commit…\n"; |
| 54 | |
| 55 | // Change version in file |
| 56 | $versionFileContent = preg_replace_callback(VERSION_REGEX, function($matches) use ($newVersion) { |
| 57 | return $matches['prefix'] . $newVersion . $matches['suffix']; |
| 58 | }, $versionFileContent); |
| 59 | file_put_contents(VERSION_FILENAME, $versionFileContent); |
| 60 | |
| 61 | // Commit and tag |
| 62 | passthru("git commit -m 'Release $newVersion' " . VERSION_FILENAME); |
| 63 | passthru("git tag -a -m 'Release $newVersion' v$newVersion"); |
| 64 | |
| 65 | echo "\n"; |
| 66 | |
| 67 | // |
| 68 | // Update documentation |
| 69 | // |
| 70 | |
| 71 | echo "Updating documentation site…\n"; |
| 72 | |
| 73 | passthru("$root/doc/generate"); |
| 74 | passthru('git checkout gh-pages'); |
| 75 | rename("$root/doc/generated", "$root/$newVersion"); |
| 76 | copy("$root/latest/api.html", "$root/$newVersion/api.html"); |
| 77 | unlink("$root/latest"); |
| 78 | symlink($newVersion, "$root/latest"); |
| 79 | passthru("git add latest $newVersion"); |
| 80 | passthru("git commit -m \"Documentation site for v$newVersion\""); |
| 81 | passthru('git checkout master'); |
| 82 | |
| 83 | echo "\n"; |
| 84 | |
| 85 | // |
| 86 | // Prepare next release |
| 87 | // |
| 88 | |
| 89 | echo "Preparing next release…\n"; |
| 90 | |
| 91 | if (strpos($newVersion, '-') !== FALSE) { |
| 92 | /** @noinspection PhpComposerExtensionStubsInspection */ |
| 93 | $nextVersion = readline('Enter next version: '); |
| 94 | } else { |
| 95 | $nextVersion = explode('.', $newVersion); |
| 96 | $nextVersion[count($nextVersion)-1] = (int)$nextVersion[count($nextVersion) - 1] + 1; |
| 97 | $nextVersion = implode('.', $nextVersion); |
| 98 | $nextVersion .= '-dev'; |
| 99 | } |
| 100 | |
| 101 | // Change version in file |
| 102 | $versionFileContent = preg_replace_callback(VERSION_REGEX, function($matches) use ($nextVersion) { |
| 103 | return $matches['prefix'] . $nextVersion . $matches['suffix']; |
| 104 | }, $versionFileContent); |
| 105 | file_put_contents(VERSION_FILENAME, $versionFileContent); |
| 106 | |
| 107 | // Commit and tag |
| 108 | passthru("git commit -m 'Prepare next release' " . VERSION_FILENAME); |
| 109 | |
| 110 | echo "\n"; |
| 111 | |
| 112 | // |
| 113 | // Publish instructions |
| 114 | // |
| 115 | |
| 116 | echo "\n"; |
| 117 | echo "The GitHub Packagist integration will work for you.\n"; |
| 118 | echo "In order to publish the release, please do:\n"; |
| 119 | echo "\n"; |
| 120 | echo " git push origin master gh-pages v$newVersion\n"; |
| 121 | echo "\n"; |
| 122 |