Skip to content

Commit

Permalink
Merge pull request #27 from 21TORR/hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
keichinger authored Jul 4, 2024
2 parents 2f8a1cb + 6f4d5bd commit bd1c342
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 179 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
3.1.0
=====

* (feature) Rename `Post*` tasks concept name to "hooks".
* (deprecation) Deprecate command `hosting:run-tasks:post-build`, use `hosting:hook:build` instead.
* (deprecation) Deprecate command `hosting:run-tasks:post-deploy`, use `hosting:hook:deploy` instead.
* (deprecation) Deprecate `PostBuildTaskInterface`, use `BuildHookInterface` instead.
* (deprecation) Deprecate `PostDeploymentTaskInterface`, use `DeployHookInterface` instead.


3.0.1
=====

Expand Down
9 changes: 9 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
3.x to 4.0
==========

* Command `hosting:run-tasks:post-build` was removed, use `hosting:hook:build` instead.
* Command `hosting:run-tasks:post-deploy` was removed, use `hosting:hook:deploy` instead.
* Interface `PostBuildTaskInterface` was removed, use `BuildHookInterface` instead.
* Interface `PostDeploymentTaskInterface` was removed, use `DeployHookInterface` instead.


2.x to 3.0
==========

Expand Down
60 changes: 60 additions & 0 deletions src/Command/BuildHooksCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php declare(strict_types=1);

namespace Torr\Hosting\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Torr\Hosting\Deployment\HookRunners;
use Torr\Hosting\Deployment\TaskCli;

#[AsCommand(
"hosting:hook:build",
description: "Runs the hooks for 'after the build finished'",
aliases: ["hosting:run-tasks:post-build"],
)]
final class BuildHooksCommand extends Command
{
private HookRunners $runners;

/**
* @inheritDoc
*/
public function __construct(HookRunners $runners)
{
parent::__construct();
$this->runners = $runners;
}

/**
* @inheritDoc
*/
protected function execute (InputInterface $input, OutputInterface $output) : int
{
$io = new TaskCli($input, $output);
$io->title("Run Build Hooks");

// @todo remove code block + alias in v4
if ("hosting:hook:build" !== $input->getFirstArgument())
{
$message = sprintf(
"The command `%s` was deprecated. Use `hosting:hook:build` instead.",
$input->getFirstArgument(),
);
trigger_deprecation(
"21torr/hosting",
"3.1.0",
$message,
);
$io->caution($message);
}

$this->runners->runBuildHooks($io);

$io->newLine();
$io->success("Ran all build hooks.");

return 0;
}
}
60 changes: 60 additions & 0 deletions src/Command/DeployHooksCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php declare(strict_types=1);

namespace Torr\Hosting\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Torr\Hosting\Deployment\HookRunners;
use Torr\Hosting\Deployment\TaskCli;

#[AsCommand(
"hosting:hook:deploy",
description: "Runs the hooks for 'after the deployment finished'",
aliases: ["hosting:run-tasks:post-deploy"],
)]
final class DeployHooksCommand extends Command
{
private HookRunners $runners;

/**
* @inheritDoc
*/
public function __construct(HookRunners $runners)
{
parent::__construct();
$this->runners = $runners;
}

/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output) : int
{
$io = new TaskCli($input, $output);
$io->title("Run Deploy Hooks");

// @todo remove code block + alias in v4
if ("hosting:hook:build" !== $input->getFirstArgument())
{
$message = sprintf(
"The command `%s` was deprecated. Use `hosting:hook:deploy` instead.",
$input->getFirstArgument(),
);
trigger_deprecation(
"21torr/hosting",
"3.1.0",
$message,
);
$io->caution($message);
}

$this->runners->runDeployHooks($io);

$io->newLine();
$io->success("Ran all deploy hooks.");

return 0;
}
}
41 changes: 0 additions & 41 deletions src/Command/PostBuildTasksCommand.php

This file was deleted.

41 changes: 0 additions & 41 deletions src/Command/PostDeploymentTasksCommand.php

This file was deleted.

16 changes: 16 additions & 0 deletions src/Deployment/BuildHookInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace Torr\Hosting\Deployment;

interface BuildHookInterface
{
/**
* Returns the label of the hook
*/
public function getLabel () : string;

/**
* Runs the build hook
*/
public function runPostBuild (TaskCli $io) : void;
}
16 changes: 16 additions & 0 deletions src/Deployment/DeployHookInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace Torr\Hosting\Deployment;

interface DeployHookInterface
{
/**
* Returns the label of the hook
*/
public function getLabel () : string;

/**
* Runs the post deployment hook
*/
public function runPostDeployment (TaskCli $io) : void;
}
66 changes: 66 additions & 0 deletions src/Deployment/HookRunners.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php declare(strict_types=1);

namespace Torr\Hosting\Deployment;

use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;

final readonly class HookRunners
{
public const string TAG_BUILD_HOOK = "hosting.hook.build";
public const string TAG_DEPLOY_HOOK = "hosting.hook.deploy";

/**
*/
public function __construct (
/** @var BuildHookInterface[] */
#[AutowireIterator(tag: self::TAG_BUILD_HOOK)]
private iterable $buildHooks,
/** @var DeployHookInterface[] */
#[AutowireIterator(tag: self::TAG_DEPLOY_HOOK)]
private iterable $deployHooks,
) {}

/**
*/
public function runBuildHooks (TaskCli $io) : void
{
$first = true;

foreach ($this->buildHooks as $runner)
{
if ($first)
{
$first = false;
}
else
{
$io->newLine(2);
}

$io->section("Run Build Hook: <fg=magenta>{$runner->getLabel()}</>");
$runner->runPostBuild($io);
}
}

/**
*/
public function runDeployHooks (TaskCli $io) : void
{
$first = true;

foreach ($this->deployHooks as $runner)
{
if ($first)
{
$first = false;
}
else
{
$io->newLine(2);
}

$io->section("Run Deploy Hook: <fg=magenta>{$runner->getLabel()}</>");
$runner->runPostDeployment($io);
}
}
}
16 changes: 6 additions & 10 deletions src/Deployment/PostBuildTaskInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

namespace Torr\Hosting\Deployment;

interface PostBuildTaskInterface
/**
* @deprecated use {@see BuildHookInterface} instead
*
* @todo remove in v4
*/
interface PostBuildTaskInterface extends BuildHookInterface
{
/**
* Returns the label of the run
*/
public function getLabel () : string;

/**
* Runs the post build tasks
*/
public function runPostBuild (TaskCli $io) : void;
}
16 changes: 6 additions & 10 deletions src/Deployment/PostDeploymentTaskInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

namespace Torr\Hosting\Deployment;

interface PostDeploymentTaskInterface
/**
* @deprecated use {@see DeployHookInterface} instead
*
* @todo remove in v4
*/
interface PostDeploymentTaskInterface extends DeployHookInterface
{
/**
* Returns the label of the run
*/
public function getLabel () : string;

/**
* Runs the post deployment tasks
*/
public function runPostDeployment (TaskCli $io) : void;
}
Loading

0 comments on commit bd1c342

Please sign in to comment.