Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
|
53599f1fc8 | |
|
0a5c12e366 | |
|
86408821a5 | |
|
e9d5e8468f | |
|
f9d5dd6b9e |
|
@ -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
|
|
@ -1,12 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
namespace taskman;
|
namespace taskman;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
task('dotnet_set_env', ['always' => true], function() {
|
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)
|
||||||
|
@ -21,11 +22,8 @@ function dotnet_shell_get($cmd)
|
||||||
|
|
||||||
function dotnet_set_env()
|
function dotnet_set_env()
|
||||||
{
|
{
|
||||||
|
//TODO: do we need this one?
|
||||||
putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1");
|
putenv("DOTNET_CLI_TELEMETRY_OPTOUT=1");
|
||||||
|
|
||||||
$dotnet_path = DotnetSupport::getPath();
|
DotnetSupport::addEnvPath();
|
||||||
if(is_win())
|
|
||||||
putenv("PATH=$dotnet_path;".getenv('PATH'));
|
|
||||||
else
|
|
||||||
putenv("PATH=$dotnet_path:".getenv('PATH'));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
namespace taskman;
|
namespace taskman;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
//NOTE: this class must not have any dependencies on any packages
|
//NOTE: this class must not have any dependencies on any packages
|
||||||
class DotnetSupport
|
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();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$dotnet_curr_ver = self::shellGet("dotnet --version");
|
$dotnet_curr_ver = self::shellGet("dotnet --version");
|
||||||
|
@ -20,22 +27,35 @@ class DotnetSupport
|
||||||
}
|
}
|
||||||
catch(\Throwable $th)
|
catch(\Throwable $th)
|
||||||
{
|
{
|
||||||
$has_dotnet = false;
|
$force = true;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
//let's restore 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();
|
||||||
|
|
||||||
$version_parts = explode('.', $version);
|
$version_parts = explode('.', $version);
|
||||||
$channel = $version_parts[0].'.'.$version_parts[1];
|
$channel = $version_parts[0].'.'.$version_parts[1];
|
||||||
if(self::isWin())
|
if(self::isWin())
|
||||||
self::Shell("powershell -NoProfile -ExecutionPolicy unrestricted Invoke-Expression '\"$install_file_path\" -Channel $channel'");
|
self::shell("powershell -NoProfile -ExecutionPolicy unrestricted Invoke-Expression '\"$install_file_path\" -Channel $channel'");
|
||||||
else
|
else
|
||||||
self::Shell("\"$install_file_path\" --channel $channel");
|
self::shell("\"$install_file_path\" --channel $channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
static function getInstallerPath() : string
|
static function getInstallerPath() : string
|
||||||
|
@ -59,6 +79,26 @@ class DotnetSupport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function addEnvPath(string $path = '') : string
|
||||||
|
{
|
||||||
|
$prev_path = getenv('PATH');
|
||||||
|
|
||||||
|
if(!$path)
|
||||||
|
$path = DotnetSupport::getPath();
|
||||||
|
|
||||||
|
if(self::isWin())
|
||||||
|
self::setEnvPath("$path;$prev_path");
|
||||||
|
else
|
||||||
|
self::setEnvPath("$path:$prev_path");
|
||||||
|
|
||||||
|
return $prev_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function setEnvPath(string $path)
|
||||||
|
{
|
||||||
|
putenv("PATH=$path");
|
||||||
|
}
|
||||||
|
|
||||||
static function isWin() : bool
|
static function isWin() : bool
|
||||||
{
|
{
|
||||||
return !(DIRECTORY_SEPARATOR == '/');
|
return !(DIRECTORY_SEPARATOR == '/');
|
||||||
|
|
Loading…
Reference in New Issue