Skip to content

Commit e05baed

Browse files
Refactor logging in PowerShell installation: replace custom log function with standard echo statements for improved clarity and consistency across Linux, macOS, and Windows installation steps.
1 parent 247296a commit e05baed

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

action.yml

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Install PowerShell
2-
description: Install a specific version of PowerShell Core on any GitHub runner (Linux, macOS, Windows). Handles install, downgrade, or forced reinstall with uniform logging.
2+
description: |
3+
Install a specific version of PowerShell Core on any GitHub runner (Linux, macOS, Windows).
4+
Handles install, downgrade, or forced reinstall.
35
author: PSModule
46
branding:
57
icon: terminal
@@ -24,13 +26,12 @@ runs:
2426
shell: bash
2527
run: |
2628
set -e
27-
log() { echo "::notice title=pwsh-installer::[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] $1"; }
2829
29-
log "Detecting existing PowerShell on Linux…"
30+
echo "Detecting existing PowerShell on Linux…"
3031
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
31-
log "Detected version: ${DETECTED_VERSION:-<none>}"
32-
log "Requested version: $REQUESTED_VERSION"
33-
log "Reinstall flag: $REINSTALL"
32+
echo "Detected version: ${DETECTED_VERSION:-<none>}"
33+
echo "Requested version: $REQUESTED_VERSION"
34+
echo "Reinstall flag: $REINSTALL"
3435
3536
if [[ -z "$DETECTED_VERSION" ]]; then
3637
DECISION="install"
@@ -39,15 +40,15 @@ runs:
3940
else
4041
DECISION="uninstall-install" # covers downgrade or upgrade
4142
fi
42-
log "Decision: $DECISION"
43+
echo "Decision: $DECISION"
4344
4445
if [[ "$DECISION" == "skip" ]]; then
45-
log "Skipping installation on Linux (exact version present)."
46+
echo "Skipping installation on Linux (exact version present)."
4647
else
47-
log "Uninstalling any existing PowerShell…"
48+
echo "Uninstalling any existing PowerShell…"
4849
sudo rm -rf /usr/local/microsoft/powershell || true
4950
sudo rm -f /usr/local/bin/pwsh || true
50-
log "Installing PowerShell $REQUESTED_VERSION…"
51+
echo "Installing PowerShell $REQUESTED_VERSION…"
5152
curl -sSL https://aka.ms/install-powershell.sh | sudo bash -s -- -Version "$REQUESTED_VERSION" -Destination /usr/local
5253
fi
5354
@@ -65,13 +66,11 @@ runs:
6566
shell: bash
6667
run: |
6768
set -e
68-
log() { echo "::notice title=pwsh-installer::[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] $1"; }
69-
70-
log "Detecting existing PowerShell on macOS…"
69+
echo "Detecting existing PowerShell on macOS…"
7170
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
72-
log "Detected version: ${DETECTED_VERSION:-<none>}"
73-
log "Requested version: $REQUESTED_VERSION"
74-
log "Reinstall flag: $REINSTALL"
71+
echo "Detected version: ${DETECTED_VERSION:-<none>}"
72+
echo "Requested version: $REQUESTED_VERSION"
73+
echo "Reinstall flag: $REINSTALL"
7574
7675
if [[ -z "$DETECTED_VERSION" ]]; then
7776
DECISION="install"
@@ -80,15 +79,15 @@ runs:
8079
else
8180
DECISION="uninstall-install"
8281
fi
83-
log "Decision: $DECISION"
82+
echo "Decision: $DECISION"
8483
8584
if [[ "$DECISION" == "skip" ]]; then
86-
log "Skipping installation on macOS (exact version present)."
85+
echo "Skipping installation on macOS (exact version present)."
8786
else
88-
log "Uninstalling any existing PowerShell…"
87+
echo "Uninstalling any existing PowerShell…"
8988
sudo rm -rf /usr/local/microsoft/powershell || true
9089
sudo rm -f /usr/local/bin/pwsh || true
91-
log "Installing PowerShell $REQUESTED_VERSION…"
90+
echo "Installing PowerShell $REQUESTED_VERSION…"
9291
curl -sSL https://aka.ms/install-powershell.sh | sudo bash -s -- -Version "$REQUESTED_VERSION" -Destination /usr/local
9392
fi
9493
@@ -105,15 +104,11 @@ runs:
105104
REINSTALL: ${{ inputs.Reinstall }}
106105
shell: powershell
107106
run: |
108-
function Log($Message) {
109-
Write-Host "::notice title=pwsh-installer::[$([DateTime]::UtcNow.ToString('u'))] $Message"
110-
}
111-
112-
Log "Detecting existing PowerShell on Windows…"
107+
Write-Host "Detecting existing PowerShell on Windows…"
113108
try { $detected = (pwsh -NoLogo -NoProfile -Command "$PSVersionTable.PSVersion.ToString()") } catch { $detected = $null }
114-
Log "Detected version: $($detected ?? '<none>')"
115-
Log "Requested version: $env:REQUESTED_VERSION"
116-
Log "Reinstall flag: $env:REINSTALL"
109+
Write-Host "Detected version: $($detected ?? '<none>')"
110+
Write-Host "Requested version: $env:REQUESTED_VERSION"
111+
Write-Host "Reinstall flag: $env:REINSTALL"
117112
118113
if (-not $detected) {
119114
$decision = 'install'
@@ -122,15 +117,15 @@ runs:
122117
} else {
123118
$decision = 'uninstall-install'
124119
}
125-
Log "Decision: $decision"
120+
Write-Host "Decision: $decision"
126121
127122
if ($decision -eq 'skip') {
128-
Log 'Skipping installation on Windows (exact version present).'
123+
Write-Host 'Skipping installation on Windows (exact version present).'
129124
}
130125
else {
131-
Log 'Uninstalling any existing PowerShell…'
126+
Write-Host 'Uninstalling any existing PowerShell…'
132127
winget uninstall --id Microsoft.PowerShell -e --silent | Out-Null
133-
Log "Installing PowerShell $env:REQUESTED_VERSION…"
128+
Write-Host "Installing PowerShell $env:REQUESTED_VERSION…"
134129
$msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi"
135130
$url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi"
136131
Invoke-WebRequest $url -OutFile $msi

0 commit comments

Comments
 (0)