/
RoboFile.php
94 lines (79 loc) · 3.2 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Robo tasks - Rural theme
*
* @see https://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
*/
public function package($commit = 'main')
{
$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();
}
}