-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDeploymentTest.php
More file actions
197 lines (163 loc) Β· 6.91 KB
/
DeploymentTest.php
File metadata and controls
197 lines (163 loc) Β· 6.91 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
declare(strict_types=1);
namespace DrevOps\Vortex\Tests\Functional;
use AlexSkrypnyk\File\File;
use DrevOps\Vortex\Tests\Traits\Subtests\SubtestAhoyTrait;
use DrevOps\Vortex\Tests\Traits\Subtests\SubtestDeploymentTrait;
use PHPUnit\Framework\Attributes\Group;
/**
* Tests deployment workflows.
*/
class DeploymentTest extends FunctionalTestCase {
use SubtestAhoyTrait;
use SubtestDeploymentTrait;
protected function setUp(): void {
parent::setUp();
static::$sutInstallerEnv = [];
$this->dockerCleanup();
}
#[Group('p2')]
public function testDeployment(): void {
$this->logStepStart();
static::$sutInstallerEnv = [
'VORTEX_INSTALLER_IS_DEMO' => '1',
];
$this->logSubstep('Prepare SUT without full build (structure only)');
$this->prepareSut();
$this->createInstalledDependenciesStub();
$this->logSubstep('Run webhook deployment');
$this->cmd('ahoy deploy', [
'* Started WEBHOOK deployment.',
'* Webhook call completed.',
'! [FAIL] Unable to complete webhook deployment.',
'* Finished WEBHOOK deployment.',
], txt: 'Webhook deployment should complete successfully', env: [
'VORTEX_DEPLOY_TYPES' => 'webhook',
'VORTEX_DEPLOY_WEBHOOK_URL' => 'https://www.example.com',
'VORTEX_DEPLOY_WEBHOOK_RESPONSE_STATUS' => '200',
]);
$this->logStepFinish();
}
#[Group('p3')]
public function testDeploymentSkipFlags(): void {
$this->logStepStart();
static::$sutInstallerEnv = [
'VORTEX_INSTALLER_IS_DEMO' => '1',
];
$this->logSubstep('Prepare SUT without full build (structure only)');
$this->prepareSut();
$this->createInstalledDependenciesStub();
$this->logSubstep('Subtest 1: Run deployment without skip flag set');
$this->cmd('ahoy deploy', [
'* Started WEBHOOK deployment.',
'* Finished WEBHOOK deployment.',
'! Skipping deployment webhook.',
], txt: 'Deployment should proceed without skip flag', env: [
'VORTEX_DEPLOY_TYPES' => 'webhook',
'VORTEX_DEPLOY_WEBHOOK_URL' => 'https://www.example.com',
'VORTEX_DEPLOY_WEBHOOK_RESPONSE_STATUS' => '200',
]);
$this->logSubstep('Subtest 2: Run deployment with skip flag but no per-branch skip');
$this->cmd('ahoy deploy', [
'* Found flag to skip a deployment.',
'* Started WEBHOOK deployment.',
'* Finished WEBHOOK deployment.',
'! Skipping deployment webhook.',
], txt: 'Deployment should proceed with ALLOW_SKIP but no specific skip', env: [
'VORTEX_DEPLOY_TYPES' => 'webhook',
'VORTEX_DEPLOY_WEBHOOK_URL' => 'https://www.example.com',
'VORTEX_DEPLOY_WEBHOOK_RESPONSE_STATUS' => '200',
'VORTEX_DEPLOY_ALLOW_SKIP' => '1',
]);
$this->logSubstep('Subtest 3: Run deployment with per-branch skip flag');
$this->cmd('ahoy deploy', [
'* Found flag to skip a deployment.',
'* Found skip variable VORTEX_DEPLOY_SKIP_BRANCH_FEATURE_TEST',
'* Skipping deployment webhook.',
'! Started WEBHOOK deployment.',
'! Finished WEBHOOK deployment.',
], txt: 'Deployment should be skipped for feature/test branch', env: [
'VORTEX_DEPLOY_TYPES' => 'webhook',
'VORTEX_DEPLOY_WEBHOOK_URL' => 'https://www.example.com',
'VORTEX_DEPLOY_WEBHOOK_RESPONSE_STATUS' => '200',
'VORTEX_DEPLOY_ALLOW_SKIP' => '1',
'VORTEX_DEPLOY_BRANCH' => 'feature/test',
'VORTEX_DEPLOY_SKIP_BRANCH_FEATURE_TEST' => '1',
]);
$this->logSubstep('Subtest 4: Run deployment with per-PR skip flag');
$this->cmd('ahoy deploy', [
'* Found flag to skip a deployment.',
'* Found skip variable VORTEX_DEPLOY_SKIP_PR_123',
'* Skipping deployment webhook.',
'! Started WEBHOOK deployment.',
'! Finished WEBHOOK deployment.',
], txt: 'Deployment should be skipped for PR 123', env: [
'VORTEX_DEPLOY_TYPES' => 'webhook',
'VORTEX_DEPLOY_WEBHOOK_URL' => 'https://www.example.com',
'VORTEX_DEPLOY_WEBHOOK_RESPONSE_STATUS' => '200',
'VORTEX_DEPLOY_ALLOW_SKIP' => '1',
'VORTEX_DEPLOY_PR' => '123',
'VORTEX_DEPLOY_SKIP_PR_123' => '1',
]);
$this->logSubstep('Subtest 5: Run deployment without skip flag but with per-PR');
$this->cmd('ahoy deploy', [
'* Started WEBHOOK deployment.',
'* Finished WEBHOOK deployment.',
'! Found flag to skip a deployment.',
'! Skipping deployment webhook.',
], txt: 'Deployment should proceed when ALLOW_SKIP is not set', env: [
'VORTEX_DEPLOY_TYPES' => 'webhook',
'VORTEX_DEPLOY_WEBHOOK_URL' => 'https://www.example.com',
'VORTEX_DEPLOY_WEBHOOK_RESPONSE_STATUS' => '200',
'VORTEX_DEPLOY_PR' => '123',
'VORTEX_DEPLOY_SKIP_PR_123' => '1',
]);
$this->logStepFinish();
}
#[Group('p2')]
public function testDeploymentArtifact(): void {
$this->logStepStart();
static::$sutInstallerEnv = [
'VORTEX_INSTALLER_IS_DEMO' => '1',
// Add trailing comma to simulate list input.
'VORTEX_INSTALLER_PROMPT_DEPLOY_TYPES' => 'artifact,',
];
$this->logSubstep('Prepare SUT with full build');
$this->prepareSut();
$this->adjustAhoyForUnmountedVolumes();
$this->logSubstep('Build site');
$this->subtestAhoyBuild();
$this->syncToHost();
$this->logSubstep('Prepare deployment directories');
$src_dir = static::$workspace . '/deployment_src';
$remote_dir = static::$workspace . '/deployment_remote';
$this->prepareDeploymentSource($src_dir);
$this->prepareRemoteRepository($remote_dir);
$this->logSubstep('Copy built codebase to deployment source');
// Copy everything including .git directory to match BATS test behavior.
// The deployment artifact script expects the source to be a git repository
// with .gitignore.artifact already present.
File::copy(static::$sut . '/.', $src_dir . '/');
$this->logSubstep('Create excluded directory (should be ignored in artifact)');
File::mkdir($src_dir . '/web/themes/custom/star_wars/node_modules');
File::dump($src_dir . '/web/themes/custom/star_wars/node_modules/test.txt', '');
$this->logSubstep('Run artifact deployment');
$this->cmd('ahoy deploy', [
'* Started ARTIFACT deployment.',
'* Installing artifact builder.',
'* Copying git repo files meta file to the deploy code repo.',
'* Copying deployment .gitignore as it may not exist in deploy code source files.',
'* Running artifact builder.',
'* Finished ARTIFACT deployment.',
], txt: 'Artifact deployment should complete successfully', env: [
'VORTEX_DEPLOY_TYPES' => 'artifact',
'VORTEX_DEPLOY_ARTIFACT_GIT_REMOTE' => $remote_dir . '/.git',
'VORTEX_DEPLOY_ARTIFACT_ROOT' => static::$sut,
'VORTEX_DEPLOY_ARTIFACT_SRC' => $src_dir,
'VORTEX_DEPLOY_ARTIFACT_GIT_USER_EMAIL' => 'testuser@example.com',
]);
$this->logSubstep('Assert deployment files in remote repository');
$this->assertDeploymentFilesPresent($remote_dir);
$this->logStepFinish();
}
}