Skip to content
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

Search by package ID if name and version specified #21

Merged
merged 37 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
77840a2
Search by package ID if name and version specified
ethanbergstrom Jan 23, 2021
a7f0097
Should have used Exact in the ListCommand config
ethanbergstrom Jan 23, 2021
8150cf4
Also use 'exact' for other version queries
ethanbergstrom Jan 23, 2021
01c58b3
Keep version test one version back from latest
ethanbergstrom Jan 23, 2021
050c634
Downgrade choco for exact package version search
ethanbergstrom Jan 23, 2021
74f2439
Downgrade choco CLI install and update change log
ethanbergstrom Jan 23, 2021
6559b16
Test what's wrong with the appveyor job
ethanbergstrom Jan 23, 2021
d6d47da
Checking to see if appveyor broke the build
ethanbergstrom Jan 23, 2021
85242a4
Revert "Test what's wrong with the appveyor job"
ethanbergstrom Jan 23, 2021
a655f24
Possible case sensitivity issue
ethanbergstrom Jan 23, 2021
c2e2ebe
Remove extra verbose line
ethanbergstrom Jan 23, 2021
1c0fd7a
Revert "Remove extra verbose line"
ethanbergstrom Jan 23, 2021
78461ee
Revert "Possible case sensitivity issue"
ethanbergstrom Jan 23, 2021
f9df540
Testing of sysinternals broke the pipeline
ethanbergstrom Jan 23, 2021
65ded1b
Forgot to include version in all the tests
ethanbergstrom Jan 23, 2021
857f5c9
Revert "Checking to see if appveyor broke the build"
ethanbergstrom Jan 23, 2021
50528d8
Testing in appveyor without params and args
ethanbergstrom Jan 23, 2021
890b0b5
More appveyor tests
ethanbergstrom Jan 23, 2021
2da3f6c
Revert "More appveyor tests"
ethanbergstrom Jan 23, 2021
fa39f02
Revert "Testing in appveyor without params and args"
ethanbergstrom Jan 23, 2021
d1e41ef
Trying a less privileged path
ethanbergstrom Jan 23, 2021
ba27ab8
Downgrade choco in appveyor - exact search bug
ethanbergstrom Jan 23, 2021
ac38d42
Finish Chocolatey downgrade documentation
ethanbergstrom Jan 23, 2021
f3da8ee
Fix CLI issue link in readme
ethanbergstrom Jan 23, 2021
3ebb372
Trying to track down CLI warnings in appveyor
ethanbergstrom Jan 23, 2021
85f26f9
Track down warnings part 2
ethanbergstrom Jan 23, 2021
da48978
More appveyor CLI erorr testing
ethanbergstrom Jan 23, 2021
8abf77e
More troubleshooting
ethanbergstrom Jan 23, 2021
23ef285
More tests
ethanbergstrom Jan 23, 2021
0e11e5f
Setting back to parent scope
ethanbergstrom Jan 23, 2021
3f8073e
Trying another scope
ethanbergstrom Jan 23, 2021
6a6ff5b
Upload choco logs
ethanbergstrom Jan 23, 2021
71f0169
Finally figured it out
ethanbergstrom Jan 23, 2021
f2a28ea
Misread the powershell docs
ethanbergstrom Jan 23, 2021
7d0aa23
typo
ethanbergstrom Jan 23, 2021
4759418
Cleanup from troubleshooting
ethanbergstrom Jan 23, 2021
8779692
Proper version comparison
ethanbergstrom Jan 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.0] - 2021-01-23
#### Changed
* Change default search to use exact package name if both package name and required version are specified (#20)
* Requires downgrade to Chocolatey 0.10.13 due to [a Chocolatey defect](https://github.com/chocolatey/choco/issues/1843) until 0.10.16 is released

#### Fixed
* AppVeyor builds no longer fail due to change in build image permissions
* Version min/max comparison should now work properly

## [2.0.0] - 2020-10-05
#### Added
* Searching/installing/managing multiple Chocolatey sources (#5)
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,27 @@ When used with CoreCLR, PowerShell 7.0.1 is a minimum requirement due to [a comp
### Save a package
Save-Package is not supported with the ChocolateyGet provider, due to Chocolatey not supporting package downloads without special licensing.

### CLI Package search with MaximumVersion / AllVersions return unexpected results
Due to [a bug with Chocolatey](https://github.com/chocolatey/choco/issues/1843) versions 0.10.14 through 0.10.15, ChocolateyGet is unable to search packages by package range via command line as of version 2.1.0.

Until [Chocolatey 0.10.16 is released](https://github.com/chocolatey/choco/milestone/43), the following workarounds are available:
- Specify `RequiredVersion` if possible
```PowerShell
Install-Package ninja -RequiredVersion 1.9.0 -Provider ChocolateyGet
```
- Downgrade Chocolatey to 0.10.13 until 0.10.16 is released (ChocolateyGet installs 0.10.13 by default)
```PowerShell
Install-Package chocolatey -RequiredVersion 0.10.13 -Provider ChocolateyGet -Force
Install-Package ninja -MaximumVersion 1.9.0 -Provider ChocolateyGet
```
- If you **must** use Chocolatey 0.10.14 or 0.10.15 for some reason, include the environment variable CHOCO_NONEXACT_SEARCH
```PowerShell
$env:CHOCO_NONEXACT_SEARCH = $true
Install-Package ninja -MaximumVersion 1.9.0 -Provider ChocolateyGet
```
- Please note - this will revert the default search behavior change requested in [Issue #20](https://github.com/jianyunt/ChocolateyGet/issues/20)
- Use ChocolateyGet via PowerShell v5 or below in Native API mode, which uses Chocolatey version 0.10.13


## Legal and Licensing
ChocolateyGet is licensed under the [MIT license](./LICENSE.txt).
9 changes: 5 additions & 4 deletions Test/ChocolateyGet.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Describe "$platform DSC-compliant package installation and uninstallation" {
}
Context 'with additional arguments' {
$package = 'sysinternals'
$argsAndParams = '--paramsglobal --params "/InstallDir=c:\windows\temp\sysinternals /QuickLaunchShortcut=false" -y --installargs MaintenanceService=false'
$argsAndParams = '--paramsglobal --params "/InstallDir='+$env:TEMP+'\sysinternals /QuickLaunchShortcut=false" -y --installargs MaintenanceService=false'

It 'searches for the latest version of a package' {
Find-Package -Provider $ChocolateyGet -Name $package -AdditionalArguments $argsAndParams | Where-Object {$_.Name -contains $package} | Should Not BeNullOrEmpty
Expand Down Expand Up @@ -84,7 +84,7 @@ Describe "$platform pipline-based package installation and uninstallation" {
}
Context 'with additional arguments' {
$package = 'sysinternals'
$argsAndParams = '--paramsglobal --params "/InstallDir=c:\windows\temp\sysinternals /QuickLaunchShortcut=false" -y --installargs MaintenanceService=false'
$argsAndParams = '--paramsglobal --params "/InstallDir='+$env:TEMP+'\sysinternals /QuickLaunchShortcut=false" -y --installargs MaintenanceService=false'

It 'searches for and silently installs the latest version of a package' {
Find-Package -Provider $ChocolateyGet -Name $package | Install-Package -Force -AdditionalArguments $argsAndParams | Where-Object {$_.Name -contains $package} | Should Not BeNullOrEmpty
Expand Down Expand Up @@ -129,8 +129,9 @@ Describe "$platform multi-source support" {
}

Describe "$platform version filters" {
$package = 'cpu-z'
$version = '1.87'
$package = 'ninja'
# Keep at least one version back, to test the 'latest' feature
$version = '1.10.1'

AfterAll {
Uninstall-Package -Name $package -Provider $ChocolateyGet -ErrorAction SilentlyContinue
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ build_script:
test_script:
- ps: Invoke-Pester -EnableExit -OutputFormat NUnitXml -OutputFile TestsResults.NativeAPI.xml
- ps: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.NativeAPI.xml))
- pwsh: Install-Package chocolatey -RequiredVersion 0.10.13 -ProviderName ChocolateyGet -Force
- pwsh: Invoke-Pester -EnableExit -OutputFormat NUnitXml -OutputFile TestsResults.CLI.xml
- pwsh: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.CLI.xml))

after_build:
- ps: Get-ChildItem $env:programdata\chocolatey\logs | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NUGET
remote: https://api.nuget.org/v3/index.json
chocolatey.lib (0.10.15)
chocolatey.lib (0.10.13)
log4net (>= 2.0.3)
log4net (2.0.3)
2 changes: 1 addition & 1 deletion src/ChocolateyGet.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'ChocolateyGet.psm1'
ModuleVersion = '2.0.0'
ModuleVersion = '2.1.0'
GUID = 'c1735ed7-8b2f-426a-8cbc-b7feb6b8288d'
Author = 'Jianyun'
Copyright = ''
Expand Down
4 changes: 3 additions & 1 deletion src/private/Install-ChocoBinaries.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ function Install-ChocoBinaries {
if (-not ([Net.ServicePointManager]::SecurityProtocol -eq [Net.SecurityProtocolType]::SystemDefault)) {
[Net.ServicePointManager]::SecurityProtocol = ([Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12)
}

# Have to keep choco pinned to 0.10.13 due to https://github.com/chocolatey/choco/issues/1843 - should be fixed in 0.10.16, which is still in beta
# https://docs.chocolatey.org/en-us/choco/setup#installing-a-particular-version-of-chocolatey
$env:chocolateyVersion = '0.10.13'
Invoke-WebRequest 'https://chocolatey.org/install.ps1' -UseBasicParsing | Invoke-Expression > $null
} catch {
ThrowError -ExceptionName 'System.OperationCanceledException' `
Expand Down
16 changes: 13 additions & 3 deletions src/private/Invoke-Choco.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ function Invoke-Choco {
Invoke-Command $genericParams
if ($Package) {
$config.Input = $Package
if (($Version -or $AllVersions) -and -not $env:CHOCO_NONEXACT_SEARCH) {
# Limit NuGet API result set to just the specific package name if version is specified
# Have to keep choco pinned to 0.10.13 due to https://github.com/chocolatey/choco/issues/1843 - should be fixed in 0.10.16, which is still in beta
$config.ListCommand.Exact = $true
}
}
$config.CommandName = [chocolatey.infrastructure.app.domain.CommandNameType]::list
}) | Out-Null
Expand Down Expand Up @@ -259,6 +264,11 @@ function Invoke-Choco {

if ($Package) {
$cmdString += "$Package "
if (($Version -or $AllVersions) -and -not $env:CHOCO_NONEXACT_SEARCH) {
# Limit NuGet API result set to just the specific package name if version is specified
# Have to keep choco pinned to 0.10.13 due to https://github.com/chocolatey/choco/issues/1843 - should be fixed in 0.10.16, which is still in beta
$cmdString += "--exact "
}
}

if ($Version) {
Expand Down Expand Up @@ -291,12 +301,12 @@ function Invoke-Choco {
# Save the output to a variable so we can inspect the exit code before submitting the output to the pipeline
$output = & $ChocoExePath $cmdString

if ($LASTEXITCODE -ne 0) {
# Add support for Error Code 2 (no results) for basic enhanced error code support
if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne 2) {
ThrowError -ExceptionName 'System.OperationCanceledException' `
-ExceptionMessage $($output | Out-String) `
-ExceptionMessage "The following command $ChocoExePath $cmdString failed with error code $LASTEXITCODE" `
-ErrorID 'JobFailure' `
-ErrorCategory InvalidOperation `
-ExceptionObject $job
} else {
if ($Install -or ($Search -and $SourceName)) {
$output | ConvertTo-SoftwareIdentity -RequestedName $Package -Source $SourceName
Expand Down
10 changes: 5 additions & 5 deletions src/private/PackageVersionHelpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ function Test-PackageVersion {
$MaximumVersion
)

$version = $Package.Version.TrimStart('v')
[System.Version]$version = $Package.Version.TrimStart('v')

if (-not ($RequiredVersion -or $MinimumVersion -or $MaximumVersion)) {
return $true
}

if ($RequiredVersion) {
return ($Version -eq $RequiredVersion)
return ($Version -eq [System.Version]$RequiredVersion)
}

$isMatch = $false

if($MinimumVersion)
{
$isMatch = $version -ge $MinimumVersion
$isMatch = $version -ge [System.Version]$MinimumVersion
}

if($MaximumVersion)
{
if($MinimumVersion)
{
$isMatch = $isMatch -and ($version -le $MaximumVersion)
$isMatch = $isMatch -and ($version -le [System.Version]$MaximumVersion)
}
else
{
$isMatch = $version -le $MaximumVersion
$isMatch = $version -le [System.Version]$MaximumVersion
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/public/Install-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function Install-Package {
return
}

$swid = Invoke-Choco -Install -Package $Matches.name -Version $Matches.version -SourceName $Matches.source |
Where-Object {Test-PackageVersion -Package $_ -RequiredVersion $Matches.version}
$swid = Invoke-Choco -Install -Package $Matches.name -Version $Matches.version -SourceName $Matches.source |
Where-Object {Test-PackageVersion -Package $_ -RequiredVersion $Matches.version -ErrorAction SilentlyContinue}

if (-not $swid) {
# Invoke-Choco didn't throw an exception but we also couldn't pull a Software Identity from the output.
Expand Down