Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #117 from chelout/sentry
Browse files Browse the repository at this point in the history
Adding a Sentry recipe
  • Loading branch information
antonmedv authored Mar 23, 2017
2 parents 44c72b0 + 539d7e2 commit 7cea596
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require 'vendor/deployer/recipes/cachetool.php';
| rabbit | [read](docs/rabbit.md) | `require 'vendor/deployer/recipes/rabbit.php';`
| rsync | [read](docs/rsync.md) | `require 'vendor/deployer/recipes/rsync.php';`
| slack | [read](docs/slack.md) | `require 'vendor/deployer/recipes/slack.php';`
| sentry | [read](docs/sentry.md) | `require 'vendor/deployer/recipes/sentry.php';`
| npm | [read](docs/npm.md) | `require 'vendor/deployer/recipes/npm.php';`

## Contributing a recipe
Expand Down
45 changes: 45 additions & 0 deletions docs/sentry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Sentry recipe

### Installing

```php
// deploy.php

require 'vendor/deployer/recipes/sentry.php';
```

### Configuration options

- **organization** *(required)*: the slug of the organization the release belongs to.
- **project** *(required)*: the slug of the project to create a release for.
- **token** *(required)*: authentication token. Can be created at https://sentry.io/api/
- **version** *(required)* – a version identifier for this release. Can be a version number, a commit hash etc. (Defaults is set to git log -n 1 --format="%h".)
- **ref** *(optional)* – an optional commit reference. This is useful if a tagged version has been provided.
- **url** *(optional)* – a URL that points to the release. This can be the path to an online interface to the sourcecode for instance.
- **date_started** *(optional)* – an optional date that indicates when the release process started.
- **date_released** *(optional)* – an optional date that indicates when the release went live. If not provided the current time is assumed.

```php
// deploy.php

set('sentry', [
'organization' => 'example org',
'project' => 'example proj',
'token' => 'd47828...',
'version' => '0.0.1'
]);
```

### Tasks

- `deploy:sentry` send message to Sentry

### Suggested Usage

Since you should only notify Sentry of a successfull deployment, the deploy:sentry task should be executed right at the end.

```php
// deploy.php

after('deploy', 'deploy:sentry');
```
48 changes: 48 additions & 0 deletions sentry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/* (c) Viacheslav Ostrovskiy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Deployer;

desc('Notifying Sentry of deployment');
task('deploy:sentry', function () {
global $php_errormsg;

$defaultConfig = [
'version' => trim(runLocally('git log -n 1 --format="%h"')),
'ref' => null,
'url' => null,
'date_started' => date("c"),
'date_released' => date("c"),
];

$config = array_merge($defaultConfig, (array) get('sentry'));

if (!is_array($config) || !isset($config['organization']) || !isset($config['project']) || !isset($config['token']) || !isset($config['version'])) {
throw new \RuntimeException("Please configure new sentry: set('sentry', ['organization' => 'example org', 'project' => 'example proj', 'token' => 'd47828...', 'version' => '0.0.1']);");
}

$postData = [
'version' => $config['version'],
'ref' => $config['ref'],
'url' => $config['url'],
'dateStarted' => $config['date_started'],
'dateReleased' => $config['date_released'],
];

$options = array('http' => array(
'method' => 'POST',
'header' => "Authorization: Bearer " . $config['token'] . "\r\n" . "Content-type: application/json\r\n",
'content' => json_encode($postData),
));

$context = stream_context_create($options);
$result = file_get_contents('https://sentry.io/api/0/projects/' . $config['organization'] . '/' . $config['project'] . '/releases/', false, $context);

if (!$result) {
throw new \RuntimeException($php_errormsg);
}
});

0 comments on commit 7cea596

Please sign in to comment.