Skip to content

Commit bacc3ee

Browse files
authored
Merge pull request #89 from ByteInternet/passthrough_github_workflow_commands
2 parents 1a5f045 + bd916fa commit bacc3ee

File tree

5 files changed

+99
-9
lines changed

5 files changed

+99
-9
lines changed

ci/test/magento/deploy1.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Hypernode\DeployConfiguration;
44

5+
use function Deployer\run;
6+
use function Deployer\task;
7+
58
/**
69
* Start by setting up the configuration
710
*
@@ -10,6 +13,12 @@
1013
*/
1114
$configuration = new ApplicationTemplate\Magento2(['en_US', 'nl_NL']);
1215

16+
task('debug:github:msg', static function () {
17+
run('echo "::notice::This message should pass through to Github Workflow Summary!"');
18+
});
19+
20+
$configuration->addDeployTask('debug:github:msg');
21+
1322
$productionStage = $configuration->addStage('production', 'banaan1.store');
1423
$productionStage->addServer('hypernode', null, [], [
1524
'user' => 'app',

ci/test/run-general.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export PHP_VERSION_SHORT=$(echo "${PHP_VERSION:-8.2}" | sed 's/\.//')
77

88
# Handy aliases
99
HN="docker-compose exec -T hypernode"
10-
DP="docker-compose exec -T deploy"
11-
DP1="docker-compose exec --workdir=/web1 -T deploy"
12-
DP2="docker-compose exec --workdir=/web2 -T deploy"
10+
DP="docker-compose exec -e GITHUB_WORKFLOW -T deploy"
11+
DP1="docker-compose exec -e GITHUB_WORKFLOW --workdir=/web1 -T deploy"
12+
DP2="docker-compose exec -e GITHUB_WORKFLOW --workdir=/web2 -T deploy"
1313

1414
function install_magento() {
1515
$HN mysql -e "DROP DATABASE IF EXISTS dummytag_preinstalled_magento"
@@ -30,6 +30,20 @@ function install_magento() {
3030
--timezone=America/Chicago --elasticsearch-host=localhost"
3131
}
3232

33+
function begin_task() {
34+
if [[ -n "${GITHUB_WORKFLOW}" ]]; then
35+
echo "::group::$@"
36+
else
37+
echo "$@"
38+
fi
39+
}
40+
41+
function end_task() {
42+
if [[ -n "${GITHUB_WORKFLOW}" ]]; then
43+
echo "::endgroup::"
44+
fi
45+
}
46+
3347
# Install docker-compose if it's not installed
3448
if ! [ -x "$(command -v docker-compose)" ]; then
3549
pip install docker-compose
@@ -38,21 +52,25 @@ fi
3852
# Clear up env
3953
trap "docker-compose down -v" EXIT
4054

55+
begin_task "Setting up Docker stack"
4156
docker-compose up -d
57+
end_task
4258

59+
begin_task "Setting Magento 2"
4360
# Create working initial Magento install on the Hypernode container
44-
$HN composer create-project --repository=https://mage-os.hypernode.com/mirror/ magento/project-community-edition /data/web/magento2
61+
$HN composer create-project --repository=https://mirror.mage-os.org/ magento/project-community-edition:2.4.5-p2 /data/web/magento2
4562
echo "Waiting for MySQL to be available on the Hypernode container"
4663
$HN bash -c "until mysql -e 'select 1' ; do sleep 1; done"
4764
install_magento
65+
end_task
4866

4967
# Copy env to the deploy container
5068
$HN /data/web/magento2/bin/magento app:config:dump scopes themes
5169
echo "Waiting for SSH to be available on the Hypernode container"
5270
chmod 0600 ci/test/.ssh/id_rsa
5371
chmod 0600 ci/test/.ssh/authorized_keys
5472
$DP rsync -a app@hypernode:/data/web/magento2/ /web
55-
$DP rsync -v -a /config/ /web
73+
$DP rsync -a /config/ /web
5674
$DP rm /web/app/etc/env.php
5775

5876
# Create second app

src/Brancher/BrancherHypernodeManager.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
135135
} elseif ($timeElapsed < $allowedErrorWindow) {
136136
// Sometimes we get an error where the logbook is not yet available, but it will be soon.
137137
// We allow a small window for this to happen, and then we throw an exception.
138-
printf(
139-
'Got an expected exception during the allowed error window of HTTP code %d, waiting for %s to become available',
140-
$e->getCode(),
141-
$brancherHypernode
138+
$this->log->info(
139+
sprintf(
140+
'Got an expected exception during the allowed error window of HTTP code %d, waiting for %s to become available.',
141+
$e->getCode(),
142+
$brancherHypernode
143+
)
142144
);
145+
;
143146
continue;
144147
}
145148
}

src/DeployerLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Deployer\Deployer;
88
use Hypernode\Deploy\Console\Output\OutputWatcher;
9+
use Hypernode\Deploy\Printer\GithubWorkflowPrinter;
910
use Symfony\Component\Console\Application;
1011
use Symfony\Component\Console\Input\ArrayInput;
1112
use Symfony\Component\Console\Input\InputDefinition;
@@ -32,6 +33,11 @@ public function getOrCreateInstance(OutputInterface $output): Deployer
3233
new InputOption('profile'),
3334
])
3435
);
36+
if (getenv('GITHUB_WORKFLOW')) {
37+
$this->deployer['pop'] = function ($c) {
38+
return new GithubWorkflowPrinter($c['output']);
39+
};
40+
}
3541

3642
return $this->deployer;
3743
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hypernode\Deploy\Printer;
6+
7+
use Deployer\Component\ProcessRunner\Printer;
8+
use Deployer\Host\Host;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Process\Process;
11+
12+
class GithubWorkflowPrinter extends Printer
13+
{
14+
public const WORKFLOW_COMMAND_PATTERN = '/^::[a-zA-Z0-9-].*::.*$/';
15+
16+
private OutputInterface $output;
17+
18+
public function __construct(OutputInterface $output)
19+
{
20+
parent::__construct($output);
21+
$this->output = $output;
22+
}
23+
24+
public function contentHasWorkflowCommand(string $content): bool
25+
{
26+
return (bool)preg_match(self::WORKFLOW_COMMAND_PATTERN, trim($content));
27+
}
28+
29+
public function callback(Host $host, bool $forceOutput): callable
30+
{
31+
return function ($type, $buffer) use ($forceOutput, $host) {
32+
if (
33+
$this->output->isVerbose() || $forceOutput ||
34+
($type == Process::OUT && $this->contentHasWorkflowCommand($buffer))
35+
) {
36+
$this->printBuffer($type, $host, $buffer);
37+
}
38+
};
39+
}
40+
41+
public function writeln(string $type, Host $host, string $line): void
42+
{
43+
if (empty($line)) {
44+
return;
45+
}
46+
47+
if ($type == Process::OUT && $this->contentHasWorkflowCommand($line)) {
48+
$this->output->writeln($line);
49+
return;
50+
}
51+
52+
parent::writeln($type, $host, $line);
53+
}
54+
}

0 commit comments

Comments
 (0)