Skip to content

Commit

Permalink
Futureproofing (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbergstrom authored Feb 11, 2023
1 parent 9147a7d commit 826b64e
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
id: cacher
with:
path: "~/.local/share/powershell/Modules"
key: crescendo-0.4.1-cache
key: crescendo-1.1-preview-cache
- name: Install Crescendo
if: steps.cacher.outputs.cache-hit != 'true'
shell: pwsh
run: Install-Module Microsoft.PowerShell.Crescendo -RequiredVersion 0.4.1 -Force
run: Install-Module Microsoft.PowerShell.Crescendo -AllowPrerelease -RequiredVersion 1.1.0-Preview01 -Force
- name: Build the module with Crescendo
shell: pwsh
run: ./build.ps1
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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).

## [0.3.0] - 2023-01-21
#### Added
* Futureproofing support for Chocolatey v2.0.0 and higher
* Ability to search remote packages with `Find-ChocoPackage` via `choco search`
#### Changed
* Migrated `Get-ChocoPackage` from using `choco search` to `choco list` to distinguish their changed meaning in Chocolatey v2.0.0 and higher
* Upgraded to PowerShell Crescendo 1.1 Preview 1 for compiling the module
* No functional changes are expected with this upgrade
#### Deprecated
* The `-LocalOnly` switch for `Get-ChocoPackage` becomes deprecated when used with Chocolatey v2.0.0, due to it becoming redundant with a change to `choco list` (see chocolatey/choco#158)
* The use of `Get-ChocoPackage` for package search operations (and it's `-Source` parameter) becomes **immediately** deprecated, as `Get-ChocoPackage` only looks at installed packages beginning with Chocolatey v2.0.0 and higher
* **Package search operations must be migrated to `Find-ChocoPackage` prior to the release of Chocolatey v2.0.0**

## [0.2.1] - 2023-01-21
#### Fixed
* No longer emits 'Environment' packages of version 'var' when installing a package that updates environment variables
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2021 Ethan Bergstrom
Copyright 2021-2023 Ethan Bergstrom

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Install-Module Foil -Force
## Sample usages
### Search for a package
```PowerShell
Get-ChocoPackage -Name nodejs
Find-ChocoPackage -Name nodejs
Get-ChocoPackage -Name firefox -Exact
Find-ChocoPackage -Name firefox -Exact
```

### Install a package
```PowerShell
Get-ChocoPackage nodejs -Exact -Verbose | Install-ChocoPackage
Find-ChocoPackage nodejs -Exact -Verbose | Install-ChocoPackage
Install-ChocoPackage -Name 7zip -Verbose
```
Expand Down Expand Up @@ -51,5 +51,9 @@ Install-ChocoPackage sysinternals -AcceptLicense -ParamsGlobal -Params '/Install
### Compatibility
Foil works with PowerShell for both FullCLR/'Desktop' (ex 5.1) and CoreCLR (ex: 7.0.1), though Chocolatey itself still requires FullCLR.

The `-LocalOnly` switch for `Get-ChocoPackage` becomes deprecated when used with Chocolatey v2.0.0, due to it becoming redundant with a change to `choco list` (see chocolatey/choco#158).

The use of `Get-ChocoPackage` for package search operations (and it's `-Source` parameter) is deprecated, as `Get-ChocoPackage` only looks at installed packages beginning with Chocolatey v2.0.0 and higher. **Users must upgrade to Foil v0.3.0 or higher and migrate package search operations to `Find-ChocoPackage` prior to the release of Chocolatey v2.0.0 to ensure continued compatibility.**

## Legal and Licensing
Foil is licensed under the [MIT license](./LICENSE.txt).
12 changes: 6 additions & 6 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. (Join-Path -Path src -ChildPath Foil.ps1 -Resolve)

$tempJsonArray = @()
$commandArray = @()

$commands | ForEach-Object {
$Noun = $_.Noun
Expand All @@ -17,8 +17,7 @@ $commands | ForEach-Object {
$VerbOutputHandlers = $_.OutputHandlers
$Description = $_.Description
$tempJson = New-TemporaryFile
New-CrescendoCommand -Verb $_.Verb -Noun $Noun | ForEach-Object {
$_.OriginalName = $BaseOriginalName
$commandArray += $(New-CrescendoCommand -Verb $_.Verb -Noun $Noun -OriginalName $BaseOriginalName | ForEach-Object {
# Marge command elements in order of noun-level first, then verb-level, then generic
$_.OriginalCommandElements = ($NounOriginalCommandElements + $VerbOriginalCommandElements + $BaseOriginalCommandElements)
$_.Description = $Description
Expand All @@ -27,9 +26,10 @@ $commands | ForEach-Object {
# Prefer verb-level handlers first, then noun-level, then generic
$_.OutputHandlers = ($VerbOutputHandlers ?? $NounOutputHandlers) ?? $BaseOutputHandlers
$_
} | ConvertTo-Json | Out-File $tempJson
$tempJsonArray += $tempJson
})
}
}

Export-CrescendoModule -ConfigurationFile $tempJsonArray -ModuleName (Join-Path -Path src -ChildPath Foil.psm1) -Force
$tempJson = (New-TemporaryFile).FullName
Export-CrescendoCommand -command $commandArray -fileName $tempJson -Force
Export-CrescendoModule -NoClobberManifest -ConfigurationFile $tempJson -ModuleName (Join-Path -Path src -ChildPath Foil.psm1) -Force
49 changes: 48 additions & 1 deletion src/Foil.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ $Commands = @(
@{
Verb = 'Get'
Description = 'Get a list of installed or available Chocolatey packages'
OriginalCommandElements = @('search')
OriginalCommandElements = @('list')
Parameters = @(
@{
Name = 'AllVersions'
Expand Down Expand Up @@ -243,6 +243,53 @@ $Commands = @(
}
}
},
@{
Verb = 'Find'
Description = 'Finds a list of available Chocolatey packages'
OriginalCommandElements = @('search')
Parameters = @(
@{
Name = 'AllVersions'
OriginalName = '--all-versions'
ParameterType = 'switch'
Description = 'All Versions'
},
@{
Name = 'Exact'
OriginalName = '--exact'
ParameterType = 'switch'
Description = 'Search by exact package name'
},
@{
Name = 'Source'
OriginalName = '--source='
ParameterType = 'string'
Description = 'Package Source'
NoGap = $true
},
@{
Name = 'PreRelease'
OriginalName = '--pre'
ParameterType = 'switch'
Description = 'Include prerelease packages'
}
)
OutputHandlers = @{
ParameterSetName = 'Default'
Handler = {
param ( $output )
$output | ForEach-Object {
$Name,$version = $_ -split '\|'
if ( -not [string]::IsNullOrEmpty($name)) {
[pscustomobject]@{
Name = $Name
Version = $version
}
}
}
}
}
},
@{
Verb = 'Uninstall'
Description = 'Uninstall an existing package with Chocolatey'
Expand Down
4 changes: 2 additions & 2 deletions src/Foil.psd1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@{
RootModule = 'Foil.psm1'
ModuleVersion = '0.2.1'
ModuleVersion = '0.3.0'
GUID = '38430603-9954-45fd-949a-5f79492ffaf7'
Author = 'Ethan Bergstrom'
Copyright = '2021'
Copyright = '2021-2023'
Description = 'A PowerShell Crescendo wrapper for Chocolatey'
# Crescendo modules aren't supported below PowerShell 5.1
# https://devblogs.microsoft.com/powershell/announcing-powershell-crescendo-preview-1/
Expand Down
34 changes: 17 additions & 17 deletions test/Foil.tests.ps1 → test/Foil.chocoV1.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Import-Module Foil

Describe "basic package search operations" {
Describe "Chocolatey V1 basic package search operations" {
Context 'without additional arguments' {
BeforeAll {
$package = 'cpu-z'
Expand All @@ -21,7 +21,7 @@ Describe "basic package search operations" {
}
}

Describe "DSC-compliant package installation and uninstallation" {
Describe "Chocolatey V1 DSC-compliant package installation and uninstallation" {
Context 'without additional arguments' {
BeforeAll {
$package = 'cpu-z'
Expand All @@ -33,7 +33,7 @@ Describe "DSC-compliant package installation and uninstallation" {
It 'silently installs the latest version of a package' {
Install-ChocoPackage -Name $package -Force | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'finds the locally installed package just installed' {
It 'detects the locally installed package just installed' {
Get-ChocoPackage -Name $package -LocalOnly | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'silently uninstalls the locally installed package just installed' {
Expand All @@ -54,7 +54,7 @@ Describe "DSC-compliant package installation and uninstallation" {
It 'correctly passed parameters to the package' {
Get-ChildItem -Path (Join-Path -Path $env:ProgramFiles -ChildPath $package) -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty
}
It 'finds the locally installed package just installed' {
It 'detects the locally installed package just installed' {
Get-ChocoPackage -Name $package -LocalOnly | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'silently uninstalls the locally installed package just installed' {
Expand All @@ -72,7 +72,7 @@ Describe "DSC-compliant package installation and uninstallation" {
It 'silently installs the latest version of a package' {
Install-ChocoPackage -Name $package -PreRelease -Force | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'finds the locally installed package just installed' {
It 'detects the locally installed package just installed' {
Get-ChocoPackage -Name $package -LocalOnly | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'silently uninstalls the locally installed package just installed' {
Expand All @@ -81,7 +81,7 @@ Describe "DSC-compliant package installation and uninstallation" {
}
}

Describe "pipline-based package installation and uninstallation" {
Describe "Chocolatey V1 pipline-based package installation and uninstallation" {
Context 'without additional arguments' {
BeforeAll {
$package = 'cpu-z'
Expand All @@ -90,7 +90,7 @@ Describe "pipline-based package installation and uninstallation" {
It 'searches for and silently installs the latest version of a package' {
Get-ChocoPackage -Name $package | Install-ChocoPackage -Force | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'finds and silently uninstalls the locally installed package just installed' {
It 'detects and silently uninstalls the locally installed package just installed' {
Get-ChocoPackage -Name $package -LocalOnly -Exact | Uninstall-ChocoPackage | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
}
Expand All @@ -102,7 +102,7 @@ Describe "pipline-based package installation and uninstallation" {
It 'searches for and silently installs the latest version of a package' {
Get-ChocoPackage -Name $package | Install-ChocoPackage -Force | Should -HaveCount 3
}
It 'finds and silently uninstalls the locally installed package just installed, along with its dependencies' {
It 'detects and silently uninstalls the locally installed package just installed, along with its dependencies' {
Get-ChocoPackage -Name $package -LocalOnly -Exact | Uninstall-ChocoPackage -RemoveDependencies | Should -HaveCount 3
}
}
Expand All @@ -114,7 +114,7 @@ Describe "pipline-based package installation and uninstallation" {
It 'searches for and silently installs the latest version of a package' {
Get-ChocoPackage -Name $package | Install-ChocoPackage -Force -Parameters '' | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'finds and silently uninstalls the locally installed package just installed' {
It 'detects and silently uninstalls the locally installed package just installed' {
Get-ChocoPackage -Name $package -LocalOnly -Exact | Uninstall-ChocoPackage | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
}
Expand All @@ -129,7 +129,7 @@ Describe "pipline-based package installation and uninstallation" {
It 'correctly passed parameters to the package' {
Get-ChildItem -Path (Join-Path -Path $env:ProgramFiles -ChildPath $package) -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty
}
It 'finds and silently uninstalls the locally installed package just installed' {
It 'detects and silently uninstalls the locally installed package just installed' {
Get-ChocoPackage -Name $package -LocalOnly -Exact | Uninstall-ChocoPackage | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
}
Expand All @@ -141,13 +141,13 @@ Describe "pipline-based package installation and uninstallation" {
It 'searches for and silently installs the latest version of a package' {
Get-ChocoPackage -Name $package -PreRelease | Install-ChocoPackage -Force | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'finds and silently uninstalls the locally installed package just installed' {
It 'detects and silently uninstalls the locally installed package just installed' {
Get-ChocoPackage -Name $package -LocalOnly -Exact | Uninstall-ChocoPackage | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
}
}

Describe "multi-source support" {
Describe "Chocolatey V1 multi-source support" {
BeforeAll {
$altSource = 'LocalChocoSource'
$altLocation = $PSScriptRoot
Expand All @@ -165,9 +165,9 @@ Describe "multi-source support" {
{ Register-ChocoSource -Name $altSource -Location $altLocation | Where-Object {$_.Name -eq $altSource} } | Should -Not -Throw
}
It 'searches for and installs the latest version of a package from an alternate source' {
Get-ChocoPackage -Name $package -source $altSource | Install-ChocoPackage -Force | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
Get-ChocoPackage -Name $package -Source $altSource | Install-ChocoPackage -Force | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'finds and uninstalls a package installed from an alternate source' {
It 'detects and uninstalls a package installed from an alternate source' {
Get-ChocoPackage -Name $package -LocalOnly -Exact | Uninstall-ChocoPackage | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty
}
It 'unregisters an alternative package source' {
Expand All @@ -176,7 +176,7 @@ Describe "multi-source support" {
}
}

Describe "version filters" {
Describe "Chocolatey V1 version filters" {
BeforeAll {
$package = 'ninja'
# Keep at least one version back, to test the 'latest' feature
Expand All @@ -190,13 +190,13 @@ Describe "version filters" {
It 'searches for and silently installs a specific package version' {
Get-ChocoPackage -Name $package -Version $version -Exact | Install-ChocoPackage -Force | Where-Object {$_.Name -contains $package -and $_.Version -eq $version} | Should -Not -BeNullOrEmpty
}
It 'finds and silently uninstalls a specific package version' {
It 'detects and silently uninstalls a specific package version' {
Get-ChocoPackage -Name $package -Version $version -LocalOnly | UnInstall-ChocoPackage -Force | Where-Object {$_.Name -contains $package -and $_.Version -eq $version} | Should -Not -BeNullOrEmpty
}
}
}

Describe "error handling on Chocolatey failures" {
Describe "Chocolatey V1 error handling on Chocolatey failures" {
Context 'package installation' {
BeforeAll {
$package = 'googlechrome'
Expand Down
Loading

0 comments on commit 826b64e

Please sign in to comment.