mirror of
https://github.com/deployphp/deployer.git
synced 2025-01-17 21:48:58 +01:00
Added support for ntfy.sh notifications, contrib/ntfy (#3522)
* Fixed typo * Added support for ntfy.sh notifications, contrib/ntfy recipe * Missing docs --------- Co-authored-by: HereticPilgrim <manuel.grauwiler@transformatik.ch>
This commit is contained in:
parent
a8fca445c3
commit
4a4e69a8c5
@ -9,7 +9,7 @@ Setup:
|
||||
2. Navigate to Teams section
|
||||
3. Select existing or create new team
|
||||
4. Select existing or create new channel
|
||||
5. Hover over channel to get tree dots, click, in menu select "Connectors"
|
||||
5. Hover over channel to get three dots, click, in menu select "Connectors"
|
||||
6. Search for and configure "Incoming Webhook"
|
||||
7. Confirm/create and copy your Webhook URL
|
||||
8. Setup deploy.php
|
||||
|
158
contrib/ntfy.php
Normal file
158
contrib/ntfy.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/*
|
||||
## Installing
|
||||
|
||||
Require ntfy.sh recipe in your `deploy.php` file:
|
||||
|
||||
Setup:
|
||||
1. Setup deploy.php
|
||||
Add in header:
|
||||
```php
|
||||
require 'contrib/ntfy.php';
|
||||
set('ntfy_topic', 'ntfy.sh/mytopic');
|
||||
```
|
||||
Add in content:
|
||||
```php
|
||||
before('deploy', 'ntfy:notify');
|
||||
after('deploy:success', 'ntfy:notify:success');
|
||||
after('deploy:failed', 'ntfy:notify:failure');
|
||||
```
|
||||
9.) Sip your coffee
|
||||
|
||||
## Configuration
|
||||
|
||||
- `ntfy_server` – ntfy server url, default `ntfy.sh`
|
||||
```
|
||||
set('ntfy_server', 'ntfy.sh');
|
||||
```
|
||||
- `ntfy_topic` – ntfy topic, **required**
|
||||
```
|
||||
set('ntfy_topic', 'mysecrettopic');
|
||||
```
|
||||
- `ntfy_title` – the title of the message, default `{{application}}`
|
||||
- `ntfy_text` – notification message template
|
||||
```
|
||||
set('ntfy_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
|
||||
```
|
||||
- `ntfy_tags` – notification message tags / emojis (comma separated)
|
||||
```
|
||||
set('ntfy_tags', `information_source`);
|
||||
```
|
||||
- `ntfy_priority` – notification message priority (integer)
|
||||
```
|
||||
set('ntfy_priority', 5);
|
||||
```
|
||||
- `ntfy_success_text` – success template, default:
|
||||
```
|
||||
set('ntfy_success_text', 'Deploy to *{{target}}* successful');
|
||||
```
|
||||
- `ntfy_success_tags` – success tags / emojis (comma separated)
|
||||
```
|
||||
set('ntfy_success_tags', `white_check_mark,champagne`);
|
||||
```
|
||||
- `ntfy_success_priority` – success notification message priority
|
||||
- `ntfy_failure_text` – failure template, default:
|
||||
```
|
||||
set('ntfy_failure_text', 'Deploy to *{{target}}* failed');
|
||||
```
|
||||
- `ntfy_failure_tags` – failure tags / emojis (comma separated)
|
||||
```
|
||||
set('ntfy_failure_tags', `warning,skull`);
|
||||
```
|
||||
- `ntfy_failure_priority` – failure notification message priority
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
If you want to notify only about beginning of deployment add this line only:
|
||||
|
||||
```php
|
||||
before('deploy', 'ntfy:notify');
|
||||
```
|
||||
|
||||
If you want to notify about successful end of deployment add this too:
|
||||
|
||||
```php
|
||||
after('deploy:success', 'ntfy:notify:success');
|
||||
```
|
||||
|
||||
If you want to notify about failed deployment add this too:
|
||||
|
||||
```php
|
||||
after('deploy:failed', 'ntfy:notify:failure');
|
||||
```
|
||||
*/
|
||||
namespace Deployer;
|
||||
|
||||
use Deployer\Utility\Httpie;
|
||||
|
||||
set('ntfy_server', 'ntfy.sh');
|
||||
|
||||
// Title of project
|
||||
set('ntfy_title', function () {
|
||||
return get('application', 'Project');
|
||||
});
|
||||
|
||||
// Deploy message
|
||||
set('ntfy_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
|
||||
set('ntfy_success_text', 'Deploy to *{{target}}* successful');
|
||||
set('ntfy_failure_text', 'Deploy to *{{target}}* failed');
|
||||
|
||||
// Message tags
|
||||
set('ntfy_tags', '');
|
||||
set('ntfy_success_tags', '');
|
||||
set('ntfy_failure_tags', '');
|
||||
|
||||
desc('Notifies ntfy server');
|
||||
task('ntfy:notify', function () {
|
||||
if (!get('ntfy_topic', false)) {
|
||||
warning('No ntfy topic configured');
|
||||
return;
|
||||
}
|
||||
|
||||
Httpie::post(get('ntfy_server'))->jsonBody([
|
||||
"topic" => get('ntfy_topic'),
|
||||
"title" => get('ntfy_title'),
|
||||
"message" => get('ntfy_text'),
|
||||
"tags" => explode(",", get('ntfy_tags')),
|
||||
"priority" => get('ntfy_priority'),
|
||||
])->send();
|
||||
})
|
||||
->once()
|
||||
->hidden();
|
||||
|
||||
desc('Notifies ntfy server about deploy finish');
|
||||
task('ntfy:notify:success', function () {
|
||||
if (!get('ntfy_topic', false)) {
|
||||
warning('No ntfy topic configured');
|
||||
return;
|
||||
}
|
||||
|
||||
Httpie::post(get('ntfy_server'))->jsonBody([
|
||||
"topic" => get('ntfy_topic'),
|
||||
"title" => get('ntfy_title'),
|
||||
"message" => get('ntfy_success_text'),
|
||||
"tags" => explode(",", get('ntfy_success_tags')),
|
||||
"priority" => get('ntfy_success_priority'),
|
||||
])->send();
|
||||
})
|
||||
->once()
|
||||
->hidden();
|
||||
|
||||
desc('Notifies ntfy server about deploy failure');
|
||||
task('ntfy:notify:failure', function () {
|
||||
if (!get('ntfy_topic', false)) {
|
||||
warning('No ntfy topic configured');
|
||||
return;
|
||||
}
|
||||
|
||||
Httpie::post(get('ntfy_server'))->jsonBody([
|
||||
"topic" => get('ntfy_topic'),
|
||||
"title" => get('ntfy_title'),
|
||||
"message" => get('ntfy_failure_text'),
|
||||
"tags" => explode(",", get('ntfy_failure_tags')),
|
||||
"priority" => get('ntfy_failure_priority'),
|
||||
])->send();
|
||||
})
|
||||
->once()
|
||||
->hidden();
|
@ -17,6 +17,7 @@
|
||||
* [Ms-teams Recipe](/docs/contrib/ms-teams.md)
|
||||
* [Newrelic Recipe](/docs/contrib/newrelic.md)
|
||||
* [Npm Recipe](/docs/contrib/npm.md)
|
||||
* [Ntfy Recipe](/docs/contrib/ntfy.md)
|
||||
* [Phinx Recipe](/docs/contrib/phinx.md)
|
||||
* [Php-fpm Recipe](/docs/contrib/php-fpm.md)
|
||||
* [Rabbit Recipe](/docs/contrib/rabbit.md)
|
||||
|
@ -21,7 +21,7 @@ Setup:
|
||||
2. Navigate to Teams section
|
||||
3. Select existing or create new team
|
||||
4. Select existing or create new channel
|
||||
5. Hover over channel to get tree dots, click, in menu select "Connectors"
|
||||
5. Hover over channel to get three dots, click, in menu select "Connectors"
|
||||
6. Search for and configure "Incoming Webhook"
|
||||
7. Confirm/create and copy your Webhook URL
|
||||
8. Setup deploy.php
|
||||
|
196
docs/contrib/ntfy.md
Normal file
196
docs/contrib/ntfy.md
Normal file
@ -0,0 +1,196 @@
|
||||
<!-- DO NOT EDIT THIS FILE! -->
|
||||
<!-- Instead edit contrib/ntfy.php -->
|
||||
<!-- Then run bin/docgen -->
|
||||
|
||||
# Ntfy Recipe
|
||||
|
||||
```php
|
||||
require 'contrib/ntfy.php';
|
||||
```
|
||||
|
||||
[Source](/contrib/ntfy.php)
|
||||
|
||||
|
||||
|
||||
## Installing
|
||||
|
||||
Require ntfy.sh recipe in your `deploy.php` file:
|
||||
|
||||
Setup:
|
||||
1. Setup deploy.php
|
||||
Add in header:
|
||||
```php
|
||||
require 'contrib/ntfy.php';
|
||||
set('ntfy_topic', 'ntfy.sh/mytopic');
|
||||
```
|
||||
Add in content:
|
||||
```php
|
||||
before('deploy', 'ntfy:notify');
|
||||
after('deploy:success', 'ntfy:notify:success');
|
||||
after('deploy:failed', 'ntfy:notify:failure');
|
||||
```
|
||||
9.) Sip your coffee
|
||||
|
||||
## Configuration
|
||||
|
||||
- `ntfy_server` – ntfy server url, default `ntfy.sh`
|
||||
```
|
||||
set('ntfy_server', 'ntfy.sh');
|
||||
```
|
||||
- `ntfy_topic` – ntfy topic, **required**
|
||||
```
|
||||
set('ntfy_topic', 'mysecrettopic');
|
||||
```
|
||||
- `ntfy_title` – the title of the message, default `{{application}}`
|
||||
- `ntfy_text` – notification message template
|
||||
```
|
||||
set('ntfy_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
|
||||
```
|
||||
- `ntfy_tags` – notification message tags / emojis (comma separated)
|
||||
```
|
||||
set('ntfy_tags', `information_source`);
|
||||
```
|
||||
- `ntfy_priority` – notification message priority (integer)
|
||||
```
|
||||
set('ntfy_priority', 5);
|
||||
```
|
||||
- `ntfy_success_text` – success template, default:
|
||||
```
|
||||
set('ntfy_success_text', 'Deploy to *{{target}}* successful');
|
||||
```
|
||||
- `ntfy_success_tags` – success tags / emojis (comma separated)
|
||||
```
|
||||
set('ntfy_success_tags', `white_check_mark,champagne`);
|
||||
```
|
||||
- `ntfy_success_priority` – success notification message priority
|
||||
- `ntfy_failure_text` – failure template, default:
|
||||
```
|
||||
set('ntfy_failure_text', 'Deploy to *{{target}}* failed');
|
||||
```
|
||||
- `ntfy_failure_tags` – failure tags / emojis (comma separated)
|
||||
```
|
||||
set('ntfy_failure_tags', `warning,skull`);
|
||||
```
|
||||
- `ntfy_failure_priority` – failure notification message priority
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
If you want to notify only about beginning of deployment add this line only:
|
||||
|
||||
```php
|
||||
before('deploy', 'ntfy:notify');
|
||||
```
|
||||
|
||||
If you want to notify about successful end of deployment add this too:
|
||||
|
||||
```php
|
||||
after('deploy:success', 'ntfy:notify:success');
|
||||
```
|
||||
|
||||
If you want to notify about failed deployment add this too:
|
||||
|
||||
```php
|
||||
after('deploy:failed', 'ntfy:notify:failure');
|
||||
```
|
||||
|
||||
|
||||
## Configuration
|
||||
### ntfy_server
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L89)
|
||||
|
||||
|
||||
|
||||
```php title="Default value"
|
||||
'ntfy.sh'
|
||||
```
|
||||
|
||||
|
||||
### ntfy_title
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L92)
|
||||
|
||||
Title of project
|
||||
|
||||
```php title="Default value"
|
||||
return get('application', 'Project');
|
||||
```
|
||||
|
||||
|
||||
### ntfy_text
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L97)
|
||||
|
||||
Deploy message
|
||||
|
||||
```php title="Default value"
|
||||
'_{{user}}_ deploying `{{branch}}` to *{{target}}*'
|
||||
```
|
||||
|
||||
|
||||
### ntfy_success_text
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L98)
|
||||
|
||||
|
||||
|
||||
```php title="Default value"
|
||||
'Deploy to *{{target}}* successful'
|
||||
```
|
||||
|
||||
|
||||
### ntfy_failure_text
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L99)
|
||||
|
||||
|
||||
|
||||
```php title="Default value"
|
||||
'Deploy to *{{target}}* failed'
|
||||
```
|
||||
|
||||
|
||||
### ntfy_tags
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L102)
|
||||
|
||||
Message tags
|
||||
|
||||
|
||||
|
||||
### ntfy_success_tags
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L103)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### ntfy_failure_tags
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L104)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Tasks
|
||||
|
||||
### ntfy:notify
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L107)
|
||||
|
||||
Notifies ntfy server.
|
||||
|
||||
|
||||
|
||||
|
||||
### ntfy:notify:success
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L125)
|
||||
|
||||
Notifies ntfy server about deploy finish.
|
||||
|
||||
|
||||
|
||||
|
||||
### ntfy:notify:failure
|
||||
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ntfy.php#L143)
|
||||
|
||||
Notifies ntfy server about deploy failure.
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user