-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatic packaging with Robo task runner
- Loading branch information
Showing
4 changed files
with
3,472 additions
and
1,693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ | |
.vscode/ export-ignore | ||
tests/ export-ignore | ||
|
||
RoboFile.php export-ignore | ||
|
||
*.psd export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.