Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move slack notification into the blt command #1464

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions blt/src/Blt/Plugin/Commands/HsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class HsCommands extends BltTasks {
*
* @aliases humsci:post-code-update
*/
public function postCodeDeployUpdate() {
public function postCodeDeployUpdate($target_env, $deployed_tag) {
$sites = $this->getConfigValue('multisites');
$parallel_executions = 10;
$parallel_executions = (int) getenv('UPDATE_PARALLEL_PROCESSES') ?: 10;

$site_chunks = array_chunk($sites, ceil(count($sites) / $parallel_executions));
$commands = [];
foreach ($site_chunks as $sites) {
Expand All @@ -50,11 +51,42 @@ public function postCodeDeployUpdate() {
$failed[] = $site;
}
}
unlink(sys_get_temp_dir() . '/update-report.txt');

$this->yell(sprintf('Updated %s sites successfully.', count($success)), 100);

if ($failed) {
$this->yell(sprintf("Update failed for the following sites:\n%s", implode("\n", $failed)), 100, 'red');

if (in_array($target_env, ['prod', 'test'])) {
$count = count($failed);
$this->sendSlackNotification("A new deployment has been made to *$target_env* using *$deployed_tag*.\n\n*$count* sites failed to update.");
}
throw new \Exception('Failed update');
}
unlink(sys_get_temp_dir() . '/update-report.txt');

if (in_array($target_env, ['prod', 'test'])) {
$this->sendSlackNotification("A new deployment has been made to *$target_env* using *$deployed_tag*.");
}
}

/**
* Send out a slack notification.
*
* @param string $message
* Slack message.
*/
protected function sendSlackNotification(string $message) {
$client = new Client();
$client->post(getenv('SLACK_NOTIFICATION_URL'), [
'form_params' => [
'payload' => json_encode([
'username' => 'Acquia Cloud',
'text' => $message,
'icon_emoji' => 'information_source',
]),
],
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion hooks/common/post-code-deploy/post-code-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ repo_root="/var/www/html/$site.$target_env"
export PATH=$repo_root/vendor/bin:$PATH
cd $repo_root

blt humsci:post-code-deploy
blt humsci:post-code-deploy $target_env $deployed_tag

set +v
2 changes: 1 addition & 1 deletion hooks/common/post-code-update/post-code-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ repo_root="/var/www/html/$site.$target_env"
export PATH=$repo_root/vendor/bin:$PATH
cd $repo_root

blt humsci:post-code-deploy
blt humsci:post-code-deploy $target_env $deployed_tag

set +v
24 changes: 0 additions & 24 deletions hooks/prod/post-code-deploy/slack.sh

This file was deleted.

Empty file.
24 changes: 0 additions & 24 deletions hooks/test/post-code-update/slack.sh

This file was deleted.