Adjusted release-related commands
This commit is contained in:
1 parent
9f3f2483f5
commit
430919bcdf
1 file changed
+78
-5
+78
-5
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
@@ -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}" ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user