Compare commits

..

3 Commits

Author SHA1 Message Date
Pavel Shevaev 53599f1fc8 Making installer more robust 2025-03-03 15:31:48 +03:00
Pavel Shevaev 0a5c12e366 Making installer more robust 2025-03-03 15:27:44 +03:00
Pavel Shevaev 86408821a5 Добавить CHANGELOG.md 2024-11-21 14:39:10 +03:00
3 changed files with 26 additions and 7 deletions

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
## v0.0.7
- Setting proper PATH when checking for dotnet during composer post-install step
## v0.0.6
- Initial working version

View File

@ -6,8 +6,8 @@ task('dotnet_set_env', ['always' => true], function() {
dotnet_set_env(); dotnet_set_env();
}); });
task('dotnet_install', function() { task('dotnet_install', function(array $args) {
DotnetSupport::install(); DotnetSupport::installEx(isset($args[0]) && $args[0] === '--force');
}); });
function dotnet_shell($cmd) function dotnet_shell($cmd)

View File

@ -7,13 +7,18 @@ class DotnetSupport
{ {
const VERSION = "8.0.0"; const VERSION = "8.0.0";
//NOTE: this is a composer event, it doesn't accept any arguments
static function install() static function install()
{
self::installEx(false);
}
static function installEx(bool $force = false)
{ {
$version = self::VERSION; $version = self::VERSION;
$has_dotnet = true;
$dotnet_curr_ver = ""; $dotnet_curr_ver = "";
//let's add to PATH
$prev_path = self::addEnvPath(); $prev_path = self::addEnvPath();
try try
{ {
@ -22,17 +27,26 @@ class DotnetSupport
} }
catch(\Throwable $th) catch(\Throwable $th)
{ {
$has_dotnet = false; $force = true;
} }
finally finally
{ {
//let's restore prev PATH
self::setEnvPath($prev_path); self::setEnvPath($prev_path);
} }
if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0) if(!$force)
{
$dotnet_ver_items = explode('.', $dotnet_curr_ver);
$target_ver_items = explode('.', $version);
//let's force install if current major version is not equal
$force = isset($dotnet_ver_items[0]) && $dotnet_ver_items[0] !== $target_ver_items[0];
}
if(!$force)
return; return;
print("DOTNET VERSION MISMATCH: $dotnet_curr_ver < $version\n"); print("DOTNET VERSION MISMATCH: $dotnet_curr_ver is not compatible with $version\n");
$install_file_path = self::getInstallerPath(); $install_file_path = self::getInstallerPath();