From 49030b00d5c465008f430ea2b6c9202c74c29934 Mon Sep 17 00:00:00 2001 From: eb019509 Date: Sun, 24 Jun 2018 12:36:01 -0500 Subject: [PATCH 1/5] Build/test script fixes --- Build.ps1 | 18 +++--------------- Test.ps1 | 11 ++++++++--- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index a8046df..2f91721 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,22 +1,10 @@ [CmdletBinding()] param( - [Parameter(ParameterSetName='DefaultBuild')] - [Parameter(ParameterSetName='PublishByName')] + [String]$PackageName = (Split-Path $PSScriptRoot -Leaf), [String]$RepoName = 'TempLocalPSRepo', - - [Parameter(ParameterSetName='DefaultBuild')] - [Parameter(ParameterSetName='PublishByName')] [String]$RepoLocation = $PSScriptRoot, - - [Parameter(ParameterSetName='DefaultBuild')] - [Parameter(ParameterSetName='PublishByName')] [String]$NuGetApiKey, - - [Parameter(ParameterSetName='PublishByName',Mandatory=$False)] - [Switch]$PublishFromModulePath, - - [Parameter(ParameterSetName='PublishByName',Mandatory=$True)] - [String]$PackageName + [Switch]$PublishFromModulePath ) if ((Get-PSRepository -Name $RepoName -ErrorAction SilentlyContinue) -ne $null) { @@ -25,7 +13,7 @@ if ((Get-PSRepository -Name $RepoName -ErrorAction SilentlyContinue) -ne $null) Register-PSRepository -Name $RepoName -SourceLocation $RepoLocation -PublishLocation $RepoLocation if (((Find-Package -Name $PackageName -Source $RepoName -ErrorAction SilentlyContinue) -ne $null) -and (!$NuGetApiKey)) { - Remove-Item (Join-Path -Path $RepoLocation -ChildPath "$Package") + Remove-Item (Join-Path -Path $RepoLocation -ChildPath "$PackageName*.nupkg") } $publishParams = @{ diff --git a/Test.ps1 b/Test.ps1 index 55737bf..722e97f 100644 --- a/Test.ps1 +++ b/Test.ps1 @@ -7,17 +7,22 @@ param( [String]$BuildScript = './build.ps1' ) +if (!$Prebuilt) { + . $BuildScript -PackageName $PackageName -RepoName $RepoName -RepoLocation $RepoLocation +} + if ((Get-PSRepository -Name $RepoName -ErrorAction SilentlyContinue) -ne $null) { Unregister-PSRepository -Name $RepoName } Register-PSRepository -Name $RepoName -SourceLocation $RepoLocation -PublishLocation $RepoLocation try { - Install-Package -Name $packageName -Source $RepoName -Force + Uninstall-Package -Name $PackageName -Force -ErrorAction SilentlyContinue + Install-Package -Name $PackageName -Source $RepoName -Force - Invoke-Pester "./Test/$packageName.tests.ps1" -OutputFile worker_TestsResults.xml -OutputFormat NUnitXML + Invoke-Pester "./Test/$PackageName.tests.ps1" -OutputFile worker_TestsResults.xml -OutputFormat NUnitXML } finally { - Uninstall-Package -name $packageName -Force + Uninstall-Package -Name $PackageName -Force Unregister-PSRepository -Name $RepoName } From fed0c49211331c120b216f45d6dcbfcab1acc2e7 Mon Sep 17 00:00:00 2001 From: eb019509 Date: Sun, 24 Jun 2018 12:36:53 -0500 Subject: [PATCH 2/5] Uses the actual source name to in the FPR --- ChocolateyGet.psm1 | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ChocolateyGet.psm1 b/ChocolateyGet.psm1 index e02ab3a..5a43a86 100644 --- a/ChocolateyGet.psm1 +++ b/ChocolateyGet.psm1 @@ -262,7 +262,7 @@ function Find-Package { Name = $pkgname; Version = $pkgversion; versionScheme = "MultiPartNumeric"; - Source = $script:PackageSourceName; + Source = $selectedSource; } $sid = New-SoftwareIdentity @swidObject @@ -568,6 +568,7 @@ function Process-Package [parameter()] [string] $Name, + [Parameter()] [string] $RequiredVersion, @@ -629,27 +630,26 @@ function Process-Package if ($pkgname -and $pkgversion) { - # filter on version - if((Test-Version -Version $pkgversion.TrimStart('v') ` - -RequiredVersion $requiredVersion ` - -MinimumVersion $minimumVersion ` - -MaximumVersion $maximumVersion )) - { - $swidObject = @{ - FastPackageReference = $pkgname+"#"+ $pkgversion.TrimStart('v')+"#"+$script:PackageSourceName; - Name = $pkgname; - Version = $pkgversion; - versionScheme = "MultiPartNumeric"; - Source = $script:PackageSourceName; - } - - $sid = New-SoftwareIdentity @swidObject - Write-Output -InputObject $sid - if(-Not $actionTaken) {$actionTaken = $true} - } + # filter on version + if((Test-Version -Version $pkgversion.TrimStart('v') ` + -RequiredVersion $requiredVersion ` + -MinimumVersion $minimumVersion ` + -MaximumVersion $maximumVersion )) + { + $swidObject = @{ + FastPackageReference = $pkgname+"#"+ $pkgversion.TrimStart('v')+"#"+$script:PackageSourceName; + Name = $pkgname; + Version = $pkgversion; + versionScheme = "MultiPartNumeric"; + Source = $script:PackageSourceName; + } + + $sid = New-SoftwareIdentity @swidObject + Write-Output -InputObject $sid + if(-Not $actionTaken) {$actionTaken = $true} + } } } - } if ($OperationMessage) @@ -660,7 +660,7 @@ function Process-Package } else { - Write-Error ($LocalizedData.OperationFailed -f $OperationMessage, $FastPackageReference) + Throw ($LocalizedData.OperationFailed -f $OperationMessage, $FastPackageReference) } } From ed01919d015fb106e6eb67278cf962d52f0841b8 Mon Sep 17 00:00:00 2001 From: eb019509 Date: Sun, 24 Jun 2018 12:37:09 -0500 Subject: [PATCH 3/5] Make the Choco error text more clear --- ChocolateyGet.Resource.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChocolateyGet.Resource.psd1 b/ChocolateyGet.Resource.psd1 index 06d9358..797a589 100644 --- a/ChocolateyGet.Resource.psd1 +++ b/ChocolateyGet.Resource.psd1 @@ -25,7 +25,7 @@ ConvertFrom-StringData @' NotInstalled=Package '{0}' is not installed. FailToInstall=Failed to install the package because the fast reference '{0}' is incorrect. FailToInstallChoco=choco installed failed. You may relaunch PowerShell as elevated mode and try again. - OperationFailed='{0}' '{1}' Failed. You may relaunch PowerShell as elevated mode and try again with -Verbose -Debug to get more information. + OperationFailed='{0}' '{1}' Failed. You may relaunch PowerShell as elevated mode or try again with -Verbose -Debug to get more information. FoundNewerChocolatey=Found Chocolatey version '{0}' is greater than the installed one '{1}' InvalidVersionFormat=Version '{0}' does not match the regex '{1}' From 0954cc143eef99858c92a4910ceb33f46f077b4a Mon Sep 17 00:00:00 2001 From: eb019509 Date: Sun, 24 Jun 2018 12:37:22 -0500 Subject: [PATCH 4/5] Increment the artifact version --- ChocolateyGet.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChocolateyGet.psd1 b/ChocolateyGet.psd1 index 3e63461..7efc386 100644 --- a/ChocolateyGet.psd1 +++ b/ChocolateyGet.psd1 @@ -1,7 +1,7 @@ @{ RootModule = 'ChocolateyGet.psm1' -ModuleVersion = '1.0.1' +ModuleVersion = '1.0.2' GUID = 'c1735ed7-8b2f-426a-8cbc-b7feb6b8288d' Author = 'Jianyun' Copyright = '' From bf1856d0de12bd13724b22bd10749afdd91f4c1b Mon Sep 17 00:00:00 2001 From: eb019509 Date: Mon, 25 Jun 2018 05:51:47 -0500 Subject: [PATCH 5/5] Fix handling FPR passed from DSC, and Choco better error handling --- ChocolateyGet.psm1 | 82 ++++++++++++++++++++++++++++++++++++---------- README.md | 4 +++ 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/ChocolateyGet.psm1 b/ChocolateyGet.psm1 index 5a43a86..ab57893 100644 --- a/ChocolateyGet.psm1 +++ b/ChocolateyGet.psm1 @@ -258,7 +258,7 @@ function Find-Package { -MaximumVersion $maximumVersion )) { $swidObject = @{ - FastPackageReference = $pkgname+"#"+ $pkgversion+"#"+$script:PackageSourceName; + FastPackageReference = $pkgname+"#"+ $pkgversion+"#"+$selectedSource; Name = $pkgname; Version = $pkgversion; versionScheme = "MultiPartNumeric"; @@ -371,18 +371,32 @@ function Install-Package Write-debug ("Calling $installCmd $additionalArgs") $progress = 1 $job=Start-Job -ScriptBlock { - & $args[0] $args[1] $args[2] - } -ArgumentList @($script:ChocoExePath, $installCmd, $additionalArgs) + & $args[0] $args[1] $args[2]; + if ($LASTEXITCODE -ne 0) { + Throw "Choco.exe failed with exit code $LASTEXITCODE" + } + } -ArgumentList @($script:ChocoExePath, $installCmd, $additionalArgs) Show-Progress -ProgressMessage $LocalizedData.InstallingPackage -PercentComplete $progress -ProgressId $script:InstallPackageId - $packages= $job | Receive-Job -Wait + $packages= $job | Receive-Job -Wait + Process-Package -Name $name ` -RequiredVersion $version ` -OperationMessage $LocalizedData.InstallingPackage ` -ProgressId $script:InstallPackageId ` -PercentComplete $progress ` - -Packages $packages - } + -Packages $packages ` + -Source $source + + if ($job.State -eq 'Failed') { + ThrowError -ExceptionName 'System.OperationCanceledException' ` + -ExceptionMessage ($LocalizedData.OperationFailed -f "Install",$fastPackageReference) ` + -ErrorID 'JobFailure' ` + -CallerPSCmdlet $PSCmdlet ` + -ErrorCategory InvalidOperation ` + -ExceptionObject $job + } +} # It is required to implement this function for the providers that support UnInstall-Package. function UnInstall-Package @@ -411,6 +425,7 @@ function UnInstall-Package $name =$matches.name $version = $Matches.version + $source = $Matches.source if (-not ($name -and $version)) { @@ -437,11 +452,15 @@ function UnInstall-Package Write-debug ("calling $script:ChocoExePath $unInstallCmd $additionalArgs") $progress = 1 $job=Start-Job -ScriptBlock { - & $args[0] $args[1] $args[2] - } -ArgumentList @($script:ChocoExePath, $unInstallCmd, $args) + & $args[0] $args[1] $args[2]; + if ($LASTEXITCODE -ne 0) { + Throw "Choco.exe failed with exit code $LASTEXITCODE" + } + } -ArgumentList @($script:ChocoExePath, $unInstallCmd, $args) Show-Progress -ProgressMessage $LocalizedData.UnInstallingPackage -PercentComplete $progress -ProgressId $script:UnInstallPackageId - $packages= $job | Receive-Job -Wait + $packages= $job | Receive-Job -Wait + Write-debug ("Completed calling $script:ChocoExePath $unInstallCmd") Process-Package -Name $name ` @@ -449,8 +468,17 @@ function UnInstall-Package -OperationMessage $LocalizedData.UnInstallingPackage ` -ProgressId $script:UnInstallPackageId ` -PercentComplete $progress -Packages $packages ` - -NameContainsWildCard $true # pass in $true so that we do not exact name match because choco returns different sometimes. - + -Source $source ` + -NameContainsWildCard $true # pass in $true so that we do not exact name match because choco returns different sometimes. + + if ($job.State -eq 'Failed') { + ThrowError -ExceptionName 'System.OperationCanceledException' ` + -ExceptionMessage ($LocalizedData.OperationFailed -f "Uninstall",$fastPackageReference) ` + -ErrorID 'JobFailure' ` + -CallerPSCmdlet $PSCmdlet ` + -ErrorCategory InvalidOperation ` + -ExceptionObject $job + } } @@ -599,7 +627,11 @@ function Process-Package [parameter()] [bool] - $NameContainsWildCard = $false + $NameContainsWildCard = $false, + + [parameter()] + [string] + $Source = $script:PackageSourceName ) @@ -627,7 +659,7 @@ function Process-Package Write-Debug ("Skipping processing: '{0}'" -f $pkg) continue } - + if ($pkgname -and $pkgversion) { # filter on version @@ -637,11 +669,11 @@ function Process-Package -MaximumVersion $maximumVersion )) { $swidObject = @{ - FastPackageReference = $pkgname+"#"+ $pkgversion.TrimStart('v')+"#"+$script:PackageSourceName; + FastPackageReference = $pkgname+"#"+ $pkgversion.TrimStart('v')+"#"+$Source; Name = $pkgname; Version = $pkgversion; versionScheme = "MultiPartNumeric"; - Source = $script:PackageSourceName; + Source = $Source; } $sid = New-SoftwareIdentity @swidObject @@ -829,20 +861,34 @@ function Install-ChocoBinaries Write-Debug ("Calling $script:ChocoExePath upgrade chocolatey") $job=Start-Job -ScriptBlock { - & $args[0] upgrade chocolatey -y - } -ArgumentList @($script:ChocoExePath) + & $args[0] upgrade chocolatey -y; + if ($LASTEXITCODE -ne 0) { + Throw "Choco.exe failed with exit code $LASTEXITCODE" + } + } -ArgumentList @($script:ChocoExePath) Show-Progress -ProgressMessage $LocalizedData.UpgradingChoco ` -PercentComplete $progress ` -ProgressId $script:InstallChocoId - $packages= $job | Receive-Job -Wait + $packages= $job | Receive-Job -Wait + Process-Package -Name $name ` -RequiredVersion $pkgversion ` -OperationMessage $LocalizedData.UpgradingChoco ` -ProgressId $script:InstallChocoId ` -PercentComplete $progress ` -Packages $packages + + if ($job.State -eq 'Failed') { + ThrowError -ExceptionName 'System.OperationCanceledException' ` + -ExceptionMessage ($LocalizedData.OperationFailed -f "Install",$name) ` + -ErrorID 'JobFailure' ` + -CallerPSCmdlet $PSCmdlet ` + -ErrorCategory InvalidOperation ` + -ExceptionObject $job + } + } } else diff --git a/README.md b/README.md index c7ae68d..301b750 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +### Jenkins Build Status - Production +[![Build Status](https://jenkins.cerner.com/communityworks/buildStatus/icon?job=CommunityWorks/ChocolateyGet/production)](https://jenkins.cerner.com/communityworks/blue/organizations/jenkins/CommunityWorks%2FChocolateyGet/activity) + +### Jenkins Build Status - Integration [![Build Status](https://jenkins.cerner.com/communityworks/buildStatus/icon?job=CommunityWorks/ChocolateyGet/integration)](https://jenkins.cerner.com/communityworks/blue/organizations/jenkins/CommunityWorks%2FChocolateyGet/activity) # ChocolateyGet