-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CMS-474] Do not require composer/composer as a direct dependency of …
…Terminus (#2308) * Delete unused BuildDebianPackage.php * Delete JsonFile.php and ComposerFile.php * Remove unused "use" statements * Remove composer/composer dependency * Replace usage of composer/composer package with native php in RoboFile::updateDependenciesversion() * Add todos to replace usages of composer/composer package with native php implementations * Add RoboFile::getProjectPath() * Replace usage of composer/composer package with native php in RoboFile::bundleLinux() * Replace usage of composer/composer package with native php in CommandCoverageReport::getRootDir() * Replace usage of composer/composer package with native php in CreateTestSiteArchive.php * Fix code style issue in RoboFile.php * Update composer dependencies * Generate Terminus plugins dependencies version bashed on composer.lock file hash * Use DIRECTORY_SEPARATOR in RoboFile::bundleLinux() * Update $terminusPluginsDependenciesVersion value * Improve error verbosity in PluginBaseCommand.php * Throw TerminusException if Terminus composer.lock not found * Include composer.json and composer.lock into phar * Improve error handling in updateTerminusDependencies()
- Loading branch information
Sergei Churilo
authored
Jan 14, 2022
1 parent
7692511
commit 5b88d12
Showing
14 changed files
with
127 additions
and
1,500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
<?php | ||
|
||
|
||
use Consolidation\AnnotatedCommand\CommandFileDiscovery; | ||
|
||
use Pantheon\Terminus\Config\ConfigAwareTrait; | ||
use Pantheon\Terminus\Helpers\CommandCoverageReport; | ||
use Pantheon\Terminus\Helpers\Composer\ComposerFile; | ||
use Pantheon\Terminus\Terminus; | ||
use Robo\Tasks; | ||
use Twig\Environment; | ||
use Twig\Extension\EscaperExtension; | ||
use Twig\Loader\FilesystemLoader; | ||
use wdm\debian\control\StandardFile; | ||
use wdm\debian\Packager; | ||
|
||
/** | ||
* Housekeeping tasks for Terminus. | ||
* | ||
* Class RoboFile | ||
*/ | ||
class RoboFile extends \Robo\Tasks | ||
class RoboFile extends Tasks | ||
{ | ||
use ConfigAwareTrait; | ||
|
||
|
@@ -25,7 +24,6 @@ class RoboFile extends \Robo\Tasks | |
*/ | ||
protected Terminus $terminus; | ||
|
||
|
||
/** | ||
* RoboFile constructor. | ||
*/ | ||
|
@@ -36,29 +34,21 @@ public function __construct() | |
} | ||
|
||
/** | ||
* @param string $file | ||
* @return \Robo\Result | ||
* @throws \Twig\Error\LoaderError | ||
* @throws \Twig\Error\RuntimeError | ||
* @throws \Twig\Error\SyntaxError | ||
* @param string|null $file | ||
*/ | ||
public function doc($file = null) | ||
{ | ||
//TODO: change this to real documentation building from phpdoc | ||
$readme = (string) CommandCoverageReport::factory(); | ||
if ($file) { | ||
file_put_contents($file, $readme); | ||
$readme = "./README.md regenerated."; | ||
$readme = './README.md regenerated.'; | ||
} | ||
$this->output()->writeln($readme); | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* @return \Robo\Result | ||
* @throws \Twig\Error\LoaderError | ||
* @throws \Twig\Error\RuntimeError | ||
* @throws \Twig\Error\SyntaxError | ||
* @param string|null $file | ||
*/ | ||
public function coverage($file = null) | ||
{ | ||
|
@@ -71,47 +61,54 @@ public function coverage($file = null) | |
} | ||
|
||
/** | ||
* Updates $terminusPluginsDependenciesVersion variable. | ||
* Updates $terminusPluginsDependenciesVersion variable in bin/terminus. | ||
*/ | ||
public function updateDependenciesversion() | ||
{ | ||
$this->say('Updating terminus dependencies version.'); | ||
$composerFilePath = realpath(dirname(\Composer\Factory::getComposerFile())); | ||
$composerLockContents = file_get_contents($composerFilePath . DIRECTORY_SEPARATOR . 'composer.lock'); | ||
$composerLockJson = json_decode($composerLockContents, true, 10); | ||
$hash = substr($composerLockJson['content-hash'], 0, 7); | ||
$binFileContents = file_get_contents('bin/terminus'); | ||
$newBinFileContents = preg_replace("/(terminusPluginsDependenciesVersion\s?=)(.*)/m", "$1 '${hash}';", $binFileContents); | ||
$this->say('Checking Terminus plugins dependencies version...'); | ||
$hash = substr(sha1_file($this->getProjectPath() . DIRECTORY_SEPARATOR . 'composer.lock'), 0, 10); | ||
$binFileContents = file_get_contents( | ||
$this->getProjectPath() . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'terminus' | ||
); | ||
$newBinFileContents = preg_replace( | ||
'/(terminusPluginsDependenciesVersion\s=\s\')(.+)(\';)/', | ||
"\${1}$hash\${3}", | ||
$binFileContents | ||
); | ||
if ($newBinFileContents && $newBinFileContents !== $binFileContents) { | ||
file_put_contents('bin/terminus', $newBinFileContents); | ||
file_put_contents('bin' . DIRECTORY_SEPARATOR . 'terminus', $newBinFileContents); | ||
$this->say('Terminus plugins dependencies version has been updated.'); | ||
return; | ||
} | ||
|
||
$this->say('Terminus plugins dependencies version remains unchanged.'); | ||
} | ||
|
||
/** | ||
* @return mixed|null | ||
* @throws Exception | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function bundleLinux() | ||
{ | ||
$this->say('Building DEBIAN/UBUNTU package.'); | ||
$composerFilePath = realpath(dirname(\Composer\Factory::getComposerFile())); | ||
|
||
$composerContents = new ComposerFile( | ||
$composerFilePath . DIRECTORY_SEPARATOR . 'composer.json' | ||
); | ||
$outputPath = $composerFilePath . DIRECTORY_SEPARATOR . 'package'; | ||
$terminus_binary = "{$composerFilePath}/terminus"; | ||
$terminus_binary = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'terminus'; | ||
$dpkg_installed_size = ceil(filesize($terminus_binary) / 1024); | ||
|
||
$outputPath = $this->getProjectPath() . DIRECTORY_SEPARATOR . 'package'; | ||
// We need the output path empty. | ||
if (is_dir($outputPath)) { | ||
exec(sprintf('rm -Rf %s', $outputPath)); | ||
mkdir($outputPath); | ||
} | ||
|
||
$name = $composerContents->getName(); | ||
$composerJson = json_decode( | ||
file_get_contents($this->getProjectPath() . DIRECTORY_SEPARATOR . 'composer.json'), | ||
true | ||
); | ||
|
||
[$vendor, $package] = explode('/', $name); | ||
[$vendor, $package] = explode('/', $composerJson['name']); | ||
// Create a config object. | ||
$config = $this->getConfig(); | ||
|
||
|
@@ -124,19 +121,22 @@ public function bundleLinux() | |
->setArchitecture('all') | ||
->setMaintainer('Terminus', '[email protected]') | ||
->setProvides($package) | ||
->setDescription($composerContents->getDescription()); | ||
->setDescription($composerJson['description']); | ||
|
||
$packager = new \wdm\debian\Packager(); | ||
$packager = new Packager(); | ||
|
||
$packager->setOutputPath($outputPath); | ||
$packager->setControl($control); | ||
$packager->addMount($terminus_binary, '/usr/bin/terminus'); | ||
$packager->addMount( | ||
$terminus_binary, | ||
DIRECTORY_SEPARATOR . 'usr' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'terminus' | ||
); | ||
|
||
//Creates folders using mount points | ||
// Creates folders using mount points. | ||
$packager->run(); | ||
|
||
// Get the Debian package command | ||
// Expectation is that this is a command line invocation for dpkg | ||
// Get the Debian package command. | ||
// Expectation is that this is a command line invocation for dpkg. | ||
$packageCommand = $packager->build(); | ||
$this->say($packageCommand); | ||
|
||
|
@@ -146,14 +146,15 @@ public function bundleLinux() | |
exec($packageCommand, $result, $status); | ||
|
||
if ($status !== 0) { | ||
throw new \Exception(join(PHP_EOL, $result)); | ||
throw new Exception(join(PHP_EOL, $result)); | ||
} | ||
if (!is_array($result)) { | ||
$result = [$result]; | ||
} | ||
// Package should be last line of output from command | ||
$packageFile = array_shift($result); | ||
$this->say('Package created: ' . $packageFile); | ||
|
||
return $packageFile; | ||
} | ||
|
||
|
@@ -175,7 +176,7 @@ public function bundleMac() | |
$twig = new Environment($loader, [ | ||
'cache' => false | ||
]); | ||
$twig->getExtension(\Twig\Extension\EscaperExtension::class) | ||
$twig->getExtension(EscaperExtension::class) | ||
->setDefaultStrategy('url'); | ||
$formulaFolder = $config->get('root') . DIRECTORY_SEPARATOR . 'Formula'; | ||
if (is_dir($formulaFolder)) { | ||
|
@@ -186,7 +187,7 @@ public function bundleMac() | |
$formulaFolder . DIRECTORY_SEPARATOR . 'terminus.rb', | ||
$twig->render('homebrew-receipt.twig', $context) | ||
); | ||
$this->say("Mac Formula Created"); | ||
$this->say('Mac Formula Created'); | ||
} | ||
|
||
/** | ||
|
@@ -204,4 +205,14 @@ public function setTerminus(Terminus $terminus): void | |
{ | ||
$this->terminus = $terminus; | ||
} | ||
|
||
/** | ||
* Returns the absolute path to the project. | ||
* | ||
* @return string | ||
*/ | ||
private function getProjectPath(): string | ||
{ | ||
return dirname(__FILE__); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.