Skip to content

Commit d026fe5

Browse files
Refactor PowerShell installation: correct APT package manager message; streamline version resolution logic and add validation for requested version.
1 parent ddd52b1 commit d026fe5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

action.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ runs:
4747
fi
4848
4949
if command -v apt-get >/dev/null; then
50-
echo "Using APT package manager (Debian/Ubuntu)"
50+
echo "Using APT package manager (Debian/Ubuntu)..."
5151
5252
if ! grep -q "packages.microsoft.com" /etc/apt/sources.list /etc/apt/sources.list.d/* 2>/dev/null; then
5353
wget -qO- https://packages.microsoft.com/keys/microsoft.asc \
@@ -83,17 +83,21 @@ runs:
8383
run: |
8484
set -e
8585
86-
# Resolve "" / null / latest → concrete latest version (Bash‑3 safe)
87-
case "${REQUESTED_VERSION:-}" in
88-
""|[Ll][Aa][Tt][Ee][Ss][Tt]|[Nn][Uu][Ll][Ll]|~)
89-
REQUESTED_VERSION=$(
90-
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
91-
grep '"tag_name"' | head -n1 |
92-
sed -E 's/.*"v?([^"]+)".*/\1/'
93-
)
94-
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
95-
;;
96-
esac
86+
# Resolve "" / null / latest → concrete latest version
87+
if [[ -z "${REQUESTED_VERSION}" || "${REQUESTED_VERSION}" =~ ^[Ll][Aa][Tt][Ee][Ss][Tt]$ || "${REQUESTED_VERSION}" =~ ^[Nn][Uu][Ll][Ll]$ || "${REQUESTED_VERSION}" == "~" ]]; then
88+
REQUESTED_VERSION=$(
89+
curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
90+
grep '"tag_name"' | head -n1 |
91+
sed -E 's/.*"v?([^"]+)".*/\1/'
92+
)
93+
echo "Latest stable PowerShell release detected: $REQUESTED_VERSION"
94+
fi
95+
96+
# Validate REQUESTED_VERSION is not empty
97+
if [[ -z "${REQUESTED_VERSION}" ]]; then
98+
echo "Error: Could not determine a valid PowerShell version."
99+
exit 1
100+
fi
97101
98102
DETECTED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
99103
if [[ "$DETECTED_VERSION" == "$REQUESTED_VERSION" ]]; then

0 commit comments

Comments
 (0)