Skip to content

Commit

Permalink
finished automated extension releases
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Mar 17, 2016
1 parent 168c1cd commit 6e4aaaa
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 54 deletions.
59 changes: 46 additions & 13 deletions build/controllers/PhpDocController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ public function options($actionID)
protected function findFiles($root)
{
$except = [];
$extensionExcept = [
'apidoc' => [
'/helpers/PrettyPrinter.php',
'/extensions/apidoc/helpers/ApiIndexer.php',
'/extensions/apidoc/helpers/ApiMarkdownLaTeX.php',
],
'codeception' => [
'/TestCase.php',
'/DbTestCase.php',
],
'gii' => [
'/components/DiffRendererHtmlInline.php',
'/generators/extension/default/*',
],
'twig' => [
'/Extension.php',
'/Optimizer.php',
'/Template.php',
'/TwigSimpleFileLoader.php',
'/ViewRendererStaticClassProxy.php',
],
];

if ($root === null) {
$root = dirname(YII2_PATH);
$extensionPath = "$root/extensions";
Expand All @@ -121,29 +144,38 @@ protected function findFiles($root)
}

$except = [
'.git/',
'/apps/',
'/build/',
'/docs/',
'/extensions/apidoc/helpers/PrettyPrinter.php',
'/extensions/apidoc/helpers/ApiIndexer.php',
'/extensions/apidoc/helpers/ApiMarkdownLaTeX.php',
'/extensions/codeception/TestCase.php',
'/extensions/codeception/DbTestCase.php',
'/extensions/composer/',
'/extensions/gii/components/DiffRendererHtmlInline.php',
'/extensions/gii/generators/extension/default/*',
'/extensions/twig/Extension.php',
'/extensions/twig/Optimizer.php',
'/extensions/twig/Template.php',
'/extensions/twig/TwigSimpleFileLoader.php',
'/extensions/twig/ViewRendererStaticClassProxy.php',
'/framework/BaseYii.php',
'/framework/Yii.php',
'assets/',
'tests/',
'vendor/',
];
foreach($extensionExcept as $ext => $paths) {
foreach($paths as $path) {
$except[] = "/extensions/$ext$path";
}
}
} elseif (preg_match('~extensions/([\w\d-]+)/?$~', $root, $matches)) {
list(, $extension) = $matches;
Yii::setAlias("@yii/$extension", "$root");

if (isset($extensionExcept[$extension])) {
foreach($extensionExcept[$extension] as $path) {
$except[] = $path;
}
}
$except[] = '/vendor/';
$except[] = '/tests/';
$except[] = '/docs/';

// // composer extension does not contain yii code
// if ($extension === 'composer') {
// return [];
// }
}
$root = FileHelper::normalizePath($root);
$options = [
Expand All @@ -159,6 +191,7 @@ protected function findFiles($root)
},
'only' => ['*.php'],
'except' => array_merge($except, [
'.git/',
'views/',
'requirements/',
'gii/generators/',
Expand Down
131 changes: 90 additions & 41 deletions build/controllers/ReleaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public function actionPrepare(array $what)
$this->printWhat($what, $newVersions, $versions);
$this->stdout("\n");

$this->stdout("Before you make a release briefly go over the changes and check if you spot obvious mistakes:\n\n", Console::BOLD);
$this->stdout("- no accidentally added CHANGELOG lines for other versions than this one?\n");
$this->stdout("- are all new `@since` tags for this relase version?\n");
$this->stdout("- other issues with code changes?\n\n");
$this->stdout("- also make sure the milestone on github is complete and no issues or PRs are left open.\n\n");
$this->printWhatUrls($what, $versions);
$this->stdout("\n");

if (!$this->confirm('When you continue, this tool will run cleanup jobs and update the changelog as well as other files (locally). Continue?', false)) {
$this->stdout("Canceled.\n");
return 1;
Expand All @@ -97,30 +105,31 @@ public function actionPrepare(array $what)
return 0;
}

/**
* Usage:
*
* ```
* ./build/build release/done framework 2.0.0-dev 2.0.0-rc
* ./build/build release/done redis 2.0.0-dev 2.0.0-rc
* ```
*/
public function actionDone(array $what, $devVersion, $nextVersion)
protected function printWhat(array $what, $newVersions, $versions)
{
$this->openChangelogs($what, $nextVersion);
$this->composerSetStability($what, 'dev');
if (in_array('framework', $what)) {
$this->updateYiiVersion($devVersion);
foreach($what as $ext) {
if ($ext === 'framework') {
$this->stdout(" - Yii Framework version ");
} else {
$this->stdout(" - ");
$this->stdout($ext, Console::FG_RED);
$this->stdout(" extension version ");
}
$this->stdout($newVersions[$ext], Console::BOLD);
$this->stdout(", current latest release is {$versions[$ext]}\n");
}
}

protected function printWhat(array $what, $newVersions, $versions)
protected function printWhatUrls(array $what, $oldVersions)
{
foreach($what as $w) {
if ($w === 'framework') {
$this->stdout(" - Yii Framework version {$newVersions[$w]}, current latest release is {$versions[$w]}\n");
foreach($what as $ext) {
if ($ext === 'framework') {
$this->stdout("framework: https://github.com/yiisoft/yii2-framework/compare/{$oldVersions[$ext]}...master\n");
$this->stdout("app-basic: https://github.com/yiisoft/yii2-app-basic/compare/{$oldVersions[$ext]}...master\n");
$this->stdout("app-advanced: https://github.com/yiisoft/yii2-app-advanced/compare/{$oldVersions[$ext]}...master\n");
} else {
$this->stdout(" - $w extension version {$newVersions[$w]}, current latest release is {$versions[$w]}\n");
$this->stdout($ext, Console::FG_RED);
$this->stdout(": https://github.com/yiisoft/yii2-$ext/compare/{$oldVersions[$ext]}...master\n");
}
}
}
Expand Down Expand Up @@ -157,6 +166,8 @@ protected function ensureGitClean($path)

protected function releaseFramework($frameworkPath, $version)
{
throw new Exception('NOT IMPLEMENTED COMPLETELY YET');

$this->stdout("\n");
$this->stdout($h = "Preparing framework release version $version", Console::BOLD);
$this->stdout("\n" . str_repeat('-', strlen($h)) . "\n\n", Console::BOLD);
Expand Down Expand Up @@ -228,6 +239,17 @@ protected function releaseFramework($frameworkPath, $version)
// if (in_array('framework', $what)) {
// $this->updateYiiVersion($version);
// }


// if done:
// * ./build/build release/done framework 2.0.0-dev 2.0.0-rc
// * ./build/build release/done redis 2.0.0-dev 2.0.0-rc
// $this->openChangelogs($what, $nextVersion);
// $this->composerSetStability($what, 'dev');
// if (in_array('framework', $what)) {
// $this->updateYiiVersion($devVersion);
// }

}

protected function releaseExtension($name, $path, $version)
Expand All @@ -236,57 +258,85 @@ protected function releaseExtension($name, $path, $version)
$this->stdout($h = "Preparing release for extension $name version $version", Console::BOLD);
$this->stdout("\n" . str_repeat('-', strlen($h)) . "\n\n", Console::BOLD);

if ($this->confirm('Run `git checkout master`?', true)) {
chdir($path);
exec('git checkout master', $output, $ret); // TODO add compatibility for other release branches
if ($ret != 0) {
throw new Exception('Command "git checkout master" failed with code ' . $ret);
}
}

if ($this->confirm('Run `git pull`?', true)) {
chdir($path);
exec('git pull', $output, $ret);
if ($ret != 0) {
throw new Exception('Command "git pull" failed with code ' . $ret);
}
}
$this->runGit('git checkout master', $path); // TODO add compatibility for other release branches
$this->runGit('git pull', $path); // TODO add compatibility for other release branches

// adjustments

$this->stdout('fixing various PHPdoc style issues...');
$this->stdout("fixing various PHPdoc style issues...\n", Console::BOLD);
$this->dryRun || Yii::$app->runAction('php-doc/fix', [$path]);
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);

$this->stdout('updating PHPdoc @property annotations...');
$this->stdout("updating PHPdoc @property annotations...\n", Console::BOLD);
$this->dryRun || Yii::$app->runAction('php-doc/property', [$path]);
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);

$this->stdout('sorting changelogs...');
$this->stdout('sorting changelogs...', Console::BOLD);
$this->dryRun || $this->resortChangelogs([$name], $version);
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);

$this->stdout('closing changelogs...');
$this->stdout('closing changelogs...', Console::BOLD);
$this->dryRun || $this->closeChangelogs([$name], $version);
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);

$this->stdout("\nIn the following you can check the above changes using git diff.\n\n");
do {
$this->runGit("git diff", $path);
} while(!$this->confirm('continue?'));
$this->runGit("git diff --color", $path);
$this->stdout("\n\n\nCheck whether the above diff is okay, if not you may change things as needed before continuing.\n");
$this->stdout("You may abort the program with Ctrl + C and reset the changes by running `git checkout -- .` in the repo.\n\n");
} while(!$this->confirm("Type `yes` to continue, `no` to view git diff again. Continue?"));

$this->stdout("\n\n");
$this->stdout(" **** RELEASE TIME! ****\n", Console::FG_YELLOW, Console::BOLD);
$this->stdout(" **** Commit, Tag and Push it! ****\n", Console::FG_YELLOW, Console::BOLD);
$this->stdout("\n\nHint: if you decide 'no' for any of the following, the command will not be executed. You may manually run them later if needed. E.g. try the release locally without pushing it.\n\n");

$this->runGit("git commit -a -m \"release version $version\"", $path);
$this->runGit("git push", $path);
$this->runGit("git tag -a $version -m\"version $version\"", $path);
$this->runGit("git push", $path);
$this->runGit("git push --tags", $path);

$this->stdout("\n\n");
$this->stdout("CONGRATULATIONS! You have just released extension ", Console::FG_YELLOW, Console::BOLD);
$this->stdout($name, Console::FG_RED, Console::BOLD);
$this->stdout(" version ", Console::FG_YELLOW, Console::BOLD);
$this->stdout($version, Console::BOLD);
$this->stdout("!\n\n", Console::FG_YELLOW, Console::BOLD);

// prepare next release

$this->stdout("Time to prepare the next release...\n\n", Console::FG_YELLOW, Console::BOLD);

$this->stdout('opening changelogs...', Console::BOLD);
$nextVersion = $this->getNextVersions([$name => $version], self::PATCH); // TODO support other versions
$this->dryRun || $this->openChangelogs([$name], $nextVersion[$name]);
$this->stdout("done.\n", Console::FG_GREEN, Console::BOLD);

$this->stdout("\n");
$this->runGit("git diff --color", $path);
$this->stdout("\n\n");
$this->runGit("git commit -a -m \"prepare for next release\"", $path);
$this->runGit("git push", $path);

$this->stdout("\n\nDONE!", Console::FG_YELLOW, Console::BOLD);

$this->stdout("\n\nThe following steps are left for you to do manually:\n\n");
$nextVersion2 = $this->getNextVersions($nextVersion, self::PATCH); // TODO support other versions
$this->stdout("- close the $version milestone on github and open new ones for {$nextVersion[$name]} and {$nextVersion2[$name]}: https://github.com/yiisoft/yii2-$name/milestones\n");
$this->stdout("- release news and announcement.\n");
$this->stdout("- update the website (will be automated soon and is only relevant for the new website).\n");

$this->stdout("\n");
}


protected function runGit($cmd, $path)
{
if ($this->confirm("Run `$cmd`?", true)) {
if ($this->dryRun) {
$this->stdout("dry run, command `$cmd` not executed.\n");
return;
}
chdir($path);
exec($cmd, $output, $ret);
echo implode("\n", $output);
Expand Down Expand Up @@ -488,7 +538,6 @@ protected function getCurrentVersions(array $what)
rsort($tags, SORT_NATURAL); // TODO this can not deal with alpha/beta/rc...
$versions[$ext] = reset($tags);
}
print_r($versions);
return $versions;
}

Expand Down

0 comments on commit 6e4aaaa

Please sign in to comment.