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 2 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
39 changes: 36 additions & 3 deletions blt/src/Blt/Plugin/Commands/HsCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ class HsCommands extends BltTasks {

use HsCommandTrait;

const UPDATE_PARALLEL_PROCESSES = 'UPDATE_PARALLEL_PROCESSES';

/**
* After code deployed, update all sites on the stack.
*
* @command humsci:post-code-deploy
*
* @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(self::UPDATE_PARALLEL_PROCESSES) ?: 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't 100% understand the need to create the UPDATE_PARALLEL_PROCESSES constant here to call out the name of the environment variable.

Copy link
Member Author

@pookmish pookmish Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* waves hand over it *
To make it look more fancy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fancy-cat


$site_chunks = array_chunk($sites, ceil(count($sites) / $parallel_executions));
$commands = [];
foreach ($site_chunks as $sites) {
Expand All @@ -50,11 +53,41 @@ 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 (EnvironmentDetector::isAhStageEnv() || EnvironmentDetector::isAhProdEnv()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you're using these instead of $target_env?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all. I didn't really think about it. lol

$this->sendSlackNotification("A new deployment has been made to *$target_env* using *$deployed_tag*. At least one site failed updating.");
Copy link
Contributor

@joegl joegl Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not include the failed sites? Would the message be too long if too many sites failed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was kinda on the fence about it. I figured it might be less noise in Slack. Maybe we can use the number of sites that failed? then it's still short message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh I like that idea. A count would be useful without creating too much noise.

}
throw new \Exception('Failed update');
}
unlink(sys_get_temp_dir() . '/update-report.txt');

if (EnvironmentDetector::isAhStageEnv() || EnvironmentDetector::isAhProdEnv()) {
$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.