mirror of
https://github.com/deployphp/deployer.git
synced 2025-02-24 01:02:24 +01:00
104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
<?php
|
|
/* (c) Anton Medvedev <anton@medv.io>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Deployer;
|
|
|
|
use Deployer\Utility\Httpie;
|
|
|
|
// Title of project
|
|
set('slack_title', function () {
|
|
return get('application', 'Project');
|
|
});
|
|
|
|
// Deploy message
|
|
set('slack_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
|
|
set('slack_success_text', 'Deploy to *{{target}}* successful');
|
|
set('slack_failure_text', 'Deploy to *{{target}}* failed');
|
|
set('slack_rollback_text', '_{{user}}_ rolled back changes on *{{target}}*');
|
|
|
|
// Color of attachment
|
|
set('slack_color', '#4d91f7');
|
|
set('slack_success_color', '#00c100');
|
|
set('slack_failure_color', '#ff0909');
|
|
set('slack_rollback_color', '#eba211');
|
|
|
|
desc('Notifying Slack');
|
|
task('slack:notify', function () {
|
|
if (!get('slack_webhook', false)) {
|
|
return;
|
|
}
|
|
|
|
$attachment = [
|
|
'title' => get('slack_title'),
|
|
'text' => get('slack_text'),
|
|
'color' => get('slack_color'),
|
|
'mrkdwn_in' => ['text'],
|
|
];
|
|
|
|
Httpie::post(get('slack_webhook'))->body(['attachments' => [$attachment]])->send();
|
|
})
|
|
->once()
|
|
->shallow()
|
|
->hidden();
|
|
|
|
desc('Notifying Slack about deploy finish');
|
|
task('slack:notify:success', function () {
|
|
if (!get('slack_webhook', false)) {
|
|
return;
|
|
}
|
|
|
|
$attachment = [
|
|
'title' => get('slack_title'),
|
|
'text' => get('slack_success_text'),
|
|
'color' => get('slack_success_color'),
|
|
'mrkdwn_in' => ['text'],
|
|
];
|
|
|
|
Httpie::post(get('slack_webhook'))->body(['attachments' => [$attachment]])->send();
|
|
})
|
|
->once()
|
|
->shallow()
|
|
->hidden();
|
|
|
|
desc('Notifying Slack about deploy failure');
|
|
task('slack:notify:failure', function () {
|
|
if (!get('slack_webhook', false)) {
|
|
return;
|
|
}
|
|
|
|
$attachment = [
|
|
'title' => get('slack_title'),
|
|
'text' => get('slack_failure_text'),
|
|
'color' => get('slack_failure_color'),
|
|
'mrkdwn_in' => ['text'],
|
|
];
|
|
|
|
Httpie::post(get('slack_webhook'))->body(['attachments' => [$attachment]])->send();
|
|
})
|
|
->once()
|
|
->shallow()
|
|
->hidden();
|
|
|
|
desc('Notifying Slack about rollback');
|
|
task('slack:notify:rollback', function () {
|
|
if (!get('slack_webhook', false)) {
|
|
return;
|
|
}
|
|
|
|
$attachment = [
|
|
'title' => get('slack_title'),
|
|
'text' => get('slack_rollback_text'),
|
|
'color' => get('slack_rollback_color'),
|
|
'mrkdwn_in' => ['text'],
|
|
];
|
|
|
|
Httpie::post(get('slack_webhook'))->body(['attachments' => [$attachment]])->send();
|
|
})
|
|
->once()
|
|
->shallow()
|
|
->hidden();
|