Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ Set of automated actions, which bucket maintainers can use to save time managing
1. `SPECIAL_SNOWFLAKES`
- String
- List of manifest names joined with `,` used as parameter for auto-pr utility.
1. [PowerShell Preference Variables](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables)
- If an environment variable with the same name as the following PowerShell preference variable exists, its value will be assigned to the corresponding PowerShell preference variable:

| Name | Type | Default Value |
| ------------------------------------------------------------ | ------ | -------------------- |
| [DebugPreference](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.5#debugpreference) | String | `'SilentlyContinue'` |
| [InformationPreference](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.5#informationpreference) | String | `'SilentlyContinue'` |
| [VerbosePreference](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.5#verbosepreference) | String | `'SilentlyContinue'` |
| [WarningPreference](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.5#warningpreference) | String | `'Continue'` |

## Available actions

Expand Down
4 changes: 0 additions & 4 deletions action.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Set Global Preference
$Global:ErrorActionPreference = 'Continue'
$Global:VerbosePreference = 'Continue'

# Import all modules
Join-Path $PSScriptRoot 'src' | Get-ChildItem -File | Select-Object -ExpandProperty Fullname | Import-Module

Expand Down
35 changes: 35 additions & 0 deletions src/Variables.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
function Initialize-PreferenceVariable {
<#
.SYNOPSIS
Initializes PowerShell preference variables based on environment variables or default values.
#>

$DefaultPreferences = [ordered]@{
# Set ErrorActionPreference first and prevent it from being overridden by the environment variable.
ErrorActionPreference = @{ Value = 'Continue'; IgnoreEnv = $true }
DebugPreference = @{ Value = 'SilentlyContinue' }
InformationPreference = @{ Value = 'SilentlyContinue' }
VerbosePreference = @{ Value = 'SilentlyContinue' }
WarningPreference = @{ Value = 'Continue' }
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

foreach ($Name in $DefaultPreferences.Keys) {
$Preference = $DefaultPreferences[$Name]
$Value = $Preference.Value

$EnvValue = Get-Item "Env:$Name" -ErrorAction Ignore | Select-Object -ExpandProperty Value

if ((-not $Preference.IgnoreEnv) -and ($EnvValue)) {
$Value = $EnvValue
}

# Use built-in output functions instead of Write-Log here to avoid dependency issues
Write-Host "Setting $Name to $Value ..."

Set-Variable -Name $Name -Value $Value -Scope Global
}
}

# Initialize PowerShell Preference Variables
Initialize-PreferenceVariable

# Environment
$env:SCOOP = Join-Path $env:USERPROFILE 'SCOOP'
$env:SCOOP_HOME = Join-Path $env:SCOOP 'apps\scoop\current'
Expand Down