Skip to content

Commit

Permalink
Merge pull request jianyunt#12 from eb019509/master
Browse files Browse the repository at this point in the history
Various fixes found in testing
  • Loading branch information
ethanbergstrom authored and GitHub Enterprise committed Jun 25, 2018
2 parents 029fe76 + 37e85c5 commit 18b4f33
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 56 deletions.
18 changes: 3 additions & 15 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 = @{
Expand Down
2 changes: 1 addition & 1 deletion ChocolateyGet.Resource.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
2 changes: 1 addition & 1 deletion ChocolateyGet.psd1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@{

RootModule = 'ChocolateyGet.psm1'
ModuleVersion = '1.0.1'
ModuleVersion = '1.0.2'
GUID = 'c1735ed7-8b2f-426a-8cbc-b7feb6b8288d'
Author = 'Jianyun'
Copyright = ''
Expand Down
118 changes: 82 additions & 36 deletions ChocolateyGet.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ function Find-Package {
-MaximumVersion $maximumVersion ))
{
$swidObject = @{
FastPackageReference = $pkgname+"#"+ $pkgversion+"#"+$script:PackageSourceName;
FastPackageReference = $pkgname+"#"+ $pkgversion+"#"+$selectedSource;
Name = $pkgname;
Version = $pkgversion;
versionScheme = "MultiPartNumeric";
Source = $script:PackageSourceName;
Source = $selectedSource;
}

$sid = New-SoftwareIdentity @swidObject
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -411,6 +425,7 @@ function UnInstall-Package

$name =$matches.name
$version = $Matches.version
$source = $Matches.source

if (-not ($name -and $version))
{
Expand All @@ -437,20 +452,33 @@ 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 `
-RequiredVersion $version `
-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
}
}


Expand Down Expand Up @@ -568,6 +596,7 @@ function Process-Package
[parameter()]
[string]
$Name,

[Parameter()]
[string]
$RequiredVersion,
Expand Down Expand Up @@ -598,7 +627,11 @@ function Process-Package

[parameter()]
[bool]
$NameContainsWildCard = $false
$NameContainsWildCard = $false,

[parameter()]
[string]
$Source = $script:PackageSourceName
)


Expand Down Expand Up @@ -626,30 +659,29 @@ function Process-Package
Write-Debug ("Skipping processing: '{0}'" -f $pkg)
continue
}

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;
}
# filter on version
if((Test-Version -Version $pkgversion.TrimStart('v') `
-RequiredVersion $requiredVersion `
-MinimumVersion $minimumVersion `
-MaximumVersion $maximumVersion ))
{
$swidObject = @{
FastPackageReference = $pkgname+"#"+ $pkgversion.TrimStart('v')+"#"+$Source;
Name = $pkgname;
Version = $pkgversion;
versionScheme = "MultiPartNumeric";
Source = $Source;
}

$sid = New-SoftwareIdentity @swidObject
Write-Output -InputObject $sid
if(-Not $actionTaken) {$actionTaken = $true}
}
$sid = New-SoftwareIdentity @swidObject
Write-Output -InputObject $sid
if(-Not $actionTaken) {$actionTaken = $true}
}
}
}

}

if ($OperationMessage)
Expand All @@ -660,7 +692,7 @@ function Process-Package
}
else
{
Write-Error ($LocalizedData.OperationFailed -f $OperationMessage, $FastPackageReference)
Throw ($LocalizedData.OperationFailed -f $OperationMessage, $FastPackageReference)
}
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 8 additions & 3 deletions Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 18b4f33

Please sign in to comment.