Skip to content

Commit d7e3064

Browse files
Refactor PowerShell installation: improve version resolution logic for 'latest'; add validation for empty version input and enhance error messaging.
1 parent a9b92d6 commit d7e3064

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

action.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ runs:
9191
echo "Requested version: [$REQUESTED_VERSION]"
9292
9393
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
94-
if [[ "${REQUESTED_VERSION}" =~ ^[Ll][Aa][Tt][Ee][Ss][Tt]$ ]]; then
94+
if [[ "${REQUESTED_VERSION,,}" == "latest" ]]; then
9595
REQUESTED_VERSION=$(
9696
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
9797
grep '"tag_name"' | head -n1 |
9898
sed -E 's/.*"v?([^"]+)".*/\1/'
9999
)
100100
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
101-
elif [[ -z "${REQUESTED_VERSION}" ]]; then
102-
echo "Error: Version input is required (or use 'latest')"
101+
fi
102+
103+
# Validate REQUESTED_VERSION is not empty
104+
if [[ -z "${REQUESTED_VERSION}" ]]; then
105+
echo "Error: Could not determine a valid PowerShell version."
103106
exit 1
104107
fi
105108
@@ -109,9 +112,17 @@ runs:
109112
exit 0
110113
fi
111114
112-
if brew info --cask powershell@$REQUESTED_VERSION >/dev/null 2>&1; then
113-
brew install --cask powershell@$REQUESTED_VERSION
115+
# Try Homebrew first
116+
if command -v brew >/dev/null; then
117+
echo "Using Homebrew package manager..."
118+
if [[ "${REQUESTED_VERSION}" == "latest" ]]; then
119+
brew install --cask powershell
120+
else
121+
brew install --cask powershell@$REQUESTED_VERSION
122+
fi
114123
else
124+
# Fall back to direct download
125+
echo "Homebrew not available, downloading directly..."
115126
ARCH=$(uname -m)
116127
if [[ "$ARCH" == "arm64" ]]; then
117128
PKG_NAME="powershell-${REQUESTED_VERSION}-osx-arm64.pkg"

0 commit comments

Comments
 (0)