This repository has been archived by the owner on Apr 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from chelout/sentry
Adding a Sentry recipe
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |