From 430919bcdf588cca7fece56730e23e7b4ba4e1f3 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Thu, 9 Jun 2022 14:46:37 +0300 Subject: [PATCH] Adjusted release-related commands --- RoboFile.php | 105 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 16 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 857e494..870bfdd 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -1,4 +1,5 @@ taskWatch() - ->monitor( [ 'public/css/variables.less', 'public/css/laps.less' ], function () { - $this->makeCss(); - } ) - ->monitor( 'public/js/source.js', function () { - $this->makeJs(); - } ) - ->run(); + ->monitor( [ 'public/css/variables.less', 'public/css/laps.less' ], function () { + $this->makeCss(); + } ) + ->monitor( 'public/js/source.js', function () { + $this->makeJs(); + } ) + ->run(); } /** @@ -42,7 +43,7 @@ class RoboFile extends \Robo\Tasks { $this->taskExec( 'lessc public/css/laps.less public/css/laps.css --source-map=public/css/laps.css.map' )->run(); $this->taskMinify( 'public/css/laps.css' ) - ->run(); + ->run(); } /** @@ -54,11 +55,11 @@ class RoboFile extends \Robo\Tasks { 'vendor/twbs/bootstrap/js/tooltip.js', 'public/js/source.js', ] ) - ->to( 'public/js/laps.js' ) - ->run(); + ->to( 'public/js/laps.js' ) + ->run(); $this->taskMinify( 'public/js/laps.js' ) - ->run(); + ->run(); } /** @@ -68,14 +69,65 @@ class RoboFile extends \Robo\Tasks { $dir = __DIR__ . '/src/mustache/cache'; $this->_cleanDir( $dir ); $mustache = new \Mustache_Engine( - array( + [ 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__ . '/src/mustache' ), 'cache' => $dir, - ) + ] ); $mustache->loadTemplate( 'laps' ); } + /** + * Creates release zip + * + * @param string $php PHP version to target. + */ + public function makeArchive( $php = '7.2.5' ): void { + + $composer = json_decode( file_get_contents( __DIR__ . '/composer.json' ) ); + $package = $composer->name; + + [ $vendor, $name ] = explode( '/', $package ); + + if ( empty( $vendor ) || empty( $name ) ) { + return; + } + + $this->_mkdir( 'release' ); + + $version = $this->latestTag(); + + $this->taskExec( "composer create-project {$package} {$name} {$version}" ) + ->dir( __DIR__ . '/release' ) + ->arg( '--prefer-dist' ) + ->arg( '--no-install' ) + ->run(); + + if ( $php ) { + $this->taskExec( "composer config platform.php {$php}" ) + ->dir( __DIR__ . "/release/{$name}" ) + ->run(); + } + + $this->taskExec( 'composer remove composer/installers --no-update' ) + ->dir( __DIR__ . "/release/{$name}" ) + ->run(); + + $this->taskExec( 'composer update --no-dev --optimize-autoloader' ) + ->dir( __DIR__ . "/release/{$name}" ) + ->run(); + + $zipFile = "release/{$name}.zip"; + + $this->_remove( $zipFile ); + + $this->taskPack( $zipFile ) + ->addDir( $name, "release/{$name}" ) + ->run(); + + $this->_deleteDir( "release/{$name}" ); + } + /** * Updates version in header and makes git version tag. * @@ -83,12 +135,13 @@ class RoboFile extends \Robo\Tasks { */ public function tag( $version ) { - $this->versionSet( $version ); + $this->makeVersion( $version ); $this->taskGitStack() ->stopOnFail() + ->add( 'CHANGELOG.md' ) ->add( 'laps.php' ) - ->commit( "Updated header version to {$version}" ) + ->commit( "Released version $version" ) ->tag( $version ) ->run(); } @@ -98,11 +151,31 @@ class RoboFile extends \Robo\Tasks { * * @param string $version Version string. */ - public function versionSet( $version ) { + public function makeVersion( $version ) { + + $this->taskReplaceInFile( 'CHANGELOG.md' ) + ->from( '## Unreleased' ) + ->to( '## Unreleased' . PHP_EOL . PHP_EOL . "## $version - " . date_format( date_create(), 'Y-m-d' ) ) + ->run(); $this->taskReplaceInFile( 'laps.php' ) ->regex( '|^Version:.*$|m' ) ->to( 'Version: ' . $version ) ->run(); } + + public function upload() { + $version = $this->latestTag(); + $zipFile = __DIR__ . '/release/laps.zip'; + + $this->makeArchive(); + $this->_exec("gh release upload $version $zipFile"); + $this->_remove( $zipFile ); + } + + private function latestTag(): string { + $commit = escapeshellarg( exec( 'git rev-list --tags --max-count=1' ) ); + + return escapeshellarg( exec( "git describe --tags {$commit}" ) ); + } }