From 1d6dd387ccbb9e83b3d74d4e51a1044593e61620 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Wed, 24 Jan 2024 17:45:23 +0800 Subject: [PATCH] release script --- bin/release.php | 51 +++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/bin/release.php b/bin/release.php index edfc965e..57393542 100644 --- a/bin/release.php +++ b/bin/release.php @@ -22,16 +22,16 @@ class Build extends Console --dry-run Dry run without git push or commit. HELP; + protected array $scripts = []; + /** - * doExecute - * * @return bool|mixed - * - * @since __DEPLOY_VERSION__ */ protected function doExecute() { - $this->compileAssets(); + foreach ($this->scripts as $script) { + $this->exec($script); + } $currentVersion = trim(file_get_contents(__DIR__ . '/../VERSION')); $targetVersion = $this->getArgument(0); @@ -42,11 +42,9 @@ protected function doExecute() $this->out('Release version: ' . $targetVersion); - $this->replaceDocblockTags($targetVersion); - static::writeVersion($targetVersion); + $this->replaceDocblockTags($targetVersion); - $this->exec('git add .'); $this->exec(sprintf('git commit -am "Release version: %s"', $targetVersion)); $this->exec(sprintf('git tag %s', $targetVersion)); @@ -56,6 +54,13 @@ protected function doExecute() return true; } + public function addScript(string $script): static + { + $this->scripts[] = $script; + + return $this; + } + /** * writeVersion * @@ -153,29 +158,9 @@ protected function replaceDocblockTags(string $version): void file_put_contents($file->getPathname(), $content); } - $this->exec('git checkout master'); + $this->exec('git checkout main'); $this->exec(sprintf('git commit -am "Prepare for %s release."', $version)); - $this->exec('git push origin master'); - } - - /** - * compileAssets - * - * @return void - * - * @since __DEPLOY_VERSION__ - */ - protected function compileAssets() - { - foreach (glob(__DIR__ . '/../assets/dist/*.js.map') as $file) { - unlink($file); - } - - foreach (glob(__DIR__ . '/../assets/dist/page/*') as $file) { - unlink($file); - } - - $this->exec('yarn --cwd ./assets build:prod'); + $this->exec('git push origin main'); } /** @@ -197,4 +182,8 @@ protected function exec($command) } } -exit((new Build())->execute()); +exit((new Build()) + ->addScript('rm -rf ' . __DIR__ . '/../assets/dist/*.js.map') + ->addScript('rm -rf ' . __DIR__ . '/../assets/dist/page/*') + ->addScript('yarn --cwd ./assets build:prod') + ->execute());