Skip to content

Commit

Permalink
Add automatic packaging with Robo task runner
Browse files Browse the repository at this point in the history
  • Loading branch information
jon48 committed Jun 7, 2020
1 parent 083bf0b commit 0c8feee
Show file tree
Hide file tree
Showing 4 changed files with 3,472 additions and 1,693 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
.vscode/ export-ignore
tests/ export-ignore

RoboFile.php export-ignore

*.psd export-ignore
93 changes: 93 additions & 0 deletions RoboFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Robo tasks - Rural theme
*
* @see http://robo.li/
*/

use Robo\Robo;
use Symfony\Component\Finder\Finder;

class RoboFile extends \Robo\Tasks
{

/**
* Package the specific commitish in a zip file for distribution.
* Commitish can be a commit hash, a tag, or a branch.
*
* @param string $commit Commitish to be packaged
* @throws \Exception
* @return \Robo\Result
*/
function package($commit = 'master') {
$getCommitResult =
$this->taskExec("git rev-parse --quiet --verify $commit")
->interactive(false)
->run();
if(!$getCommitResult->wasSuccessful() || $getCommitResult->getMessage() === '') {
throw new \Exception('The commit requested does not exist');
}

$collection = $this->collectionBuilder();

$workDir = $collection->workDir("build/release.tmp");

$PROJECT_NAME = 'webtrees-theme-rural';
$THEME_DIR = 'myartjaub_ruraltheme';

$output_name = "rural-webtrees-$commit";
$output_name = str_replace('.', '_', str_replace('-v.', '.', $output_name));

$build_archive_dir = "$workDir/$output_name.build";
$build_archive_zip = "$build_archive_dir.zip";

$build_release_path = "build/$output_name.zip";

$buildTasks = $this->collectionBuilder();

$buildTasksResult = $buildTasks
->taskFilesystemStack()
->mkdir($workDir)
->progressMessage("Starting build of $PROJECT_NAME $commit")
->progressMessage("Export git archive at commit $commit")
->taskExec("git archive --format=zip --output=$build_archive_zip $commit")
->taskExtract($build_archive_zip)
->to($build_archive_dir)
->taskComposerInstall()
->dir($build_archive_dir)
//->taskNpmInstall() // Does not handle paths with space
->taskExec("npm install --no-fund")
->dir($build_archive_dir)
->taskExec("npm run production")
->dir($build_archive_dir)
->progressMessage("Build of $PROJECT_NAME $commit completed!")
->run();

// Exit if the build step failed
if (!$buildTasksResult->wasSuccessful()) {
return $buildTasksResult;
}

$filesToDelete = Finder::create()
->in($build_archive_dir)
->name('composer*.*')
->name('package*.*')
->name('webpack*.*');

$collection
->progressMessage("Starting packaging of $PROJECT_NAME $commit")
->taskDeleteDir("$build_archive_dir/build")
->taskDeleteDir("$build_archive_dir/node_modules")
->taskDeleteDir("$build_archive_dir/src")
->taskDeleteDir("$build_archive_dir/vendor") // This line tends to fail on Windows - Permission denied
->taskFilesystemStack()
->remove($filesToDelete)
->taskPack($build_release_path)
->addDir($THEME_DIR, $build_archive_dir)
->taskDeleteDir($workDir)
->progressMessage("Package created: $build_release_path !!!")
;

return $collection->run();
}
}
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@
}
},
"require-dev" : {
"fisharebest/webtrees" : "~2.0.4"
"fisharebest/webtrees" : "~2.0.4",
"consolidation/robo": "^2.1"
},
"scripts": {
"webtrees-theme-rural:package": [
"./vendor/bin/robo package"
]
},
"scripts-descriptions": {
"webtrees-theme-rural:package": "Create a package file for distribution. Add -- commit for specific commit."
},
"extra" : {
"installer-name" : "myartjaub_ruraltheme"
Expand Down
Loading

0 comments on commit 0c8feee

Please sign in to comment.