@@ -96,24 +96,44 @@ runs:
9696 # Determine Linux distribution type
9797 ARCH=$(dpkg --print-architecture 2>/dev/null || rpm --eval '%{_arch}' 2>/dev/null || echo "x86_64")
9898
99+ # Query GitHub Releases API for the actual asset URLs to handle naming
100+ # convention differences across releases (e.g. powershell-preview_ vs powershell_).
101+ RELEASE_JSON=$(
102+ curl -s -f \
103+ -H "Accept : application/vnd.github+json" \
104+ -H "Authorization : Bearer $GITHUB_TOKEN" \
105+ -H "X-GitHub-Api-Version : 2022-11-28" \
106+ " https://api.github.com/repos/PowerShell/PowerShell/releases/tags/v${REQUESTED_VERSION}"
107+ )
108+ if [[ -z "$RELEASE_JSON" ]]; then
109+ echo "Error : Failed to fetch release info for v${REQUESTED_VERSION} from GitHub."
110+ exit 1
111+ fi
112+
99113 if command -v apt-get >/dev/null || command -v dpkg >/dev/null; then
100114 # Debian/Ubuntu based
101115 echo "Detected Debian/Ubuntu based system..."
102- DEB_NAME="powershell_${REQUESTED_VERSION}-1.deb_${ARCH}.deb"
103- URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${DEB_NAME}"
116+ URL=$(echo "$RELEASE_JSON" | jq -r --arg arch "$ARCH" \
117+ ' [.assets[] | select(.name | test("^powershell.*\\.deb_" + $arch + "\\.deb$"))] | .[0].browser_download_url // empty' )
118+ if [[ -z "$URL" ]]; then
119+ echo "Error : No .deb package found for architecture '$ARCH' in release v${REQUESTED_VERSION}."
120+ exit 1
121+ fi
122+ DEB_NAME=$(basename "$URL")
104123 echo "Downloading from : $URL"
105124 wget -q "$URL" -O "$DEB_NAME"
106125 echo "Starting installation of PowerShell [$REQUESTED_VERSION]..."
107126 sudo dpkg -i "$DEB_NAME" || sudo apt-get -f install -y
108127 elif command -v rpm >/dev/null; then
109128 # RHEL/Fedora/CentOS based
110129 echo "Detected RHEL/Fedora/CentOS based system..."
111- if [[ "$ARCH" == "aarch64" ]]; then
112- RPM_NAME="powershell-${REQUESTED_VERSION}-1.rh.${ARCH}.rpm"
113- else
114- RPM_NAME="powershell-${REQUESTED_VERSION}-1.rh.x86_64.rpm"
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' )
132+ if [[ -z "$URL" ]]; then
133+ echo "Error : No .rpm package found for architecture '$ARCH' in release v${REQUESTED_VERSION}."
134+ exit 1
115135 fi
116- URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${RPM_NAME}"
136+ RPM_NAME=$(basename "$URL")
117137 echo "Downloading from : $URL"
118138 wget -q "$URL" -O "$RPM_NAME"
119139 echo "Starting installation of PowerShell [$REQUESTED_VERSION]..."
0 commit comments