Skip to content

Commit 45bce54

Browse files
Refactor PowerShell installation: streamline version resolution logic for empty, 'null', and 'latest' inputs; enhance readability of the code.
1 parent 948a179 commit 45bce54

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

action.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,16 @@ runs:
8181
run: |
8282
set -e
8383
84-
# Resolve empty / 'null' / 'latest' to a concrete version number
85-
lower_req="$(printf '%s' "$REQUESTED_VERSION" | tr '[:upper:]' '[:lower:]')"
86-
if [[ -z "$REQUESTED_VERSION" || "$lower_req" == "latest" || "$lower_req" == "null" ]]; then
87-
REQUESTED_VERSION=$(
88-
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
89-
grep '"tag_name"' | head -n1 | sed -E 's/.*"v?([^"]+)".*/\1/'
90-
)
91-
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
92-
fi
84+
case "${REQUESTED_VERSION:-}" in
85+
"" | [Ll][Aa][Tt][Ee][Ss][Tt] | [Nn][Uu][Ll][Ll])
86+
REQUESTED_VERSION=$(
87+
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
88+
grep '"tag_name"' | head -n1 |
89+
sed -E 's/.*"v?([^"]+)".*/\1/'
90+
)
91+
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
92+
;;
93+
esac
9394
9495
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
9596
if [[ "$DETECTED_VERSION" == "$REQUESTED_VERSION" ]]; then

0 commit comments

Comments
 (0)