Fixed dependency conflict with older module versions #396 (#397)

This commit is contained in:
Bernie White 2022-05-10 22:45:30 +10:00 коммит произвёл GitHub
Родитель 19c7f091a9
Коммит 6532a0d150
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 70 добавлений и 33 удалений

Просмотреть файл

@ -15,23 +15,32 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
What's changed since v1.5.0:
- New features:
- Added support for PSRule v2. [#312](https://github.com/microsoft/PSRule-pipelines/issues/312)
- Added support for PSRule v2 by @BernieWhite.
[#312](https://github.com/microsoft/PSRule-pipelines/issues/312)
- Added `ps-rule-assert@2` task for PSRule v2.
- Added `ps-rule-install@2` task for PSRule v2.
- Added support for outputting analysis results as SARIF. [#315](https://github.com/microsoft/PSRule-pipelines/issues/315)
- Added support for outputting analysis results as SARIF by @BernieWhite.
[#315](https://github.com/microsoft/PSRule-pipelines/issues/315)
- To use the SARIF output format set the `outputFormat` parameter to `Sarif`.
- Currently a pre-release version of PSRule must be used.
- Added the ability to use a specific version of PSRule. [#314](https://github.com/microsoft/PSRule-pipelines/issues/314)
- Added the ability to use a specific version of PSRule by @BernieWhite.
[#314](https://github.com/microsoft/PSRule-pipelines/issues/314)
- To install a specific version set the version parameter.
- By default, the latest stable version of PSRule is used.
- Added the ability to use an alternative PowerShell repository. [#353](https://github.com/microsoft/PSRule-pipelines/issues/353)
- Added the ability to use an alternative PowerShell repository by @BernieWhite.
[#353](https://github.com/microsoft/PSRule-pipelines/issues/353)
- Register and authenticate to the repository in PowerShell if required.
- Configure repository to install modules from the named repository.
- General improvements:
- Expose more rule error output in CI. [#308](https://github.com/microsoft/PSRule-pipelines/issues/308)
- Expose more rule error output in CI by @ArmaanMcleod.
[#308](https://github.com/microsoft/PSRule-pipelines/issues/308)
- Bug fixes:
- Fixed failure loading VstsTaskSdk. [#361](https://github.com/microsoft/PSRule-pipelines/issues/361)
- Fixed handling of unset path. [#363](https://github.com/microsoft/PSRule-pipelines/issues/363)
- Fixed failure loading VstsTaskSdk by @BernieWhite.
[#361](https://github.com/microsoft/PSRule-pipelines/issues/361)
- Fixed handling of unset path by @BernieWhite.
[#363](https://github.com/microsoft/PSRule-pipelines/issues/363)
- Fixed dependency conflict with older module versions by @BernieWhite.
[#396](https://github.com/microsoft/PSRule-pipelines/issues/396)
## v1.5.0

Просмотреть файл

@ -153,6 +153,9 @@ else {
#
# Check and install modules
#
Write-Host "`#`#[group]Checking PSRule";
$dependencyFile = Join-Path -Path $PSScriptRoot -ChildPath 'modules.json';
$latestVersion = (Get-Content -Path $dependencyFile -Raw | ConvertFrom-Json -AsHashtable -Depth 5).dependencies.PSRule.version;
$checkParams = @{
@ -176,8 +179,14 @@ foreach ($m in $installed) {
Write-Host "[info] Using existing module $($m.Name): $($m.Version)";
}
Write-Host "`#`#[endgroup]";
#
# Look for existing modules
Write-Host '';
#
Write-Host "`#`#[group]Checking modules";
$moduleNames = @()
if (![String]::IsNullOrEmpty($Modules)) {
$moduleNames = $Modules.Split(',', [System.StringSplitOptions]::RemoveEmptyEntries);
@ -218,7 +227,7 @@ foreach ($m in $moduleNames) {
}
try {
$checkParams = @{ RequiredVersion = $checkParams.RequiredVersion.Split('-')[0] }
$checkParams = @{ MinimumVersion = $checkParams.RequiredVersion.Split('-')[0] }
$Null = Import-Module PSRule @checkParams -ErrorAction Stop;
$version = (Get-Module PSRule).Version;
}
@ -228,10 +237,14 @@ catch {
$Host.SetShouldExit(1);
}
Write-Host "`#`#[endgroup]";
#
# Run assert pipeline
#
Write-Host '';
Write-Host "`#`#[group]Checking environment";
Write-Host "[info] Using Version: $version";
Write-Host "[info] Using Workspace: $workspacePath"
Write-Host "[info] Using PWD: $PWD";
@ -244,6 +257,8 @@ Write-Host "[info] Using InputPath: $InputPath";
Write-Host "[info] Using OutputFormat: $OutputFormat";
Write-Host "[info] Using OutputPath: $OutputPath";
Write-Host "`#`#[endgroup]";
try {
Push-Location -Path $Path;
$invokeParams = @{
@ -289,10 +304,16 @@ try {
}
catch [PSRule.Pipeline.RuleException] {
Write-Host "`#`#vso[task.logissue type=error]$($_.Exception.Message)";
Write-Host "$($_.Exception.ScriptStackTrace)";
HostExit
}
catch [PSRule.Pipeline.FailPipelineException] {
Write-Host "`#`#vso[task.logissue type=error]$(Get-VstsLocString -Key 'AssertFailed')";
HostExit
}
catch {
Write-Host "`#`#vso[task.logissue type=error]$(Get-VstsLocString -Key 'AssertFailed')";
Write-Host "`#`#vso[task.logissue type=error]$($_.Exception.Message)";
Write-Host "$($_.Exception.ScriptStackTrace)";
HostExit
}
finally {

Просмотреть файл

@ -83,27 +83,34 @@ if ($PreRelease) {
$moduleParams['AllowPrerelease'] = $True;
}
# Install each module if not already installed
foreach ($m in $moduleNames) {
Write-Host "[info] Checking module: $m";
if ($Null -eq (Get-InstalledModule -Name $m -ErrorAction Ignore)) {
Write-Host "[info] Installing module: $m";
$Null = Install-Module -Name $m @moduleParams -Repository $Repository -AllowClobber;
}
elseif ($Latest) {
Write-Host "[info] Updating module: $m";
$Null = Update-Module -Name $m @moduleParams;
}
else {
WriteDebug "Module '$m' already installed";
}
# Check
if ($Null -eq (Get-InstalledModule -Name $m)) {
$exitResult = 1;
Write-Host "[error] Failed to install module: $m";
}
else {
Write-Host "[info] Using module: $m - v$((Get-InstalledModule -Name $m).Version)";
try {
# Install each module if not already installed
foreach ($m in $moduleNames) {
Write-Host "[info] Checking module: $m";
if ($Null -eq (Get-InstalledModule -Name $m -ErrorAction Ignore)) {
Write-Host "[info] Installing module: $m";
$Null = Install-Module -Name $m @moduleParams -Repository $Repository -AllowClobber;
}
elseif ($Latest) {
Write-Host "[info] Updating module: $m";
$Null = Update-Module -Name $m @moduleParams;
}
else {
WriteDebug "Module '$m' already installed";
}
# Check
if ($Null -eq (Get-InstalledModule -Name $m)) {
$exitResult = 1;
Write-Host "[error] Failed to install module: $m";
}
else {
Write-Host "[info] Using module: $m - v$((Get-InstalledModule -Name $m).Version)";
}
}
}
$Host.SetShouldExit($exitResult);
catch {
Write-Host "`#`#vso[task.logissue type=error]$($_.Exception.Message)";
Write-Host "$($_.Exception.ScriptStackTrace)";
HostExit
}
Write-Host '---';