Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 67 additions & 26 deletions .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DrevOps\VortexInstaller\Command;

use DrevOps\VortexInstaller\Downloader\Artifact;
use DrevOps\VortexInstaller\Downloader\Downloader;
use DrevOps\VortexInstaller\Downloader\RepositoryDownloader;
use DrevOps\VortexInstaller\Prompts\Handlers\Starter;
Expand Down Expand Up @@ -85,27 +86,38 @@ class InstallCommand extends Command implements CommandRunnerAwareInterface, Exe
*/
protected ?Downloader $fileDownloader = NULL;

/**
* The artifact representing the repository and reference to install.
*/
protected Artifact $artifact;

/**
* {@inheritdoc}
*/
protected function configure(): void {
$this->setName('install');
$this->setDescription('Install Vortex from remote or local repository.');
$this->setHelp(<<<EOF
Interactively install Vortex from the latest stable release into the current directory:
php installer --destination=.

Non-interactively install Vortex from the latest stable release into the specified directory:
php installer --no-interaction --destination=path/to/destination

Install Vortex from the stable branch into the specified directory:
php installer --uri=https://github.com/drevops/vortex.git@stable --destination=path/to/destination

Install Vortex from a specific release into the specified directory:
php installer --uri=https://github.com/drevops/vortex.git@1.2.3 --destination=path/to/destination

Install Vortex from a specific commit into the specified directory:
php installer --uri=https://github.com/drevops/vortex.git@abcd123 --destination=path/to/destination
<info>Interactively install Vortex from the latest stable release into the current directory:</info>
php installer.php --destination=.

<info>Non-interactively install Vortex from the latest stable release into the specified directory:</info>
php installer.php --no-interaction --destination=path/to/destination

<info>Install from the latest auto-discovered stable release (default behavior if --uri is specified):</info>
php installer.php --uri=https://github.com/drevops/vortex.git
php installer.php --uri=https://github.com/drevops/vortex.git#stable

<info>Install using repository URL with specific git ref after #:</info>
php installer.php --uri=https://github.com/drevops/vortex.git#25.11.0
php installer.php --uri=https://github.com/drevops/vortex.git#v1.2.3
php installer.php --uri=https://github.com/drevops/vortex.git#main

<info>Copy GitHub URL directly from your browser:</info>
php installer.php --uri=https://github.com/drevops/vortex/releases/tag/25.11.0
php installer.php --uri=https://github.com/drevops/vortex/tree/1.2.3
php installer.php --uri=https://github.com/drevops/vortex/tree/main
php installer.php --uri=https://github.com/drevops/vortex/commit/abcd123
EOF
);
$this->addOption(static::OPTION_DESTINATION, NULL, InputOption::VALUE_REQUIRED, 'Destination directory. Defaults to the current directory.');
Expand Down Expand Up @@ -138,6 +150,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->header();

// Only validate if using custom repository or custom reference.
if (!$this->artifact->isDefault()) {
Task::action(
label: 'Validating repository and reference',
action: function (): string {
$this->getRepositoryDownloader()->validate($this->artifact);
return 'Repository and reference validated successfully';
},
hint: fn(): string => sprintf('Checking repository "%s" and reference "%s"', $this->artifact->getRepo(), $this->artifact->getRef()),
success: fn(string $return): string => $return
);
Tui::line('');
}

Tui::line(Tui::dim('Press any key to continue...'));
Tui::getChar();
Comment thread
AlexSkrypnyk marked this conversation as resolved.

$this->promptManager->runPrompts();

Tui::list($this->promptManager->getResponsesSummary(), 'Installation summary');
Expand All @@ -153,11 +182,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
Task::action(
label: 'Downloading Vortex',
action: function (): string {
$version = $this->getRepositoryDownloader()->download($this->config->get(Config::REPO), $this->config->get(Config::REF), $this->config->get(Config::TMP));
$version = $this->getRepositoryDownloader()->download($this->artifact, $this->config->get(Config::TMP));
$this->config->set(Config::VERSION, $version);
return $version;
},
hint: fn(): string => sprintf('Downloading from "%s" repository at commit "%s"', ...RepositoryDownloader::parseUri($this->config->get(Config::REPO))),
hint: fn(): string => sprintf('Downloading from "%s" repository at ref "%s"', $this->artifact->getRepo(), $this->artifact->getRef()),
success: fn(string $return): string => sprintf('Vortex downloaded (%s)', $return)
);

Expand Down Expand Up @@ -301,9 +330,25 @@ protected function resolveOptions(array $arguments, array $options): void {
Env::putFromDotenv($dest_env_file);
}

[$repo, $ref] = RepositoryDownloader::parseUri($options[static::OPTION_URI] ?: 'https://github.com/drevops/vortex.git@stable');
$this->config->set(Config::REPO, $repo);
$this->config->set(Config::REF, $ref);
// Build URI for artifact.
$uri_from_option = !empty($options[static::OPTION_URI]) && is_scalar($options[static::OPTION_URI]) ? strval($options[static::OPTION_URI]) : NULL;
$repo = Env::get(Config::REPO) ?: ($this->config->get(Config::REPO) ?: NULL);
$ref = Env::get(Config::REF) ?: ($this->config->get(Config::REF) ?: NULL);

// Priority: option URI > env/config repo+ref > default.
$uri = $uri_from_option;
if (!$uri && $repo) {
$uri = $ref ? $repo . '#' . $ref : $repo;
}

try {
$this->artifact = Artifact::fromUri($uri);
$this->config->set(Config::REPO, $this->artifact->getRepo());
$this->config->set(Config::REF, $this->artifact->getRef());
}
catch (\RuntimeException $e) {
throw new \RuntimeException(sprintf('Invalid repository URI: %s', $e->getMessage()), $e->getCode(), $e);
}

// Check if the project is a Vortex project.
$this->config->set(Config::IS_VORTEX_PROJECT, File::contains($this->config->getDst() . DIRECTORY_SEPARATOR . 'README.md', '/badge\/Vortex-/'));
Expand Down Expand Up @@ -508,15 +553,14 @@ protected function header(): void {
$title = 'Welcome to the Vortex interactive installer';
$content = '';

$ref = $this->config->get(Config::REF);
if ($ref == RepositoryDownloader::REF_STABLE) {
if ($this->artifact->isStable()) {
$content .= 'This tool will guide you through installing the latest ' . Tui::underscore('stable') . ' version of Vortex into your project.' . PHP_EOL;
}
elseif ($ref == RepositoryDownloader::REF_HEAD) {
elseif ($this->artifact->isDevelopment()) {
$content .= 'This tool will guide you through installing the latest ' . Tui::underscore('development') . ' version of Vortex into your project.' . PHP_EOL;
}
else {
$content .= sprintf('This tool will guide you through installing a ' . Tui::underscore('custom') . ' version of Vortex into your project at commit "%s".', $ref) . PHP_EOL;
$content .= sprintf('This tool will guide you through installing a ' . Tui::underscore('custom') . ' version of Vortex into your project at commit "%s".', $this->artifact->getRef()) . PHP_EOL;
}

$content .= PHP_EOL;
Expand Down Expand Up @@ -548,9 +592,6 @@ protected function header(): void {
}

Tui::box($content, $title);

Tui::line(Tui::dim('Press any key to continue...'));
Tui::getChar();
}

public function footer(): void {
Expand Down
Loading