Skip to content

Commit 23bddd9

Browse files
Enhance PowerShell installation on Linux: add version normalization, improve version comparison logic, and handle multiple package naming formats for downloads.
1 parent e67fd07 commit 23bddd9

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

action.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ runs:
9696
run: |
9797
version='${{ inputs.Version }}'
9898
99+
# Function to normalize version (remove trailing .0 and v prefix)
100+
normalize_version() {
101+
local version=${1#v} # Remove v prefix
102+
version=${version%.0} # Remove trailing .0
103+
version=${version%.0} # Remove additional .0 if present
104+
echo "$version"
105+
}
106+
99107
# Function to compare versions
100108
compare_versions() {
101-
local current=$1
102-
local target=$2
109+
local current=$(normalize_version "$1")
110+
local target=$(normalize_version "$2")
103111
104112
# Split versions into arrays
105113
IFS='.' read -ra current_parts <<< "$current"
@@ -144,6 +152,7 @@ runs:
144152
0) echo "Versions are equal"; need_to_install=false ;;
145153
2) echo "Current version is higher"; need_to_install=false ;;
146154
1) echo "Current version is lower"; need_to_install=true ;;
155+
*) echo "Version comparison failed, proceeding with installation" ;;
147156
esac
148157
else
149158
echo "PowerShell is not installed. Will install version $clean_version"
@@ -154,8 +163,18 @@ runs:
154163
sudo apt-get update
155164
sudo apt-get install -y wget apt-transport-https
156165
157-
wget https://github.com/PowerShell/PowerShell/releases/download/v$clean_version/powershell_${clean_version}-1.deb_amd64.deb
158-
sudo dpkg -i powershell_${clean_version}-1.deb_amd64.deb
166+
# Download package - handle both old and new naming formats
167+
pkg_name="powershell_${clean_version}-1.deb_amd64.deb"
168+
if ! wget "https://github.com/PowerShell/PowerShell/releases/download/v$clean_version/$pkg_name"; then
169+
# Try alternative package name format
170+
pkg_name="powershell-${clean_version}-linux-x64.deb"
171+
wget "https://github.com/PowerShell/PowerShell/releases/download/v$clean_version/$pkg_name" || {
172+
echo "ERROR: Failed to download PowerShell package"
173+
exit 1
174+
}
175+
fi
176+
177+
sudo dpkg -i "$pkg_name"
159178
sudo apt-get install -f
160179
161180
# Verify installation

0 commit comments

Comments
 (0)