-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature_init.php
More file actions
75 lines (66 loc) 路 2.46 KB
/
Copy pathfeature_init.php
File metadata and controls
75 lines (66 loc) 路 2.46 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
<?php
namespace Deployer;
require_once('url_shortener.php');
require_once('feature_list.php');
require_once(__DIR__ . '/../../functions.php');
task('feature:init', function () {
checkVerbosity();
if (!featureRequested()) {
debug('No feature given, staying on the base instance');
return;
}
// extend deploy path / public url
initFeature();
})
->select('type=feature-branch-deployment')
->once()
->desc('Initialize a feature branch');
task('feature:select', function () {
checkVerbosity();
// extend deploy path / public url, asking for the feature if none was given
initFeature();
})
->select('type=feature-branch-deployment')
->once()
->desc('Select a feature branch and initialize it');
/**
* Initialize a feature branch
* (!: needed for all deployer tasks considering a feature branch)
*
* @param ?string $feature
* @return ?string
* @throws \Deployer\Exception\Exception
* @throws \Deployer\Exception\RunException
* @throws \Deployer\Exception\TimeoutException
* @throws \Exception
*/
function initFeature(?string $feature = null): ?string
{
debug('Initializing feature instance');
set('deploy_base_path', get('deploy_path'));
// check if feature was already initialized
if (has('feature_initialized') && get('feature_initialized')) return get('feature');;
prepareDeployerConfiguration();
// use feature variable or feature input option or ask for feature branch
$feature = $feature ?: (featureRequested() ? input()->getOption('feature') : askChoice('Please select a feature branch', array_map(function ($array) {
return $array[2];
}, listFeatureInstances())));
set('feature', $feature);
if (isUrlShortener()) {
// initialize the url shortener function
initUrlShortener($feature);
set('npm_variables', 'FEATURE_BRANCH_PATH_PUBLIC=/' . $feature . ' ');
} else {
// extend deploy path with feature directory
set('deploy_path', get('deploy_path') . '/' . $feature);
// extend public url path with feature path and specific web path
$publicUrls = [];
foreach (get('public_urls') as $publicUrl) {
$publicUrls[] = $publicUrl . $feature . '/current/' . get('web_path');
}
set('public_urls', $publicUrls);
set('npm_variables', 'FEATURE_BRANCH_PATH_PUBLIC=/' . $feature . '/current/' . get('web_path') . ' ');
}
set('feature_initialized', true);
return $feature;
}