Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
* release/2.1.0: (52 commits)
  (maint) If statement formatting change
  (#3224) Add Assembly Loaded configuration option
  (maint) Resave without BOM
  (#3224) Update version check tests
  (#3174) Store non-normalized package version
  (maint) Add required whitespace
  (#3225) Add Pester Tests to ensure environment
  (#3201 #3225) Re-instate setting of config values
  (maint) Remove env variable for release version
  (maint) Fix encoding of file
  (#3194) Add tab completion for cache command
  (#2854) Re-save file with UTF-8 with BOM
  (#3218) Update Tab Expansion to use Test-Path
  (#3218) Remove try catch block for tab completion
  (build) Use latest Chocolatey.Cake.Recipe package
  (#2854) Do Write-Error instead of Write-Warning
  (#2854) Pester tests to Get-ChocolateyConfigValue
  (maint) Resave Get-ChocolateyConfigValue as CRLF
  (#2854) Add helper to read config values
  (#3214) Add Pester tests to ensure cache cleared
  ...
  • Loading branch information
gep13 committed Jun 29, 2023
2 parents d25f993 + a6bbcbd commit 46976cf
Show file tree
Hide file tree
Showing 118 changed files with 4,259 additions and 3,883 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_methods = true:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:suggestion
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Build with Mono
run: |
chmod +x build.sh
$GITHUB_WORKSPACE//build.sh --verbosity=diagnostic --target=CI --testExecutionType=all
$GITHUB_WORKSPACE//build.sh --verbosity=diagnostic --target=CI --testExecutionType=unit
- name: Upload Ubuntu build results
uses: actions/upload-artifact@v3
# Always upload build results
Expand All @@ -49,7 +49,7 @@ jobs:
path: tools
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
- name: Build with .Net Framework
run: ./build.ps1 --verbosity=diagnostic --target=CI --testExecutionType=all --shouldRunOpenCover=false
run: ./build.ps1 --verbosity=diagnostic --target=CI --testExecutionType=unit --shouldRunOpenCover=false
- name: Upload Windows build results
uses: actions/upload-artifact@v3
# Always upload build results
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Build with Mono
run: |
chmod +x build.sh
$GITHUB_WORKSPACE//build.sh --verbosity=diagnostic --target=CI --testExecutionType=all
$GITHUB_WORKSPACE//build.sh --verbosity=diagnostic --target=CI --testExecutionType=unit
- name: Upload MacOS build results
uses: actions/upload-artifact@v3
# Always upload build results
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
exempt-all-assignees: false
exempt-draft-pr: true
stale-issue-label: "Pending Closure"
stale-pr-label: '0 - Waiting on User'
only-pr-labels: '0 - Waiting on User'
stale-pr-label: 'Pending Closure'
only-labels: '0 - Waiting on User'
close-issue-label: "No Response / Stale"
close-pr-label: "No Response / Stale"
exempt-issue-labels: 'Security / CVE,0 - Backlog,1 - Ready for work,2 - Working,3 - Review,4 - Done,5 - Push required'
exempt-issue-labels: 'Security / CVE'
exempt-pr-labels: 'Security / CVE'
labels-to-remove-when-unstale: '0 - Wating on User,Pending closure'
stale-issue-message: |
Expand Down
17 changes: 16 additions & 1 deletion .teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import jetbrains.buildServer.configs.kotlin.v2019_2.Dependencies
import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.pullRequests
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.finishBuildTrigger
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.schedule
import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot

project {
Expand Down Expand Up @@ -57,14 +58,28 @@ object Chocolatey : BuildType({

script {
name = "Call Cake"
scriptContent = "call build.official.bat --verbosity=diagnostic --target=CI --testExecutionType=all --shouldRunOpenCover=false"
scriptContent = """
IF "%teamcity.build.triggeredBy%" == "Schedule Trigger" (SET TestType=all) ELSE (SET TestType=unit)
call build.official.bat --verbosity=diagnostic --target=CI --testExecutionType=%%TestType%% --shouldRunOpenCover=false
""".trimIndent()
}
}

triggers {
vcs {
branchFilter = ""
}
schedule {
schedulingPolicy = daily {
hour = 2
minute = 0
}
branchFilter = """
+:<default>
""".trimIndent()
triggerBuild = always()
withPendingChangesOnly = false
}
}

features {
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

The Chocolatey team has very explicit information here regarding the process for contributions, and we will be sticklers about the way you write your commit messages (yes, really), so to save yourself some rework, please make sure you read over this entire document prior to contributing.
The Chocolatey team has very explicit information here regarding the process for contributions, and we will be sticklers about the way you write your commit messages (yes, really), so to save yourself some rework, please make sure you read over this entire document prior to contributing. See this [Pull Request](https://github.com/chocolatey/choco/pull/3011) as an example of what we consider to be a great contribution.

<!-- TOC -->

Expand Down Expand Up @@ -274,6 +274,8 @@ choco client properly.

### Submit Pull Request (PR)

See this [Pull Request](https://github.com/chocolatey/choco/pull/3011) as an example of what we consider to be a great contribution.

Prerequisites:

- You are making commits in a feature branch.
Expand Down
19 changes: 15 additions & 4 deletions GenerateDocs.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -PSEdition Desktop
#Requires -PSEdition Desktop
# Copyright © 2017 Chocolatey Software, Inc
# Copyright © 2011 - 2017 RealDimensions Software, LLC
#
Expand All @@ -23,7 +23,8 @@ $thisDirectory = (Split-Path -Parent $MyInvocation.MyCommand.Definition);
$psModuleName = 'chocolateyInstaller'
$psModuleLocation = [System.IO.Path]::GetFullPath("$thisDirectory\src\chocolatey.resources\helpers\chocolateyInstaller.psm1")
$docsFolder = [System.IO.Path]::GetFullPath("$thisDirectory\docs\generated")
$chocoExe = [System.IO.Path]::GetFullPath("$thisDirectory\code_drop\temp\_PublishedApps\choco_merged\choco.exe")
$mergedDirectory = [System.IO.Path]::GetFullPath("$thisDirectory\code_drop\temp\_PublishedApps\choco_merged")
$chocoExe = "$mergedDirectory\choco.exe"
$lineFeed = "`r`n"
$sourceLocation = 'https://github.com/chocolatey/choco/blob/master/'
$sourceCommands = $sourceLocation + 'src/chocolatey/infrastructure.app/commands'
Expand Down Expand Up @@ -96,6 +97,11 @@ These are the functions from above as one list.
'@

if (!(Test-Path "$mergedDirectory\lib")) {
# Workaround for the warning outputted when the directory doesn't exist
$null = New-Item -Path "$mergedDirectory\lib" -ItemType Directory
}

function Get-Aliases($commandName) {

$aliasOutput = ''
Expand Down Expand Up @@ -127,6 +133,9 @@ function Replace-CommonItems($text) {
$text = $text.Replace("`n", $lineFeed)
$text = $text -replace "\*\*NOTE:\*\*", '> :choco-info: **NOTE**
>
>'
$text = $text -replace "\*\*WARNING:\*\*",'> :choco-warning: **WARNING**
>
>'
$text = $text -replace '(community feed[s]?[^\]]|community repository)', '[$1](https://community.chocolatey.org/packages)'
$text = $text -replace '(Chocolatey for Business|Chocolatey Professional|Chocolatey Pro)(?=[^\w])', '[$1](https://chocolatey.org/compare)'
Expand Down Expand Up @@ -232,7 +241,8 @@ function Convert-CommandText {
$commandText = $commandText -replace '^(Commands|How To Pass Options)', '## $1'
$commandText = $commandText -replace '^(Windows Features|Ruby|Cygwin|Python)\s*$', '### $1'
$commandText = $commandText -replace '(?<!\s)NOTE:', '> :choco-info: **NOTE**'
$commandText = $commandText -replace '\*> :choco-info: \*\*NOTE\*\*\*', '> :choco-info: **NOTE**'
$commandText = $commandText -replace '(?<!\s)WARNING:', '> :choco-warning: **WARNING**'
$commandText = $commandText -replace '\*> :choco-(info|warning): \*\*(INFO|WARNING)\*\*\*', '> :choco-$1: **$2**'
$commandText = $commandText -replace 'the command reference', '[how to pass arguments](xref:choco-commands#how-to-pass-options-switches)'
$commandText = $commandText -replace '(community feed[s]?|community repository)', '[$1](https://community.chocolatey.org/packages)'
#$commandText = $commandText -replace '\`(apikey|install|upgrade|uninstall|list|search|info|outdated|pin)\`', '[[`$1`|Commands$1]]'
Expand All @@ -258,7 +268,7 @@ function Convert-CommandText {
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-package-reducer', 'https://docs.chocolatey.org/en-us/features/package-reducer'
$commandText = $commandText -replace 'https://chocolatey.org/docs/en-us/features/package-reducer', 'https://docs.chocolatey.org/en-us/features/package-reducer'
$commandText = $commandText -replace '\[community feed\)\]\(https://community.chocolatey.org/packages\)', '[community feed](https://community.chocolatey.org/packages))'
$commandText = $commandText -replace '> :choco-info: \*\*NOTE\*\*\s', '> :choco-info: **NOTE**
$commandText = $commandText -replace '> :choco-(info|warning): \*\*(INFO|WARNING)\*\*\s', '> :choco-$1: **$2**
>
> '

Expand Down Expand Up @@ -575,6 +585,7 @@ The following are experimental or use not recommended:
$global:powerShellReferenceTOC | Out-File $fileName -Encoding UTF8 -Force

Write-Host "Generating command reference markdown files"
Generate-CommandReference 'Cache' '5'
Generate-CommandReference 'Config' '10'
Generate-CommandReference 'Download' '20'
Generate-CommandReference 'Export' '30'
Expand Down
2 changes: 1 addition & 1 deletion recipe.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.22.0
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.23.1

///////////////////////////////////////////////////////////////////////////////
// TOOLS
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey.resources/chocolatey.resources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<EmbeddedResource Include="helpers\chocolateyInstaller.psm1" />
<EmbeddedResource Include="helpers\functions\Format-FileSize.ps1" />
<EmbeddedResource Include="helpers\functions\Get-CheckSumValid.ps1" />
<EmbeddedResource Include="helpers\functions\Get-ChocolateyConfigValue.ps1" />
<EmbeddedResource Include="helpers\functions\Get-ChocolateyPath.ps1" />
<EmbeddedResource Include="helpers\functions\Get-ChocolateyUnzip.ps1" />
<EmbeddedResource Include="helpers\functions\Get-ChocolateyWebFile.ps1" />
Expand Down
87 changes: 42 additions & 45 deletions src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function script:chocoCmdOperations($commands, $command, $filter, $currentArgumen
Where-Object { $_ -like "$filter*" }
}

$script:chocoCommands = @('-?','search','list','info','install','outdated','upgrade','uninstall','new','pack','push','-h','--help','pin','source','config','feature','apikey','export','help','template','--version')
$script:chocoCommands = @('-?','search','list','info','install','outdated','upgrade','uninstall','new','pack','push','-h','--help','pin','source','config','feature','apikey','export','help','template','cache','--version')

# ensure these all have a space to start, or they will cause issues
$allcommands = " --debug --verbose --trace --noop --help -? --online --accept-license --confirm --limit-output --no-progress --log-file='' --execution-timeout='' --cache-location='' --proxy='' --proxy-user='' --proxy-password='' --proxy-bypass-list='' --proxy-bypass-on-local --force --no-color --skip-compatibility-checks"
$allcommands = " --debug --verbose --trace --noop --help -? --online --accept-license --confirm --limit-output --no-progress --log-file='' --execution-timeout='' --cache-location='' --proxy='' --proxy-user='' --proxy-password='' --proxy-bypass-list='' --proxy-bypass-on-local --force --no-color --skip-compatibility-checks --ignore-http-cache"

$commandOptions = @{
list = "--id-only --pre --exact --by-id-only --id-starts-with --detailed --prerelease --include-programs --source='' --page='' --page-size=''"
Expand All @@ -58,65 +58,57 @@ $commandOptions = @{
apikey = "--source='' --api-key='' --remove"
export = "--include-version-numbers --output-file-path=''"
template = "--name=''"
cache = "--expired"
}

$commandOptions['find'] = $commandOptions['search']

try {
$licenseFile = Get-Item -Path "$env:ChocolateyInstall\license\chocolatey.license.xml" -ErrorAction Stop
$licenseFile = "$env:ChocolateyInstall\license\chocolatey.license.xml"

if ($licenseFile) {
# Add pro-only commands
$script:chocoCommands = @(
$script:chocoCommands
'download'
'optimize'
)
if (Test-Path $licenseFile) {
# Add pro-only commands
$script:chocoCommands = @(
$script:chocoCommands
'download'
'optimize'
)

$commandOptions.download = "--internalize --internalize-all-urls --ignore-dependencies --installed-packages --ignore-unfound-packages --resources-location='' --download-location='' --outputdirectory='' --source='' --version='' --prerelease --user='' --password='' --cert='' --certpassword='' --append-use-original-location --recompile --disable-package-repository-optimizations"
$commandOptions.sync = "--output-directory='' --id='' --package-id=''"
$commandOptions.optimize = "--deflate-nupkg-only --id=''"
$commandOptions.download = "--internalize --internalize-all-urls --ignore-dependencies --installed-packages --ignore-unfound-packages --resources-location='' --download-location='' --outputdirectory='' --source='' --version='' --prerelease --user='' --password='' --cert='' --certpassword='' --append-use-original-location --recompile --disable-package-repository-optimizations"
$commandOptions.sync = "--output-directory='' --id='' --package-id=''"
$commandOptions.optimize = "--deflate-nupkg-only --id=''"

# Add pro switches to commands that have additional switches on Pro
$proInstallUpgradeOptions = " --install-directory='' --package-parameters-sensitive='' --max-download-rate='' --install-arguments-sensitive='' --skip-download-cache --use-download-cache --skip-virus-check --virus-check --virus-positives-minimum='' --deflate-package-size --no-deflate-package-size --deflate-nupkg-only"
# Add pro switches to commands that have additional switches on Pro
$proInstallUpgradeOptions = " --install-directory='' --package-parameters-sensitive='' --max-download-rate='' --install-arguments-sensitive='' --skip-download-cache --use-download-cache --skip-virus-check --virus-check --virus-positives-minimum='' --deflate-package-size --no-deflate-package-size --deflate-nupkg-only"

$commandOptions.install += $proInstallUpgradeOptions
$commandOptions.upgrade += $proInstallUpgradeOptions + " --exclude-chocolatey-packages-during-upgrade-all --include-chocolatey-packages-during-upgrade-all"
$commandOptions.new += " --build-package --use-original-location --keep-remote --url='' --url64='' --checksum='' --checksum64='' --checksumtype='' --pause-on-error"
$commandOptions.pin += " --note=''"
$commandOptions.install += $proInstallUpgradeOptions
$commandOptions.upgrade += $proInstallUpgradeOptions + " --exclude-chocolatey-packages-during-upgrade-all --include-chocolatey-packages-during-upgrade-all"
$commandOptions.new += " --build-package --use-original-location --keep-remote --url='' --url64='' --checksum='' --checksum64='' --checksumtype='' --pause-on-error"
$commandOptions.pin += " --note=''"

# Add Business-only commands and options if the license is a Business or Trial license
[xml]$xml = Get-Content -Path $licenseFile.FullName -ErrorAction Stop
$licenseType = $xml.license.type
# Add Business-only commands and options if the license is a Business or Trial license
[xml]$xml = Get-Content -Path $licenseFile -ErrorAction Stop
$licenseType = $xml.license.type

if ('Business', 'BusinessTrial' -contains $licenseType) {
if ('Business', 'BusinessTrial' -contains $licenseType) {

# Add business-only commands
$script:chocoCommands = @(
$script:chocoCommands
'support'
'sync'
)
# Add business-only commands
$script:chocoCommands = @(
$script:chocoCommands
'support'
'sync'
)

$commandOptions.list += " --audit"
$commandOptions.uninstall += " --from-programs-and-features"
$commandOptions.new += " --file='' --file64='' --from-programs-and-features --remove-architecture-from-name --include-architecture-in-name"
$commandOptions.list += " --audit"
$commandOptions.uninstall += " --from-programs-and-features"
$commandOptions.new += " --file='' --file64='' --from-programs-and-features --remove-architecture-from-name --include-architecture-in-name"

# Add --use-self-service to commands that support it
$selfServiceCommands = 'list', 'find', 'search', 'info', 'install', 'upgrade', 'uninstall', 'pin', 'outdated', 'push', 'download', 'sync', 'optimize'
foreach ($command in $selfServiceCommands) {
$commandOptions.$command += ' --use-self-service'
}
# Add --use-self-service to commands that support it
$selfServiceCommands = 'list', 'find', 'search', 'info', 'install', 'upgrade', 'uninstall', 'pin', 'outdated', 'push', 'download', 'sync', 'optimize'
foreach ($command in $selfServiceCommands) {
$commandOptions.$command += ' --use-self-service'
}
}
}
catch {
# Remove the error that last occurred from $error so it doesn't cause any
# issues for users, as we're deliberately ignoring it.
if ($error.Count -gt 0) {
$error.RemoveAt(0)
}
}

foreach ($key in @($commandOptions.Keys)) {
$commandOptions.$key += $allcommands
Expand Down Expand Up @@ -233,6 +225,11 @@ function ChocolateyTabExpansion($lastBlock) {
@('list', 'info', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
}

# Handles cache first tab
"^(cache)\s+(?<subcommand>[^-\s]*)$" {
@('list', 'remove', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
}

# Handles more options after others
"^(?<cmd>$($commandOptions.Keys -join '|'))(?<currentArguments>.*)\s+(?<op>\S*)$" {
chocoCmdOperations $commandOptions $matches['cmd'] $matches['op'] $matches['currentArguments']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright © 2022 Chocolatey Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function Get-ChocolateyConfigValue {
<#
.SYNOPSIS
Retrieve a value from the Chocolatey Configuration file
.DESCRIPTION
This function will attempt to retrieve the path according to the specified Path Type
to a valid location that can be used by maintainers in certain scenarios.
.NOTES
Available in 2.1.0+
.INPUTS
None
.OUTPUTS
This function outputs the value of the specified configuration key.
If the key is not found, there is no output.
.PARAMETER configKey
The name of the configuration value that should be looked up.
.PARAMETER IgnoredArguments
Allows splatting with arguments that do not apply. Do not use directly.
.EXAMPLE
>
$value = Get-ChocolateyConfigValue -configKey 'cacheLocation'
#>
param(
[parameter(Mandatory = $true)]
[string] $configKey,
[parameter(ValueFromRemainingArguments = $true)]
[Object[]] $ignoredArguments
)

try {
$installLocation = Get-ChocolateyPath -pathType 'InstallPath'
$configPath = Join-Path $installLocation "config\chocolatey.config"
[xml]$configContents = Get-Content -Path $configPath
return $configContents.chocolatey.config.add |
Where-Object { $_.key -eq $configKey } |
Select-Object -ExpandProperty value
}
catch {
Write-Error "Unable to read config value '$configKey' with error" -Exception $_
}
}

0 comments on commit 46976cf

Please sign in to comment.