Skip to content

Commit 4b3e22e

Browse files
Refactor Debian/Ubuntu installation: update APT package handling to download .deb from GitHub if exact version not found, and improve error handling for macOS installation via Homebrew.
1 parent 662112c commit 4b3e22e

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

action.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ runs:
4646
fi
4747
4848
# -------------------------------------------------------------------------------------------------
49-
# Ubuntu/Debian install via APT package (preferred over legacy GitHub install script)
49+
# Debian/Ubuntu installation
5050
# -------------------------------------------------------------------------------------------------
5151
if command -v apt-get >/dev/null; then
5252
echo "Using APT package manager (Debian/Ubuntu)…"
@@ -72,21 +72,20 @@ runs:
7272
if [[ -n "$EXACT_PKG" ]]; then
7373
sudo apt-get install -y powershell=$EXACT_PKG
7474
else
75-
echo "Exact version not found in repo; installing latest available package instead."
76-
sudo apt-get install -y powershell
75+
echo "Exact version not found in repo; downloading .deb package from GitHub release…"
76+
ARCH=$(dpkg --print-architecture)
77+
DEB_NAME="powershell_${REQUESTED_VERSION}-1.deb_${ARCH}.deb"
78+
URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${DEB_NAME}"
79+
echo "Fetching $URL"
80+
wget -q "$URL" -O "$DEB_NAME"
81+
sudo dpkg -i "$DEB_NAME" || sudo apt-get -f install -y
7782
fi
7883
7984
else
8085
echo "Unsupported Linux distribution (no apt-get). PowerShell install via package manager not implemented."
8186
exit 1
8287
fi
8388
84-
PWSH_PATH=$(command -v pwsh)
85-
echo "PWSH_PATH=$PWSH_PATH" >> $GITHUB_ENV
86-
echo "PWSH_VERSION=$REQUESTED_VERSION" >> $GITHUB_ENV
87-
echo "pwsh-path=$PWSH_PATH" >> $GITHUB_OUTPUT
88-
echo "pwsh-version=$REQUESTED_VERSION" >> $GITHUB_OUTPUT
89-
9089
- name: Install PowerShell (macOS)
9190
if: runner.os == 'macOS'
9291
env:
@@ -116,15 +115,20 @@ runs:
116115
else
117116
echo "Uninstalling any existing PowerShell…"
118117
brew uninstall --ignore-dependencies --force powershell || true
119-
echo "Installing PowerShell $REQUESTED_VERSION via Homebrew…"
120-
brew install --cask powershell@$REQUESTED_VERSION || brew install --cask powershell
121-
fi
122118
123-
PWSH_PATH=$(command -v pwsh)
124-
echo "PWSH_PATH=$PWSH_PATH" >> $GITHUB_ENV
125-
echo "PWSH_VERSION=$REQUESTED_VERSION" >> $GITHUB_ENV
126-
echo "pwsh-path=$PWSH_PATH" >> $GITHUB_OUTPUT
127-
echo "pwsh-version=$REQUESTED_VERSION" >> $GITHUB_OUTPUT
119+
echo "Attempting to install PowerShell $REQUESTED_VERSION via Homebrew…"
120+
if brew info --cask powershell@$REQUESTED_VERSION >/dev/null 2>&1; then
121+
brew install --cask powershell@$REQUESTED_VERSION
122+
else
123+
echo "Exact version not available via Homebrew; downloading .pkg from GitHub release…"
124+
ARCH=$(uname -m)
125+
if [[ "$ARCH" == "arm64" ]]; then PKG_NAME="powershell-${REQUESTED_VERSION}-osx-arm64.pkg"; else PKG_NAME="powershell-${REQUESTED_VERSION}-osx-x64.pkg"; fi
126+
URL="https://github.com/PowerShell/PowerShell/releases/download/v${REQUESTED_VERSION}/${PKG_NAME}"
127+
echo "Fetching $URL"
128+
curl -sSL "$URL" -o "$PKG_NAME"
129+
sudo installer -pkg "$PKG_NAME" -target /
130+
fi
131+
fi
128132
129133
- name: Install PowerShell (Windows)
130134
if: runner.os == 'Windows'

0 commit comments

Comments
 (0)