Add release script

This commit is contained in:
Anton Medvedev 2017-12-16 21:38:43 +07:00
parent 6557322874
commit e8192fd596
2 changed files with 55 additions and 1 deletions

View File

@ -4,7 +4,8 @@
[v6.0.4...master](https://github.com/deployphp/deployer/compare/v6.0.4...master)
### Fixed
- Fixed `previous_release` param when `release_name` was overrided [#1455]
- Fixed `previous_release` param when `release_name` was overridden [#1455]
## v6.0.4
[v6.0.3...v6.0.4](https://github.com/deployphp/deployer/compare/v6.0.3...v6.0.4)

53
scripts/release Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env php
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require __DIR__ . '/../vendor/autoload.php';
chdir(realpath(__DIR__ . '/..'));
$opt = getopt('v::');
$changelog = file_get_contents('CHANGELOG.md');
$latestVersion = '0.0.0';
if (preg_match('/## v(.+)/', $changelog, $matches)) {
$latestVersion = $matches[1];
}
if (array_key_exists('v', $opt)) {
$version = $opt['v'];
if (!preg_match('/^\d+\.\d+\.\d+(-[\d\w\.]+)?$/i', $version)) {
die("Version number must follow semantic versioning.\n");
}
} else {
die("Please, specify verion to release. Latest version is -v$latestVersion\n");
}
// Next goes bunch of regexs. Now we have three problems.
// Right solution will be to create a parser what reads
// changelog and generates AST, printer which outputs all
// in desired format. But it will take too much effort.
// So may be you, {{user_name}}, wish to implement it?
//
// ...back to regexs 👨🏻‍🚀
$changelog = preg_replace('/(?<=## )master/', "v$version", $changelog);
$changelog = preg_replace('/\[(v.+)master\]\((.+)master\)/', "[$1v$version]($2v$version)", $changelog);
$new = <<<MASTER
# Changelog
## master
[v$version...master](https://github.com/deployphp/deployer/compare/v$version...master)
MASTER;
$changelog = preg_replace('/# Changelog/', $new, $changelog);
file_put_contents('CHANGELOG.md', $changelog);
echo "Updated CHANGELOG.md to v$version.";