@@ -110,38 +110,74 @@ runs:
110110 exit 1
111111 fi
112112
113+ # Determine if the requested version is a prerelease (contains a hyphen, e.g. 7.6.0-preview.6)
114+ IS_PRERELEASE=false
115+ if [[ "$REQUESTED_VERSION" == *-* ]]; then
116+ IS_PRERELEASE=true
117+ fi
118+
113119 if command -v apt-get >/dev/null || command -v dpkg >/dev/null; then
114120 # Debian/Ubuntu based
115121 echo "Detected Debian/Ubuntu based system..."
116- URL=$(echo "$RELEASE_JSON" | jq -r --arg arch "$ARCH" \
117- ' [.assets[] | select(.name | test("^powershell.*\\.deb_" + $arch + "\\.deb$"))] | .[0].browser_download_url // empty' )
122+ if [[ "$IS_PRERELEASE" == "true" ]]; then
123+ # For prerelease versions, select the powershell-preview package
124+ URL=$(echo "$RELEASE_JSON" | jq -r --arg arch "$ARCH" \
125+ ' [.assets[] | select(.name | test("^powershell-preview_.*\\.deb_" + $arch + "\\.deb$"))] | .[0].browser_download_url // empty' )
126+ else
127+ # For stable versions, select the powershell package (not powershell-lts or powershell-preview)
128+ URL=$(echo "$RELEASE_JSON" | jq -r --arg arch "$ARCH" \
129+ ' [.assets[] | select(.name | test("^powershell_.*\\.deb_" + $arch + "\\.deb$"))] | .[0].browser_download_url // empty' )
130+ fi
118131 if [[ -z "$URL" ]]; then
119132 echo "Error : No .deb package found for architecture '$ARCH' in release v${REQUESTED_VERSION}."
120133 exit 1
121134 fi
122135 DEB_NAME=$(basename "$URL")
123136 echo "Downloading from : $URL"
124137 wget -q "$URL" -O "$DEB_NAME"
138+
139+ # Remove all existing PowerShell packages to avoid dpkg conflicts
140+ # (powershell, powershell-lts, and powershell-preview all provide /usr/bin/pwsh)
141+ echo "Removing existing PowerShell packages to avoid conflicts..."
142+ sudo dpkg --remove powershell powershell-lts powershell-preview 2>/dev/null || true
143+
125144 echo "Starting installation of PowerShell [$REQUESTED_VERSION]..."
126145 sudo dpkg -i "$DEB_NAME" || sudo apt-get -f install -y
127146 elif command -v rpm >/dev/null; then
128147 # RHEL/Fedora/CentOS based
129148 echo "Detected RHEL/Fedora/CentOS based system..."
130- URL=$(echo "$RELEASE_JSON" | jq -r --arg arch "$ARCH" \
131- ' [.assets[] | select(.name | test("^powershell.*\\.rh\\." + (if $arch == "aarch64" then $arch else "x86_64" end) + "\\.rpm$"))] | .[0].browser_download_url // empty' )
149+ if [[ "$IS_PRERELEASE" == "true" ]]; then
150+ URL=$(echo "$RELEASE_JSON" | jq -r --arg arch "$ARCH" \
151+ ' [.assets[] | select(.name | test("^powershell-preview.*\\.rh\\." + (if $arch == "aarch64" then $arch else "x86_64" end) + "\\.rpm$"))] | .[0].browser_download_url // empty' )
152+ else
153+ URL=$(echo "$RELEASE_JSON" | jq -r --arg arch "$ARCH" \
154+ ' [.assets[] | select(.name | test("^powershell-[0-9].*\\.rh\\." + (if $arch == "aarch64" then $arch else "x86_64" end) + "\\.rpm$"))] | .[0].browser_download_url // empty' )
155+ fi
132156 if [[ -z "$URL" ]]; then
133157 echo "Error : No .rpm package found for architecture '$ARCH' in release v${REQUESTED_VERSION}."
134158 exit 1
135159 fi
136160 RPM_NAME=$(basename "$URL")
137161 echo "Downloading from : $URL"
138162 wget -q "$URL" -O "$RPM_NAME"
163+
164+ # Remove existing PowerShell packages to avoid conflicts
165+ echo "Removing existing PowerShell packages to avoid conflicts..."
166+ sudo rpm -e powershell powershell-preview 2>/dev/null || true
167+
139168 echo "Starting installation of PowerShell [$REQUESTED_VERSION]..."
140169 sudo rpm -i "$RPM_NAME" || sudo yum install -y "$RPM_NAME"
141170 else
142171 echo "Unsupported Linux distribution. Cannot determine package format."
143172 exit 1
144173 fi
174+
175+ # Verify installation succeeded
176+ INSTALLED_VERSION=$(pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()' 2>/dev/null || true)
177+ if [[ "$INSTALLED_VERSION" != "$REQUESTED_VERSION" ]]; then
178+ echo "Error : Installation verification failed. Expected $REQUESTED_VERSION but got ${INSTALLED_VERSION:-nothing}."
179+ exit 1
180+ fi
145181 echo "Installation complete. PowerShell [$REQUESTED_VERSION] is now available."
146182
147183 # For prerelease builds, add the install directory to GITHUB_PATH so subsequent
0 commit comments