Skip to content

Commit 4967815

Browse files
Refactor PowerShell installation: enhance version resolution for macOS; improve error handling and fallback logic for Homebrew installation.
1 parent d7e3064 commit 4967815

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

action.yml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ runs:
9090
9191
echo "Requested version: [$REQUESTED_VERSION]"
9292
93-
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
94-
if [[ "${REQUESTED_VERSION,,}" == "latest" ]]; then
93+
# Convert to lowercase for comparison (macOS-compatible method)
94+
REQ_VER_LOWER=$(echo "$REQUESTED_VERSION" | tr '[:upper:]' '[:lower:]')
95+
96+
# Only resolve to latest version if explicitly set to 'latest'
97+
if [[ "$REQ_VER_LOWER" == "latest" ]]; then
9598
REQUESTED_VERSION=$(
9699
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
97100
grep '"tag_name"' | head -n1 |
@@ -112,25 +115,37 @@ runs:
112115
exit 0
113116
fi
114117
115-
# Try Homebrew first
118+
# Try Homebrew first (simplified approach)
116119
if command -v brew >/dev/null; then
117120
echo "Using Homebrew package manager..."
118-
if [[ "${REQUESTED_VERSION}" == "latest" ]]; then
121+
# Homebrew handles 'latest' automatically when no version is specified
122+
if [[ "$REQ_VER_LOWER" == "latest" ]]; then
119123
brew install --cask powershell
120124
else
121-
brew install --cask powershell@$REQUESTED_VERSION
125+
# Try specific version formula first
126+
if brew install --cask "powershell@$REQUESTED_VERSION" 2>/dev/null; then
127+
echo "Successfully installed via Homebrew"
128+
else
129+
# Fall back to generic formula if versioned one doesn't exist
130+
echo "Version-specific formula not found, installing latest via Homebrew"
131+
brew install --cask powershell
132+
fi
122133
fi
123134
else
124135
# Fall back to direct download
125136
echo "Homebrew not available, downloading directly..."
126137
ARCH=$(uname -m)
127-
if [[ "$ARCH" == "arm64" ]]; then
128-
PKG_NAME="powershell-${REQUESTED_VERSION}-osx-arm64.pkg"
129-
else
130-
PKG_NAME="powershell-${REQUESTED_VERSION}-osx-x64.pkg"
131-
fi
138+
case "$ARCH" in
139+
"arm64") PKG_NAME="powershell-${REQUESTED_VERSION}-osx-arm64.pkg" ;;
140+
*) PKG_NAME="powershell-${REQUESTED_VERSION}-osx-x64.pkg" ;;
141+
esac
142+
132143
URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${PKG_NAME}"
133-
curl -sSL "$URL" -o "$PKG_NAME"
144+
echo "Downloading from: $URL"
145+
if ! curl -sSL "$URL" -o "$PKG_NAME"; then
146+
echo "Error: Failed to download PowerShell package"
147+
exit 1
148+
fi
134149
sudo installer -pkg "$PKG_NAME" -target /
135150
fi
136151

0 commit comments

Comments
 (0)