Repository navigation
Expand file tree
/
Copy pathbuild.php
More file actions
113 lines (100 loc) · 3.77 KB
/
Copy pathbuild.php
File metadata and controls
113 lines (100 loc) · 3.77 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Deployer;
/**
* Shared local-build implementation.
*
* import('vendor/generoi/deployer-genero/build.php');
*
* Only the implementations live here. The `build` and `deploy` task *lists*
* stay in each project's deploy.php on purpose: they document that project's
* pipeline, and reading deploy.php should tell you what a deploy does.
*
* `build:theme` and `cache:clear` also stay per project — they genuinely
* differ (16 and 14 distinct variants across 47 sites), unlike the tasks below,
* which were byte-identical everywhere apart from formatting.
*
* Any setting below can be overridden per project, e.g. a site that needs an
* extra path kept out of the artifact re-declares `build_artifact_exclude`.
*/
/*
* The project root, computed from this file's own location: the package is
* installed at <root>/vendor/generoi/deployer-genero, so the root is three
* levels up.
*
* __DIR__ cannot be used directly (it is the package directory), and
* Deployer\Support\deployer_root() cannot be used either — it does not exist
* in Deployer 7, which half the fleet still runs. getcwd() is the fallback for
* a non-standard install location.
*/
set('build_repository', function () {
$root = dirname(__DIR__, 3);
return is_file($root.'/composer.json') ? $root : getcwd();
});
// Named after the project directory, so concurrent builds of different projects
// cannot collide in /tmp.
//
// On GitHub Actions, build under $RUNNER_TEMP instead: from ubuntu-26.04 /tmp is
// a RAM-backed tmpfs with a ~6 GB per-user quota, which a full build exceeds
// ("Disk quota exceeded"). $RUNNER_TEMP is on the runner's disk and emptied
// after every job. https://github.com/actions/runner-images/issues/14777
set('build_path', function () {
$tmp = getenv('RUNNER_TEMP') ?: '/tmp';
return rtrim($tmp, '/').'/dep-'.basename(get('build_repository'));
});
set('build_artifact_dir', '{{build_path}}/artifact');
set('build_artifact_exclude', [
'.git',
'node_modules',
'*.sql',
'/.*',
'/*.md',
'/config/*.yml',
'/config/patches',
'/*.php',
'/*.xml',
'/*.yml',
]);
/*
* These run on the machine invoking dep, so they must use its own git and
* composer. Deployer's {{bin/git}} / {{bin/composer}} are resolved against the
* REMOTE host even inside runLocally(), and {{bin/composer}} will install
* composer.phar onto the production server when it is not found there.
*/
desc('Clone the working tree into a clean build path');
task('build:setup', function () {
runLocally('rm -rf {{build_path}}');
runLocally('mkdir -p {{build_path}}');
runLocally('git clone {{build_repository}} {{build_path}}');
});
desc('Install Composer dependencies into the build');
task('build:composer', function () {
runLocally('cd {{build_path}} && composer {{composer_action}} {{composer_options}}');
});
desc('Copy the build into a sanitised artifact directory');
task('build:artifact', function () {
$exclude = array_reduce(get('build_artifact_exclude'), function ($carry, $exclude) {
return $carry.' --exclude='.escapeshellarg($exclude);
}, '');
runLocally("rsync -r --delete --links $exclude '{{build_path}}/' '{{build_artifact_dir}}/'");
});
/*
* A sane default, in the same spirit as recipe/common.php shipping a minimal
* `deploy` that recipe/laravel.php overrides.
*
* `build:theme` is not included: it is the one step that genuinely differs per
* site (16 distinct implementations across the fleet). A project with a theme
* build overrides this list and slots it in:
*
* task('build', [
* 'build:setup',
* 'build:composer',
* 'build:theme',
* 'build:artifact',
* ]);
*/
desc('Build release locally');
task('build', [
'build:setup',
'build:composer',
'build:artifact',
]);