diff --git a/recipes/rumvision.php b/recipes/rumvision.php new file mode 100644 index 0000000..7e0e578 --- /dev/null +++ b/recipes/rumvision.php @@ -0,0 +1,117 @@ + 'k7mbqpzs.Qm8JxL2...', + 'domains' => ['example.com'], +]); +``` + +### Suggested Usage + +Since you should only notify RUMvision of a successful deployment, the deploy:rumvision task should be executed right at the end. + +```php +// deploy.php + +after('deploy', 'deploy:rumvision'); +``` + + */ + +namespace Deployer; + +use Deployer\Utility\Httpie; + +desc('Notifies RUMvision of deployment'); +task( + 'deploy:rumvision', + static function () { + $defaultConfig = [ + 'title' => get('release_name'), + 'name_prefix' => null, + 'description' => null, + 'url_scope' => 'all', + 'url_category_ids' => null, + 'impact_at' => date('c'), + 'category_slug' => 'hosting', + 'domains' => [], + ]; + + $config = array_merge($defaultConfig, array_filter((array) get('rumvision'))); + array_walk( + $config, + static function (&$value) use ($config) { + if (is_callable($value)) { + $value = $value($config); + } + }, + ); + + if ( + empty($config['api_key']) + || empty($config['domains']) + || !is_array($config['domains']) + ) { + throw new \RuntimeException( + << 'k7mbqpzs.Qm8JxL2...', + 'domains' => ['example.com'], + ] + ); + EXAMPLE, + ); + } + + $annotationData = array_filter( + [ + 'title' => ($config['name_prefix'] ?? '') . $config['title'], + 'description' => $config['description'], + 'url_scope' => $config['url_scope'], + 'url_category_ids' => $config['url_category_ids'], + 'impact_at' => $config['impact_at'], + 'category_slug' => $config['category_slug'], + 'domains' => array_values((array) $config['domains']), + ], + static fn($value) => $value !== null && $value !== [], + ); + + $response = Httpie::post('https://insights.rumvision.com/api/v1/annotations') + ->setopt(CURLOPT_TIMEOUT, 10) + ->header('Authorization', sprintf('Bearer %s', $config['api_key'])) + ->jsonBody($annotationData) + ->getJson(); + + if (!isset($response['data']['id'])) { + throw new \RuntimeException(sprintf('Unable to create annotation: %s', print_r($response, true))); + } + + writeln( + sprintf( + 'RUMvision: Annotation %s ' + . 'for domain(s): %s created successfully.', + $annotationData['title'], + implode(', ', $annotationData['domains']), + ), + ); + }, +); diff --git a/recipes/tideways.php b/recipes/tideways.php new file mode 100644 index 0000000..e91ad60 --- /dev/null +++ b/recipes/tideways.php @@ -0,0 +1,109 @@ + 'Qm8JxL2...' +]); +``` + +### 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', 'deploy:tideways'); +``` + + */ + +namespace Deployer; + +use Deployer\Utility\Httpie; + +desc('Notifies Tideways of deployment'); +task( + 'deploy:tideways', + static function () { + $defaultConfig = [ + 'name' => get('release_name'), + 'type' => 'release', + 'description' => null, + 'environment' => null, + 'service' => null, + 'compareAfterMinutes' => 90, + ]; + + $config = array_merge($defaultConfig, array_filter((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']) + ) { + throw new \RuntimeException( + << 'Qm8JxL2...', + ] + );" + EXAMPLE, + ); + } + + $releaseData = array_filter( + [ + 'apiKey' => $config['api_key'], + 'name' => ($config['name_prefix'] ?? '') . $config['name'], + 'description' => $config['description'], + 'type' => $config['type'], + 'environment' => $config['environment'], + 'service' => $config['service'], + 'compareAfterMinutes' => $config['compareAfterMinutes'], + ], + ); + + $response = Httpie::post('https://app.tideways.io/api/events') + ->setopt(CURLOPT_TIMEOUT, 10) + ->jsonBody($releaseData) + ->getJson(); + + if (!isset($response['ok'], $response['id']) || $response['ok'] !== true) { + throw new \RuntimeException(sprintf('Unable to create a release: %s', print_r($response, true))); + } + + writeln( + sprintf( + 'Tideways: Release of version %s ' + . 'for project: %s created successfully.', + $releaseData['name'], + $response['name'], + ), + ); + }, +); diff --git a/src/AfterDeployTask/Rumvision.php b/src/AfterDeployTask/Rumvision.php new file mode 100644 index 0000000..fe35109 --- /dev/null +++ b/src/AfterDeployTask/Rumvision.php @@ -0,0 +1,148 @@ +apiKey = $apiKey; + $this->domains = $domains; + $this->title = $title; + $this->namePrefix = $namePrefix; + $this->description = $description; + $this->urlScope = $urlScope; + $this->urlCategoryIds = $urlCategoryIds; + $this->impactAt = $impactAt; + $this->categorySlug = $categorySlug; + } + + public function getApiKey(): string + { + return $this->apiKey; + } + + /** + * @return string[] + */ + public function getDomains(): array + { + return $this->domains; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function getNamePrefix(): ?string + { + return $this->namePrefix; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function getUrlScope(): ?string + { + return $this->urlScope; + } + + /** + * @return string[]|null + */ + public function getUrlCategoryIds(): ?array + { + return $this->urlCategoryIds; + } + + public function getImpactAt(): ?string + { + return $this->impactAt; + } + + public function getCategorySlug(): ?string + { + return $this->categorySlug; + } +} diff --git a/src/AfterDeployTask/Tideways.php b/src/AfterDeployTask/Tideways.php new file mode 100644 index 0000000..5025195 --- /dev/null +++ b/src/AfterDeployTask/Tideways.php @@ -0,0 +1,129 @@ +apiKey = $apiKey; + $this->name = $name; + $this->namePrefix = $namePrefix; + $this->type = $type; + $this->description = $description; + $this->environment = $environment; + $this->service = $service; + $this->compareAfterMinutes = $compareAfterMinutes; + } + + public function getApiKey(): string + { + return $this->apiKey; + } + + public function getName(): ?string + { + return $this->name; + } + + public function getNamePrefix(): ?string + { + return $this->namePrefix; + } + + public function getType(): ?string + { + return $this->type; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function getEnvironment(): ?string + { + return $this->environment; + } + + public function getService(): ?string + { + return $this->service; + } + + public function getCompareAfterMinutes(): ?int + { + return $this->compareAfterMinutes; + } +}