From e3bd6da3a2a02eb3de95d3d00d6e212320c15126 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Tue, 7 Jan 2025 14:17:55 +0100 Subject: [PATCH 1/4] IMP: Make SlackNotifications compatible again --- src/Bootstrap.php | 4 ++++ src/DeployRunner.php | 1 + src/Deployer/Task/After/SlackTask.php | 2 +- src/Deployer/TaskBuilder.php | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 563bd06..f1f8e8a 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -61,6 +61,10 @@ private function initContainer(): Container 'version' => $this->getVersion(), ]); + if (!defined('DEPLOYER_VERSION')) { + define("DEPLOYER_VERSION", sprintf("Hypernode Deploy %s", $this->getVersion())); + } + $container = $builder->build(); $this->registerTwigLoader($container); diff --git a/src/DeployRunner.php b/src/DeployRunner.php index 9307eb0..e9de6a1 100644 --- a/src/DeployRunner.php +++ b/src/DeployRunner.php @@ -223,6 +223,7 @@ private function configureStageServer( $host->setSshMultiplexing(true); $host->set('roles', $server->getRoles()); $host->set('domain', $stage->getDomain()); + $host->set('stage', $stage->getName()); $host->set('deploy_path', function () { // Ensure directory exists before returning it run('mkdir -p ~/apps/{{domain}}/shared'); diff --git a/src/Deployer/Task/After/SlackTask.php b/src/Deployer/Task/After/SlackTask.php index 1aab66d..f3d62ef 100644 --- a/src/Deployer/Task/After/SlackTask.php +++ b/src/Deployer/Task/After/SlackTask.php @@ -35,7 +35,7 @@ public function supports(TaskConfigurationInterface $config): bool */ public function configureWithTaskConfig(TaskConfigurationInterface $config): ?Task { - $this->recipeLoader->load('slack.php'); + $this->recipeLoader->load('../contrib/slack.php'); set('slack_webhook', $config->getWebHook()); set('slack_text', '{{release_message}}'); diff --git a/src/Deployer/TaskBuilder.php b/src/Deployer/TaskBuilder.php index d97e767..10821db 100644 --- a/src/Deployer/TaskBuilder.php +++ b/src/Deployer/TaskBuilder.php @@ -41,12 +41,12 @@ public function buildAll(array $commands, string $namePrefix): array } /** - * @param Command $command + * @param TaskConfigurationInterface $command * @param string $name * @return Task * @throws \Exception */ - private function build(Command $command, string $name): Task + private function build(TaskConfigurationInterface $command, string $name): Task { $task = task($name, function () use ($command) { $this->runCommandWithin($command); From e7506e14f1a491f63bc58bb2386f573f7cccecc5 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Tue, 7 Jan 2025 15:31:42 +0100 Subject: [PATCH 2/4] Add additional checks for git changes in release notes --- src/Deployer/TaskBuilder.php | 4 ++-- src/Stdlib/ReleaseInfo.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Deployer/TaskBuilder.php b/src/Deployer/TaskBuilder.php index 10821db..d97e767 100644 --- a/src/Deployer/TaskBuilder.php +++ b/src/Deployer/TaskBuilder.php @@ -41,12 +41,12 @@ public function buildAll(array $commands, string $namePrefix): array } /** - * @param TaskConfigurationInterface $command + * @param Command $command * @param string $name * @return Task * @throws \Exception */ - private function build(TaskConfigurationInterface $command, string $name): Task + private function build(Command $command, string $name): Task { $task = task($name, function () use ($command) { $this->runCommandWithin($command); diff --git a/src/Stdlib/ReleaseInfo.php b/src/Stdlib/ReleaseInfo.php index 3be2fc6..fbb3142 100644 --- a/src/Stdlib/ReleaseInfo.php +++ b/src/Stdlib/ReleaseInfo.php @@ -3,6 +3,7 @@ namespace Hypernode\Deploy\Stdlib; use Hypernode\DeployConfiguration\Stage; +use Deployer\Exception\RunException; use function Deployer\get; use function Deployer\parse; @@ -18,7 +19,12 @@ class ReleaseInfo public function getCommitSha(): string { - return runLocally('git rev-parse HEAD'); + try { + return runLocally('git rev-parse HEAD'); + } + catch (\Throwable $e) { + return ''; + } } public function getMessage(): string @@ -52,7 +58,11 @@ public function getMessage(): string */ private function branchList(): array { - $gitLogOutput = runLocally('git log --merges -n 1'); + $gitLogOutput = ''; + try { + $gitLogOutput = runLocally('git log --merges -n 1'); + } + catch (RunException $e) {} if (!preg_match(self::MERGE_PATTERN, $gitLogOutput, $matches)) { output()->write('No merge commit found'); From 1364fabbdfa4bd99b810b6da42837b00e6758260 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Tue, 7 Jan 2025 16:16:52 +0100 Subject: [PATCH 3/4] Fix grumPHP --- src/Bootstrap.php | 2 +- src/Stdlib/ReleaseInfo.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bootstrap.php b/src/Bootstrap.php index f1f8e8a..f88b22f 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -62,7 +62,7 @@ private function initContainer(): Container ]); if (!defined('DEPLOYER_VERSION')) { - define("DEPLOYER_VERSION", sprintf("Hypernode Deploy %s", $this->getVersion())); + define("DEPLOYER_VERSION", sprintf("Hypernode Deploy %s", $this->getVersion())); } $container = $builder->build(); diff --git a/src/Stdlib/ReleaseInfo.php b/src/Stdlib/ReleaseInfo.php index fbb3142..94a7b8b 100644 --- a/src/Stdlib/ReleaseInfo.php +++ b/src/Stdlib/ReleaseInfo.php @@ -21,8 +21,7 @@ public function getCommitSha(): string { try { return runLocally('git rev-parse HEAD'); - } - catch (\Throwable $e) { + } catch (\Throwable $e) { return ''; } } @@ -61,8 +60,9 @@ private function branchList(): array $gitLogOutput = ''; try { $gitLogOutput = runLocally('git log --merges -n 1'); + } catch (RunException $e) { + } - catch (RunException $e) {} if (!preg_match(self::MERGE_PATTERN, $gitLogOutput, $matches)) { output()->write('No merge commit found'); From ad34d12e6bdf797ebb3fa6ac9049b8c71fd14197 Mon Sep 17 00:00:00 2001 From: Jonathan Visser Date: Tue, 7 Jan 2025 16:41:21 +0100 Subject: [PATCH 4/4] Fix grumphp --- src/Stdlib/ReleaseInfo.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Stdlib/ReleaseInfo.php b/src/Stdlib/ReleaseInfo.php index 94a7b8b..19959d9 100644 --- a/src/Stdlib/ReleaseInfo.php +++ b/src/Stdlib/ReleaseInfo.php @@ -61,7 +61,6 @@ private function branchList(): array try { $gitLogOutput = runLocally('git log --merges -n 1'); } catch (RunException $e) { - } if (!preg_match(self::MERGE_PATTERN, $gitLogOutput, $matches)) {