Skip to content

Commit

Permalink
Merge pull request #131 from ByteInternet/feature/support-slack-notif…
Browse files Browse the repository at this point in the history
…ications

Better support slack notifications
  • Loading branch information
poespas authored Jan 9, 2025
2 parents 0de0ad4 + 30b6d34 commit 27a71ae
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ private function initContainer(): Container

$container = $builder->build();

if (!defined('DEPLOYER_VERSION')) {
define("DEPLOYER_VERSION", sprintf("Hypernode Deploy %s", $this->getVersion()));
}

$this->registerTwigLoader($container);

return $container;
Expand Down
1 change: 1 addition & 0 deletions src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Deployer/Task/After/SlackTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}}');
Expand Down
6 changes: 5 additions & 1 deletion src/Deployer/Task/Common/DefaultsTaskGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public function configure(Configuration $config): void
});

set('commit_sha', function () {
return $this->releaseInfo->getCommitSha();
try {
return $this->releaseInfo->getCommitSha();
} catch (\Throwable $e) {
return '';
}
});

if (str_starts_with($config->getPhpVersion(), 'php')) {
Expand Down
9 changes: 8 additions & 1 deletion src/Stdlib/ReleaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hypernode\Deploy\Stdlib;

use Deployer\Exception\RunException;
use Hypernode\DeployConfiguration\Stage;

use function Deployer\get;
Expand Down Expand Up @@ -52,7 +53,13 @@ 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) {
return [];
}

if (!preg_match(self::MERGE_PATTERN, $gitLogOutput, $matches)) {
output()->write('No merge commit found');
Expand Down

0 comments on commit 27a71ae

Please sign in to comment.