From 799268cc08945bcbc2929fd9ec7ab38aba33da81 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 14 Aug 2023 23:16:37 +0100 Subject: [PATCH 1/6] Don't set TTY in CI --- src/Commands/BuildCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index b03026f6..44021631 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -12,7 +12,7 @@ class BuildCommand extends Command { use LocatesPhpBinary; - protected $signature = 'native:build {os=all : The operating system to build for (all, linux, mac, windows)}'; + protected $signature = 'native:build {os=all : The operating system to build for (all, linux, mac, windows)} {--ci : Whether the build is running in a CI environment}'; public function handle() { @@ -31,7 +31,7 @@ public function handle() Process::path(__DIR__.'/../../resources/js/') ->env($this->getEnvironmentVariables()) ->forever() - ->tty(PHP_OS_FAMILY != 'Windows') + ->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('ci')) ->run($buildCommand, function (string $type, string $output) { echo $output; }); From 496b2b953b2b526cdb5df8d96067cb5d597264e4 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 14 Aug 2023 23:54:46 +0100 Subject: [PATCH 2/6] Add tty parameter to executeCommand --- src/Traits/ExecuteCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Traits/ExecuteCommand.php b/src/Traits/ExecuteCommand.php index 1f75884c..8113a83f 100644 --- a/src/Traits/ExecuteCommand.php +++ b/src/Traits/ExecuteCommand.php @@ -10,8 +10,10 @@ trait ExecuteCommand { use LocatesPhpBinary; - protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install'): void + protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install', bool $tty = true): void { + $tty = $tty || PHP_OS_FAMILY != 'Windows'; + $envs = [ 'install' => [ 'NATIVEPHP_PHP_BINARY_PATH' => base_path($this->phpBinaryPath()), @@ -29,7 +31,7 @@ protected function executeCommand(string $command, bool $skip_queue = false, str Process::path(__DIR__.'/../../resources/js/') ->env($envs[$type]) ->forever() - ->tty(PHP_OS_FAMILY != 'Windows') + ->tty($tty) ->run($command, function (string $type, string $output) { if ($this->getOutput()->isVerbose()) { echo $output; From 6bf7012566f63fb2ee93f915d75a94b729770007 Mon Sep 17 00:00:00 2001 From: Dan Johnson Date: Tue, 15 Aug 2023 21:35:14 +0100 Subject: [PATCH 3/6] fix: allow --ci flag for install --- src/Commands/InstallCommand.php | 13 +++++++++---- src/Traits/ExecuteCommand.php | 6 ++---- src/Traits/Installer.php | 14 ++++++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 2b51f6fa..f721ae7e 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -12,21 +12,26 @@ class InstallCommand extends Command { use Installer; - protected $signature = 'native:install {--force : Overwrite existing files by default} {--installer=npm : The package installer to use: npm, yarn or pnpm}'; + protected $signature = 'native:install {--force : Overwrite existing files by default} {--installer=npm : The package installer to use: npm, yarn or pnpm} {--ci : Whether the build is running in a CI environment}'; protected $description = 'Install all of the NativePHP resources'; public function handle(): void { intro('Publishing NativePHP Service Provider...'); + + $isCI = $this->option('ci'); + $this->callSilent('vendor:publish', ['--tag' => 'nativephp-provider']); $this->callSilent('vendor:publish', ['--tag' => 'nativephp-config']); - $installer = $this->getInstaller($this->option('installer')); + $installer = $this->getInstaller($this->option('installer'), $isCI); + + $this->installNPMDependencies(force: $this->option('force'), installer: $installer, isCI: $isCI); - $this->installNPMDependencies(force: $this->option('force'), installer: $installer); + $shouldPromptForServe = ! $isCI && ! $this->option('force'); - if (! $this->option('force') && confirm('Would you like to start the NativePHP development server', false)) { + if ($shouldPromptForServe && confirm('Would you like to start the NativePHP development server', false)) { $this->call('native:serve', ['--installer' => $installer]); } diff --git a/src/Traits/ExecuteCommand.php b/src/Traits/ExecuteCommand.php index 8113a83f..e6461557 100644 --- a/src/Traits/ExecuteCommand.php +++ b/src/Traits/ExecuteCommand.php @@ -10,10 +10,8 @@ trait ExecuteCommand { use LocatesPhpBinary; - protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install', bool $tty = true): void + protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install', bool $isCI = false): void { - $tty = $tty || PHP_OS_FAMILY != 'Windows'; - $envs = [ 'install' => [ 'NATIVEPHP_PHP_BINARY_PATH' => base_path($this->phpBinaryPath()), @@ -31,7 +29,7 @@ protected function executeCommand(string $command, bool $skip_queue = false, str Process::path(__DIR__.'/../../resources/js/') ->env($envs[$type]) ->forever() - ->tty($tty) + ->tty(!$isCI && PHP_OS_FAMILY != 'Windows') ->run($command, function (string $type, string $output) { if ($this->getOutput()->isVerbose()) { echo $output; diff --git a/src/Traits/Installer.php b/src/Traits/Installer.php index b29d56f5..993f2414 100644 --- a/src/Traits/Installer.php +++ b/src/Traits/Installer.php @@ -11,26 +11,28 @@ trait Installer { use ExecuteCommand; - protected function installNPMDependencies(bool $force, ?string $installer = 'npm'): void + protected function installNPMDependencies(bool $force, ?string $installer = 'npm', bool $isCI = false): void { - if ($force || confirm('Would you like to install the NativePHP NPM dependencies?', true)) { + $shouldPrompt = $force || $isCI; + + if ($shouldPrompt || confirm('Would you like to install the NativePHP NPM dependencies?', true)) { note('Installing NPM dependencies (This may take a while)...'); if (! $installer) { - $this->installDependencies(); + $this->installDependencies(isCI: $isCI); } else { - $this->installDependencies(installer: $installer); + $this->installDependencies(installer: $installer, isCI: $isCI); } $this->output->newLine(); } } - protected function installDependencies(?string $installer): void + protected function installDependencies(?string $installer = null, bool $isCI = false): void { [$installer, $command] = $this->getInstallerAndCommand(installer: $installer); note("Installing NPM dependencies using the {$installer} package manager..."); - $this->executeCommand(command: $command); + $this->executeCommand(command: $command, isCI: $isCI); } protected function getInstallerAndCommand(?string $installer, $type = 'install'): array From be0d2491aeee05beee793415afa5a2ff8b3c78c5 Mon Sep 17 00:00:00 2001 From: Dan Johnson Date: Tue, 15 Aug 2023 22:14:27 +0100 Subject: [PATCH 4/6] fix: don't enable TTY for publish on CI --- src/Commands/PublishCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php index 724f6729..0b45b91f 100644 --- a/src/Commands/PublishCommand.php +++ b/src/Commands/PublishCommand.php @@ -12,7 +12,7 @@ class PublishCommand extends Command { use LocatesPhpBinary; - protected $signature = 'native:publish {os=mac}'; + protected $signature = 'native:publish {os=mac} {--ci : Whether the build is running in a CI environment}'; public function handle() { @@ -33,7 +33,7 @@ public function handle() Process::path(__DIR__.'/../../resources/js/') ->env($this->getEnvironmentVariables()) ->forever() - ->tty(PHP_OS_FAMILY != 'Windows') + ->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('ci')) ->run('npm run publish:mac-arm', function (string $type, string $output) { echo $output; }); From 62c0b2cf5dee1c150acd7dc5a44a88a6a8e9eccf Mon Sep 17 00:00:00 2001 From: Dan Johnson Date: Wed, 16 Aug 2023 17:43:59 +0100 Subject: [PATCH 5/6] refact: rename from --ci to --no-interaction --- src/Commands/BuildCommand.php | 4 ++-- src/Commands/InstallCommand.php | 10 +++++----- src/Commands/PublishCommand.php | 4 ++-- src/Traits/ExecuteCommand.php | 4 ++-- src/Traits/Installer.php | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 44021631..5e52aebc 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -12,7 +12,7 @@ class BuildCommand extends Command { use LocatesPhpBinary; - protected $signature = 'native:build {os=all : The operating system to build for (all, linux, mac, windows)} {--ci : Whether the build is running in a CI environment}'; + protected $signature = 'native:build {os=all : The operating system to build for (all, linux, mac, windows)} {--no-interaction : Whether interaction should be disabled}'; public function handle() { @@ -31,7 +31,7 @@ public function handle() Process::path(__DIR__.'/../../resources/js/') ->env($this->getEnvironmentVariables()) ->forever() - ->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('ci')) + ->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('no-interaction')) ->run($buildCommand, function (string $type, string $output) { echo $output; }); diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index f721ae7e..743c627e 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -12,7 +12,7 @@ class InstallCommand extends Command { use Installer; - protected $signature = 'native:install {--force : Overwrite existing files by default} {--installer=npm : The package installer to use: npm, yarn or pnpm} {--ci : Whether the build is running in a CI environment}'; + protected $signature = 'native:install {--force : Overwrite existing files by default} {--installer=npm : The package installer to use: npm, yarn or pnpm} {--no-interaction : Whether interaction should be disabled}'; protected $description = 'Install all of the NativePHP resources'; @@ -20,16 +20,16 @@ public function handle(): void { intro('Publishing NativePHP Service Provider...'); - $isCI = $this->option('ci'); + $withoutInteraction = $this->option('no-interaction'); $this->callSilent('vendor:publish', ['--tag' => 'nativephp-provider']); $this->callSilent('vendor:publish', ['--tag' => 'nativephp-config']); - $installer = $this->getInstaller($this->option('installer'), $isCI); + $installer = $this->getInstaller($this->option('installer'), $withoutInteraction); - $this->installNPMDependencies(force: $this->option('force'), installer: $installer, isCI: $isCI); + $this->installNPMDependencies(force: $this->option('force'), installer: $installer, withoutInteraction: $withoutInteraction); - $shouldPromptForServe = ! $isCI && ! $this->option('force'); + $shouldPromptForServe = ! $withoutInteraction && ! $this->option('force'); if ($shouldPromptForServe && confirm('Would you like to start the NativePHP development server', false)) { $this->call('native:serve', ['--installer' => $installer]); diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php index 0b45b91f..e36907a6 100644 --- a/src/Commands/PublishCommand.php +++ b/src/Commands/PublishCommand.php @@ -12,7 +12,7 @@ class PublishCommand extends Command { use LocatesPhpBinary; - protected $signature = 'native:publish {os=mac} {--ci : Whether the build is running in a CI environment}'; + protected $signature = 'native:publish {os=mac} {--no-interaction : Whether interaction should be disabled}'; public function handle() { @@ -33,7 +33,7 @@ public function handle() Process::path(__DIR__.'/../../resources/js/') ->env($this->getEnvironmentVariables()) ->forever() - ->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('ci')) + ->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('no-interaction')) ->run('npm run publish:mac-arm', function (string $type, string $output) { echo $output; }); diff --git a/src/Traits/ExecuteCommand.php b/src/Traits/ExecuteCommand.php index e6461557..3b3ab4b7 100644 --- a/src/Traits/ExecuteCommand.php +++ b/src/Traits/ExecuteCommand.php @@ -10,7 +10,7 @@ trait ExecuteCommand { use LocatesPhpBinary; - protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install', bool $isCI = false): void + protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install', bool $withoutInteraction = false): void { $envs = [ 'install' => [ @@ -29,7 +29,7 @@ protected function executeCommand(string $command, bool $skip_queue = false, str Process::path(__DIR__.'/../../resources/js/') ->env($envs[$type]) ->forever() - ->tty(!$isCI && PHP_OS_FAMILY != 'Windows') + ->tty(!$withoutInteraction && PHP_OS_FAMILY != 'Windows') ->run($command, function (string $type, string $output) { if ($this->getOutput()->isVerbose()) { echo $output; diff --git a/src/Traits/Installer.php b/src/Traits/Installer.php index 993f2414..65c1ce34 100644 --- a/src/Traits/Installer.php +++ b/src/Traits/Installer.php @@ -11,28 +11,28 @@ trait Installer { use ExecuteCommand; - protected function installNPMDependencies(bool $force, ?string $installer = 'npm', bool $isCI = false): void + protected function installNPMDependencies(bool $force, ?string $installer = 'npm', bool $withoutInteraction = false): void { - $shouldPrompt = $force || $isCI; + $shouldPrompt = $force || $withoutInteraction; if ($shouldPrompt || confirm('Would you like to install the NativePHP NPM dependencies?', true)) { note('Installing NPM dependencies (This may take a while)...'); if (! $installer) { - $this->installDependencies(isCI: $isCI); + $this->installDependencies(withoutInteraction: $withoutInteraction); } else { - $this->installDependencies(installer: $installer, isCI: $isCI); + $this->installDependencies(installer: $installer, withoutInteraction: $withoutInteraction); } $this->output->newLine(); } } - protected function installDependencies(?string $installer = null, bool $isCI = false): void + protected function installDependencies(?string $installer = null, bool $withoutInteraction = false): void { [$installer, $command] = $this->getInstallerAndCommand(installer: $installer); note("Installing NPM dependencies using the {$installer} package manager..."); - $this->executeCommand(command: $command, isCI: $isCI); + $this->executeCommand(command: $command, withoutInteraction: $withoutInteraction); } protected function getInstallerAndCommand(?string $installer, $type = 'install'): array From a6c4ae49b5f5cef4a547809b7d8bc2cc5e8b3730 Mon Sep 17 00:00:00 2001 From: Dan Johnson Date: Wed, 16 Aug 2023 23:35:17 +0100 Subject: [PATCH 6/6] fix: --no-interaction is a global Symfony Console option flag, so no need to specify it --- src/Commands/BuildCommand.php | 2 +- src/Commands/InstallCommand.php | 2 +- src/Commands/PublishCommand.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 5e52aebc..4c4d1609 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -12,7 +12,7 @@ class BuildCommand extends Command { use LocatesPhpBinary; - protected $signature = 'native:build {os=all : The operating system to build for (all, linux, mac, windows)} {--no-interaction : Whether interaction should be disabled}'; + protected $signature = 'native:build {os=all : The operating system to build for (all, linux, mac, windows)}'; public function handle() { diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 743c627e..28b2367d 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -12,7 +12,7 @@ class InstallCommand extends Command { use Installer; - protected $signature = 'native:install {--force : Overwrite existing files by default} {--installer=npm : The package installer to use: npm, yarn or pnpm} {--no-interaction : Whether interaction should be disabled}'; + protected $signature = 'native:install {--force : Overwrite existing files by default} {--installer=npm : The package installer to use: npm, yarn or pnpm}'; protected $description = 'Install all of the NativePHP resources'; diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php index e36907a6..05e77ea5 100644 --- a/src/Commands/PublishCommand.php +++ b/src/Commands/PublishCommand.php @@ -12,7 +12,7 @@ class PublishCommand extends Command { use LocatesPhpBinary; - protected $signature = 'native:publish {os=mac} {--no-interaction : Whether interaction should be disabled}'; + protected $signature = 'native:publish {os=mac}'; public function handle() {