Skip to content

Commit

Permalink
release script
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Jan 24, 2024
1 parent 48f7451 commit 1d6dd38
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions bin/release.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));

Expand All @@ -56,6 +54,13 @@ protected function doExecute()
return true;
}

public function addScript(string $script): static
{
$this->scripts[] = $script;

return $this;
}

/**
* writeVersion
*
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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());

0 comments on commit 1d6dd38

Please sign in to comment.