-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add Tideways deployment notification task #4123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
peterjaap
wants to merge
4
commits into
master
Choose a base branch
from
tideways-recipe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,151 @@ | ||
| <?php | ||
| /* | ||
|
|
||
| ### Configuration options | ||
|
|
||
| - **api_key** *(required)*: Tideways API key for authentication. | ||
| - **version** *(required)*: A version identifier for this release. Can be a version number, a commit hash etc. (Default is set to git log -n 1 --format="%h".) | ||
| - **environment** *(optional)*: The environment you're deploying to. Defaults to 'production'. | ||
| - **service** *(optional)*: The service name for the release. Defaults to 'web'. | ||
| - **compare_after_minutes** *(optional)*: Time in minutes to compare performance before/after release. Defaults to 90. | ||
| - **project** *(optional)*: Project name/path for the description field. | ||
| - **description** *(optional)*: Custom description for the release. | ||
| - **tideways_server** *(optional)*: Tideways server URL. Defaults to 'https://app.tideways.io'. | ||
| - **git_version_command** *(optional)*: The command that retrieves the git version information. Defaults to 'git log -n 1 --format="%h"'. | ||
|
|
||
| ```php | ||
| // deploy.php | ||
|
|
||
| set('tideways', [ | ||
| 'api_key' => 'your-api-key', | ||
| 'version' => '', | ||
| 'environment' => 'production', | ||
| 'service' => 'web', | ||
| 'compare_after_minutes' => 90, | ||
| ]); | ||
| ``` | ||
|
|
||
| ### Suggested Usage | ||
|
|
||
| Since you should only notify Tideways of a successful deployment, the deploy:tideways task should be executed right at the end. | ||
|
|
||
| ```php | ||
| // deploy.php | ||
|
|
||
| after('deploy:success', 'deploy:tideways'); | ||
| ``` | ||
|
|
||
| */ | ||
|
|
||
| namespace Deployer; | ||
|
|
||
| use Deployer\Utility\Httpie; | ||
|
|
||
| desc('Notifies Tideways of deployment'); | ||
| task( | ||
| 'deploy:tideways', | ||
| static function () { | ||
| $defaultConfig = [ | ||
| 'version' => getReleaseGitRef(), | ||
| 'environment' => 'production', | ||
| 'service' => 'web', | ||
| 'compare_after_minutes' => 90, | ||
| 'project' => null, | ||
| 'description' => null, | ||
| 'tideways_server' => 'https://app.tideways.io', | ||
| ]; | ||
|
|
||
| $config = array_merge($defaultConfig, (array) get('tideways')); | ||
| array_walk( | ||
| $config, | ||
| static function (&$value) use ($config) { | ||
| if (is_callable($value)) { | ||
| $value = $value($config); | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| if (!isset($config['api_key']) || empty($config['api_key'])) { | ||
| writeln('<comment>Skipping Tideways release creation: api_key not set</comment>'); | ||
| return; | ||
| } | ||
|
|
||
| if (!isset($config['version']) || empty($config['version'])) { | ||
| throw new \RuntimeException( | ||
| <<<EXAMPLE | ||
| Required data missing. Please configure tideways: | ||
| set( | ||
| 'tideways', | ||
| [ | ||
| 'api_key' => 'your-api-key', | ||
| 'version' => '1.0.0', | ||
| ] | ||
| ); | ||
| EXAMPLE, | ||
| ); | ||
| } | ||
|
|
||
| $payload = [ | ||
| 'apiKey' => $config['api_key'], | ||
| 'name' => $config['version'], | ||
| 'type' => 'release', | ||
| 'environment' => $config['environment'], | ||
| 'service' => $config['service'], | ||
| 'compareAfterMinutes' => (int) $config['compare_after_minutes'], | ||
| ]; | ||
|
|
||
| // Add description if provided or generate from project | ||
| if (!empty($config['description'])) { | ||
| $payload['description'] = $config['description']; | ||
| } elseif (!empty($config['project'])) { | ||
| $payload['description'] = "Release {$config['version']} for project {$config['project']}"; | ||
| } | ||
|
|
||
| $eventsApiUrl = $config['tideways_server'] . '/api/events'; | ||
|
|
||
| try { | ||
| Httpie::post($eventsApiUrl) | ||
| ->setopt(CURLOPT_TIMEOUT, 10) | ||
| ->header('Content-Type', 'application/json') | ||
| ->body(json_encode($payload)) | ||
| ->send(); | ||
|
|
||
| writeln( | ||
| sprintf( | ||
| '<info>Tideways:</info> Release <comment>%s</comment> ' . | ||
| 'for environment <comment>%s</comment> and service <comment>%s</comment> created successfully.', | ||
| $config['version'], | ||
| $config['environment'], | ||
| $config['service'], | ||
| ), | ||
| ); | ||
| } catch (\Throwable $e) { | ||
| writeln('<error>Failed to create Tideways release: ' . $e->getMessage() . '</error>'); | ||
| throw $e; | ||
| } | ||
| }, | ||
| ); | ||
|
|
||
| function getReleaseGitRef(): \Closure | ||
| { | ||
| return static function ($config = []): string { | ||
| if (get('update_code_strategy') === 'archive') { | ||
| if (isset($config['git_version_command'])) { | ||
| cd('{{deploy_path}}/.dep/repo'); | ||
|
|
||
| return trim(run($config['git_version_command'])); | ||
| } | ||
|
|
||
| return run('cat {{current_path}}/REVISION'); | ||
| } | ||
|
|
||
| cd('{{release_path}}'); | ||
|
|
||
| if (isset($config['git_version_command'])) { | ||
| return trim(run($config['git_version_command'])); | ||
| } | ||
|
|
||
| return trim(run('git log -n 1 --format="%h"')); | ||
| }; | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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,43 @@ | ||
| <!-- DO NOT EDIT THIS FILE! --> | ||
| <!-- Instead edit contrib/tideways.php --> | ||
| <!-- Then run bin/docgen --> | ||
|
|
||
| # Tideways Recipe | ||
|
|
||
| ```php | ||
| require 'contrib/tideways.php'; | ||
| ``` | ||
|
|
||
| [Source](/contrib/tideways.php) | ||
|
|
||
|
|
||
|
|
||
| ### Configuration options | ||
| - **api_key** *(required)*: Tideways API key for authentication. | ||
| - **version** *(required)*: A version identifier for this release. Can be a version number, a commit hash etc. (Default is set to git log -n 1 --format="%h".) | ||
| - **environment** *(optional)*: The environment you're deploying to. Defaults to 'production'. | ||
| - **service** *(optional)*: The service name for the release. Defaults to 'web'. | ||
| - **compare_after_minutes** *(optional)*: Time in minutes to compare performance before/after release. Defaults to 90. | ||
| - **project** *(optional)*: Project name/path for the description field. | ||
| - **description** *(optional)*: Custom description for the release. | ||
| - **tideways_server** *(optional)*: Tideways server URL. Defaults to 'https://app.tideways.io'. | ||
| - **git_version_command** *(optional)*: The command that retrieves the git version information. Defaults to 'git log -n 1 --format="%h"'. | ||
| ```php | ||
| deploy.php | ||
| set('tideways', [ | ||
| 'api_key' => 'your-api-key', | ||
| 'version' => '', | ||
| 'environment' => 'production', | ||
| 'service' => 'web', | ||
| 'compare_after_minutes' => 90, | ||
| ]); | ||
| ``` | ||
| ### Suggested Usage | ||
| Since you should only notify Tideways of a successful deployment, the deploy:tideways task should be executed right at the end. | ||
| ```php | ||
| deploy.php | ||
| after('deploy:success', 'deploy:tideways'); | ||
| ``` | ||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.