forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewrelic.php
59 lines (45 loc) · 1.38 KB
/
newrelic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/*
## Installing
Add to your _deploy.php_
```php
require 'contrib/newrelic.php';
```
## Configuration
- `newrelic_app_id` – newrelic's app id
- `newrelic_api_key` – newrelic's api key
- `newrelic_description` – message to send
## Usage
Since you should only notify New Relic of a successful deployment, the `newrelic:notify` task should be executed right at the end.
```php
after('deploy', 'newrelic:notify');
```
*/
namespace Deployer;
use Deployer\Utility\Httpie;
set('newrelic_app_id', function () {
throw new \Exception('Please, configure "newrelic_app_id" parameter.');
});
set('newrelic_description', function() {
return runLocally('git log -n 1 --format="%an: %s" | tr \'"\' "\'"');
});
set('newrelic_revision', function() {
return runLocally('git log -n 1 --format="%h"');
});
desc('Notifying New Relic of deployment');
task('newrelic:notify', function () {
if (($appId = get('newrelic_app_id')) && ($apiKey = get('newrelic_api_key'))) {
$data = [
'user' => get('user'),
'revision' => get('newrelic_revision'),
'description' => get('newrelic_description'),
];
Httpie::post("https://api.newrelic.com/v2/applications/$appId/deployments.json")
->header("X-Api-Key: $apiKey")
->query(['deployment' => $data])
->send();
}
})
->once()
->shallow()
->hidden();