-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(GH-44) Pass the Source correctly to choco #84
Merged
ferventcoder
merged 1 commit into
chocolatey:development
from
Jark:pass-in-source-parameter-to-choco
Jun 22, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,17 +85,17 @@ function Set-TargetResource | |
Write-Verbose -Message "Uninstalling $Name due to version mis-match" | ||
UninstallPackage -pName $Name -pParams $Params | ||
Write-Verbose -Message "Re-Installing $Name with correct version $version" | ||
InstallPackage -pName $Name -pParams $Params -pVersion $Version -cParams $chocoParams | ||
InstallPackage -pName $Name -pParams $Params -pVersion $Version -pSource $Source -cParams $chocoParams | ||
} elseif ($AutoUpgrade) { | ||
Write-Verbose -Message "Upgrading $Name due to version mis-match" | ||
Upgrade-Package -pName $Name -pParams $Params | ||
Upgrade-Package -pName $Name -pParams $Params -pSource $Source | ||
} | ||
} | ||
} | ||
} else { | ||
$whatIfShouldProcess = $pscmdlet.ShouldProcess("$Name", 'Install package from Chocolatey') | ||
if ($whatIfShouldProcess) { | ||
InstallPackage -pName $Name -pParams $Params -pVersion $Version -cParams $chocoParams | ||
InstallPackage -pName $Name -pParams $Params -pVersion $Version -pSource $Source -cParams $chocoParams | ||
} | ||
} | ||
} | ||
|
@@ -152,7 +152,7 @@ function Test-TargetResource | |
Write-Verbose -Message "Checking if $Name is installed" | ||
|
||
if ($AutoUpgrade -and $isInstalled) { | ||
$result = Test-LatestVersionInstalled -pName $Name | ||
$result = Test-LatestVersionInstalled -pName $Name -pSource $Source | ||
} else { | ||
$result = $isInstalled | ||
} | ||
|
@@ -204,6 +204,8 @@ function InstallPackage | |
[Parameter(Position=2)] | ||
[string]$pVersion, | ||
[Parameter(Position=3)] | ||
[string]$pSource, | ||
[Parameter(Position=4)] | ||
[string]$cParams | ||
) | ||
|
||
|
@@ -216,6 +218,9 @@ function InstallPackage | |
if ($pVersion) { | ||
$chocoinstallparams += " --version=`"$pVersion`"" | ||
} | ||
if ($pSource) { | ||
$chocoinstallparams += " --source=`"$pSource`"" | ||
} | ||
if ($cParams) { | ||
$chocoinstallparams += " $cParams" | ||
} | ||
|
@@ -251,14 +256,12 @@ function UninstallPackage | |
$packageUninstallOuput = choco uninstall $pName --params="$pParams" -y | ||
} | ||
|
||
|
||
Write-Verbose -Message "Package uninstall output $packageUninstallOuput " | ||
|
||
#refresh path varaible in powershell, as choco doesn"t, to pull in git | ||
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine') | ||
} | ||
|
||
|
||
function IsPackageInstalled | ||
{ | ||
param( | ||
|
@@ -292,16 +295,26 @@ function IsPackageInstalled | |
} | ||
|
||
Function Test-LatestVersionInstalled { | ||
[Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingInvokeExpression','')] | ||
param( | ||
[Parameter(Position=0,Mandatory)] | ||
[string]$pName | ||
[Parameter(Mandatory)] | ||
[string]$pName, | ||
[Parameter(Mandatory)] | ||
[string]$pSource | ||
) | ||
Write-Verbose -Message "Testing if $pName can be upgraded" | ||
|
||
$queryres = choco upgrade $pName --noop | Select-String -Pattern $pName | ||
$queryres | ForEach-Object {Write-Verbose -Message $_} | ||
[string]$chocoupgradeparams = '--noop' | ||
if ($pSource) { | ||
$chocoupgradeparams += " --source=`"$pSource`"" | ||
} | ||
|
||
Write-Verbose -Message "Testing if $pName can be upgraded: 'choco upgrade $pName $chocoupgradeparams'" | ||
|
||
$packageUpgradeOuput = Invoke-Expression -Command "choco upgrade $pName $chocoupgradeparams" | ||
$packageUpgradeOuput | ForEach-Object {Write-Verbose -Message $_} | ||
|
||
if ($queryres -match "$pName.*is the latest version available based on your source") { | ||
if ($packageUpgradeOuput -match "$pName.*is the latest version available based on your source") { | ||
return $true | ||
} | ||
return $false | ||
|
@@ -337,6 +350,8 @@ Function Upgrade-Package { | |
[Parameter(Position=1)] | ||
[string]$pParams, | ||
[Parameter(Position=2)] | ||
[string]$pSource, | ||
[Parameter(Position=3)] | ||
[string]$cParams | ||
) | ||
|
||
|
@@ -347,10 +362,13 @@ Function Upgrade-Package { | |
if ($pParams) { | ||
$chocoupgradeparams += " --params=`"$pParams`"" | ||
} | ||
if ($pSource) { | ||
$chocoupgradeparams += " --source=`"$pSource`"" | ||
} | ||
if ($cParams) { | ||
$chocoupgradeparams += " $cParams" | ||
} | ||
$cmd = "choco upgrade -dv -y $pName $chocoupgradeparams" | ||
$cmd = "choco upgrade $pName $chocoupgradeparams" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 on removing duplicates |
||
Write-Verbose -Message "Upgrade command: '$cmd'" | ||
|
||
if (-not (IsPackageInstalled -pName $pName)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the use of Invoke-Expression to
Test-LatestVersionInstalled
, since the other internal functions (InstallPackage
/Upgrade-Package
), seem to use Invoke-Expression as well and that specificPSScriptAnalyzer
rule will cause the build to fail.I don't mind changing all uses of Invoke-Expression to
Start-Process
in this pull request, but this might be better to do in a different commit, just let me know.