Refactor deployment logic and add watch path check

This commit is contained in:
Andras Bacsai 2024-04-03 14:05:35 +02:00
parent 22a1d3882e
commit b7121c5000
2 changed files with 19 additions and 15 deletions

View File

@ -311,20 +311,9 @@ class Github extends Controller
} }
if ($x_github_event === 'push') { if ($x_github_event === 'push') {
if ($application->isDeployable()) { if ($application->isDeployable()) {
$watch_files_trigger = $application->watchPathCheck($changed_files); $is_watch_path_triggered = $application->isWatchPathsTriggered($changed_files);
if (!$watch_files_trigger) { ray('Watch files trigger: ' . !$is_watch_path_triggered);
$paths = str($application->watch_paths)->explode("\n"); if ($is_watch_path_triggered || is_null($application->watch_paths)) {
$return_payloads->push([
'status' => 'failed',
'message' => 'Changed files do not match watch paths. Ignoring deployment.',
'application_uuid' => $application->uuid,
'application_name' => $application->name,
'details' => [
'changed_files' => $changed_files,
'watch_paths' => $paths,
],
]);
} else {
ray('Deploying ' . $application->name . ' with branch ' . $branch); ray('Deploying ' . $application->name . ' with branch ' . $branch);
$deployment_uuid = new Cuid2(7); $deployment_uuid = new Cuid2(7);
queue_application_deployment( queue_application_deployment(
@ -339,6 +328,18 @@ class Github extends Controller
'application_uuid' => $application->uuid, 'application_uuid' => $application->uuid,
'application_name' => $application->name, 'application_name' => $application->name,
]); ]);
} else {
$paths = str($application->watch_paths)->explode("\n");
$return_payloads->push([
'status' => 'failed',
'message' => 'Changed files do not match watch paths. Ignoring deployment.',
'application_uuid' => $application->uuid,
'application_name' => $application->name,
'details' => [
'changed_files' => $changed_files,
'watch_paths' => $paths,
],
]);
} }
} else { } else {
$return_payloads->push([ $return_payloads->push([

View File

@ -914,8 +914,11 @@ class Application extends BaseModel
} }
); );
} }
public function watchPathCheck(Collection $modified_files): bool public function isWatchPathsTriggered(Collection $modified_files): bool
{ {
if (is_null($this->watch_paths)) {
return false;
}
$watch_paths = collect(explode("\n", $this->watch_paths)); $watch_paths = collect(explode("\n", $this->watch_paths));
$matches = $modified_files->filter(function ($file) use ($watch_paths) { $matches = $modified_files->filter(function ($file) use ($watch_paths) {
return $watch_paths->contains(function ($glob) use ($file) { return $watch_paths->contains(function ($glob) use ($file) {