Skip to content

Commit 92cdbe7

Browse files
committed
FEATURE: install correct prunner version post-package-update
1 parent 6ddda55 commit 92cdbe7

4 files changed

Lines changed: 147 additions & 16 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\Prunner\Command;
5+
6+
use Flowpack\Prunner\Composer\InstallerScripts;
7+
use Neos\Flow\Cli\CommandController;
8+
9+
class PrunnerCommandController extends CommandController
10+
{
11+
12+
private const COMPOSER_INSTALL_CMD_KEY = 'post-install-cmd';
13+
private const COMPOSER_UPDATE_CMD_KEY = 'post-update-cmd';
14+
15+
public function setupProjectCommand()
16+
{
17+
$cmd = InstallerScripts::class . '::postUpdateAndInstall';
18+
19+
$this->outputLine('adding post-install-script to root composer.json');
20+
21+
$composerJsonFile = file_get_contents(FLOW_PATH_ROOT . '/composer.json');
22+
$composerJson = json_decode($composerJsonFile, true);
23+
if (!isset($composerJson['scripts'])) {
24+
$composerJson['scripts'] = [];
25+
}
26+
27+
$postInstallCmd = [];
28+
if (is_string($composerJson['scripts'][self::COMPOSER_INSTALL_CMD_KEY])) {
29+
$postInstallCmd[] = $composerJson['scripts'][self::COMPOSER_INSTALL_CMD_KEY];
30+
} else {
31+
$postInstallCmd = $composerJson['scripts'][self::COMPOSER_INSTALL_CMD_KEY];
32+
}
33+
if (array_search($cmd, $postInstallCmd) === false) {
34+
$postInstallCmd[] = $cmd;
35+
}
36+
$composerJson['scripts'][self::COMPOSER_INSTALL_CMD_KEY] = $postInstallCmd;
37+
38+
$postUpdateCmd = [];
39+
if (is_string($composerJson['scripts'][self::COMPOSER_UPDATE_CMD_KEY])) {
40+
$postUpdateCmd[] = $composerJson['scripts'][self::COMPOSER_UPDATE_CMD_KEY];
41+
} else {
42+
$postUpdateCmd = $composerJson['scripts'][self::COMPOSER_UPDATE_CMD_KEY];
43+
}
44+
if (array_search($cmd, $postUpdateCmd) === false) {
45+
$postUpdateCmd[] = $cmd;
46+
}
47+
$composerJson['scripts'][self::COMPOSER_UPDATE_CMD_KEY] = $postUpdateCmd;
48+
49+
file_put_contents(FLOW_PATH_ROOT . '/composer.json', json_encode($composerJson, JSON_PRETTY_PRINT));
50+
51+
$this->outputLine('Updated root composer.json. <b>You now need to run composer install</b>');
52+
}
53+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\Prunner\Composer;
5+
6+
use Composer\Script\Event;
7+
use Neos\Utility\Files;
8+
use PharData;
9+
10+
class InstallerScripts
11+
{
12+
13+
private const PRUNNER_DISPATCH_SCRIPT = <<<'EOD'
14+
#!/bin/sh
15+
16+
SCRIPTS_DIR=$(dirname "$(realpath $0)")
17+
18+
OS_TYPE=$(uname -s)
19+
ARCH_TYPE=$(uname -m)
20+
21+
# Make a very simple check if we have a bundled binary for the right OS / architecture
22+
BIN_TARGET="${SCRIPTS_DIR}/${OS_TYPE}_${ARCH_TYPE}/prunner"
23+
24+
if [ -f "$BIN_TARGET" ]; then
25+
$BIN_TARGET $@
26+
else
27+
echo "Unsupported OS or architecture"
28+
exit 1
29+
fi
30+
EOD;
31+
32+
33+
public static function postUpdateAndInstall(Event $event)
34+
{
35+
$platform = php_uname('s'); // stuff like Darwin etc
36+
$architecture = php_uname('m'); // x86_64
37+
38+
$version = '0.0.1';
39+
40+
$baseDirectory = 'prunner';
41+
$platformSpecificTargetDirectory = $baseDirectory . '/' . $platform . '_' . $architecture;
42+
43+
if (file_exists($platformSpecificTargetDirectory . '/version') && trim(file_get_contents($platformSpecificTargetDirectory . '/version')) !== $version) {
44+
echo '> Version of prunner inside ' . $platformSpecificTargetDirectory . ' is ' . trim(file_get_contents($platformSpecificTargetDirectory . '/version')) . ', but we expect ' . $version . ".\n";
45+
echo '> Removing prunner, and re-downloading.' . "\n";
46+
Files::removeDirectoryRecursively($platformSpecificTargetDirectory);
47+
}
48+
if (!file_exists($platformSpecificTargetDirectory . '/prunner')) {
49+
echo '> Downloading prunner from https://github.com/Flowpack/prunner' . "\n";
50+
echo '> Version: ' . $version . "\n";
51+
echo '> Platform: ' . $platform . "\n";
52+
echo '> Architecture: ' . $architecture . "\n";
53+
$downloadLink = sprintf('https://github.com/Flowpack/prunner/releases/download/v%s/prunner_%s_%s_%s.tar.gz', $version, $version, $platform, $architecture);
54+
$downloadedFileContents = file_get_contents($downloadLink);
55+
echo '> Download complete.' . "\n";
56+
57+
file_put_contents('Data/Temporary/prunner.tar.gz', $downloadedFileContents);
58+
unlink('Data/Temporary/prunner.tar');
59+
60+
// decompress from gz
61+
$p = new PharData('Data/Temporary/prunner.tar.gz');
62+
$p->decompress();
63+
$phar = new PharData('Data/Temporary/prunner.tar');
64+
65+
if (!is_dir(dirname($platformSpecificTargetDirectory))) {
66+
mkdir(dirname($platformSpecificTargetDirectory));
67+
}
68+
69+
$phar->extractTo($platformSpecificTargetDirectory);
70+
file_put_contents($platformSpecificTargetDirectory . '/version', $version);
71+
72+
echo '> Prunner extracted to ' . $platformSpecificTargetDirectory . "\n";
73+
}
74+
75+
file_put_contents($baseDirectory . '/prunner', self::PRUNNER_DISPATCH_SCRIPT);
76+
chmod($baseDirectory . '/prunner', 0755);
77+
}
78+
}

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ A minimalistic React UI to start and view pipelines, jobs and task details.
1919

2020
A Neos/Flow PHP package providing a backend module for the current pipeline state, and a PHP API.
2121

22+
## Installation
23+
24+
```bash
25+
# add the package
26+
composer require flowpack/prunner
27+
28+
# patch main composer.json to add Flowpack\Prunner\Composer\InstallerScripts::postUpdateAndInstall to post-install-cmd and post-update-cmd
29+
./flow prunner:setupProject
30+
31+
# run composer install again, to download prunner.
32+
composer install
33+
34+
# prunner is now installed in your project root, as "prunner/prunner"
35+
```
36+
37+
Now, start up prunner
2238

2339
## License
2440

Resources/Private/Scripts/prunner

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)