@@ -79,14 +79,75 @@ runs:
7979 if : runner.os == 'macOS'
8080 shell : bash
8181 run : |
82+ # Clean up existing PowerShell installation
8283 sudo rm -rf /usr/local/microsoft/powershell
84+
85+ # Get version information
8386 version='${{ inputs.version }}'
8487 if [ -z "$version" ]; then
88+ # Get latest version if not specified
8589 version=$(curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep 'tag_name' | cut -d '"' -f 4)
90+ echo "Latest PowerShell version: $version"
8691 else
8792 version="v$version"
93+ echo "Installing specified PowerShell version: $version"
94+ fi
95+
96+ # The version without 'v' prefix
97+ clean_version=${version#v}
98+
99+ # Try the different naming patterns for the macOS package
100+ pkg_patterns=(
101+ "powershell-$clean_version-osx-x64.pkg"
102+ "powershell-$clean_version-osx-arm64.pkg"
103+ "powershell-$clean_version-osx.pkg"
104+ )
105+
106+ # Determine if running on Apple Silicon or Intel
107+ if [ "$(uname -m)" = "arm64" ]; then
108+ echo "Detected Apple Silicon (ARM64)"
109+ arch="arm64"
110+ else
111+ echo "Detected Intel CPU (x64)"
112+ arch="x64"
113+ fi
114+
115+ # Try to download the appropriate package based on architecture
116+ download_success=false
117+
118+ for pkg_name in "${pkg_patterns[@]}"; do
119+ echo "Trying to download $pkg_name..."
120+ url="https://github.com/PowerShell/PowerShell/releases/download/$version/$pkg_name"
121+
122+ # Try to download the file
123+ if curl -LO $url --fail; then
124+ echo "Successfully downloaded $pkg_name"
125+ download_success=true
126+ break
127+ else
128+ echo "Failed to download $pkg_name"
129+ fi
130+ done
131+
132+ if [ "$download_success" = false ]; then
133+ echo "ERROR: Could not download PowerShell package for macOS. Please check version and available packages."
134+ exit 1
135+ fi
136+
137+ # Verify the file exists before installation
138+ if [ -f "$pkg_name" ]; then
139+ echo "Installing PowerShell package: $pkg_name"
140+ sudo installer -pkg "$pkg_name" -target /
141+
142+ # Verify the installation
143+ if [ -f "/usr/local/bin/pwsh" ]; then
144+ echo "PowerShell installed successfully:"
145+ /usr/local/bin/pwsh -Command '$PSVersionTable'
146+ else
147+ echo "ERROR: PowerShell installation failed. Could not find /usr/local/bin/pwsh"
148+ exit 1
149+ fi
150+ else
151+ echo "ERROR: Downloaded package file not found: $pkg_name"
152+ exit 1
88153 fi
89- pkg="powershell-${version#v}-osx.pkg"
90- url="https://github.com/PowerShell/PowerShell/releases/download/$version/$pkg"
91- curl -LO $url
92- sudo installer -pkg $pkg -target /
0 commit comments