Skip to content

Commit 2d3c379

Browse files
Fix anonymous-mode and GHES token routing for all platforms
Thread 1&2 (linux/macos): guard gh api path with [[ -n \ ]] so anonymous callers fall through to the unauthenticated curl path instead of letting gh api fail on GitHub-hosted runners where gh is always installed. Thread 3 (windows): build REST API base URL from GH_HOST so GHES environments resolve releases against the configured host instead of hard-coded api.github.com. Thread 4 (action.yml): add GH_ENTERPRISE_TOKEN to all three step env blocks; GitHub CLI requires this variable (not GH_TOKEN) when talking to a non-github.com host.
1 parent dc09e1f commit 2d3c379

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ runs:
5050
PRERELEASE: ${{ inputs.Prerelease }}
5151
GITHUB_TOKEN: ${{ inputs.Token }}
5252
GH_TOKEN: ${{ inputs.Token }}
53+
GH_ENTERPRISE_TOKEN: ${{ inputs.Token }}
5354
GH_HOST: ${{ inputs.Host }}
5455
run: bash ./scripts/linux/install.sh
5556

@@ -62,6 +63,7 @@ runs:
6263
PRERELEASE: ${{ inputs.Prerelease }}
6364
GITHUB_TOKEN: ${{ inputs.Token }}
6465
GH_TOKEN: ${{ inputs.Token }}
66+
GH_ENTERPRISE_TOKEN: ${{ inputs.Token }}
6567
GH_HOST: ${{ inputs.Host }}
6668
run: bash ./scripts/macos/install.sh
6769

@@ -74,5 +76,6 @@ runs:
7476
PRERELEASE: ${{ inputs.Prerelease }}
7577
GITHUB_TOKEN: ${{ inputs.Token }}
7678
GH_TOKEN: ${{ inputs.Token }}
79+
GH_ENTERPRISE_TOKEN: ${{ inputs.Token }}
7780
GH_HOST: ${{ inputs.Host }}
7881
run: ./scripts/windows/install.ps1

scripts/linux/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ echo "Prerelease: [$PRERELEASE]"
77

88
github_api_get() {
99
local endpoint="$1"
10-
if command -v gh >/dev/null 2>&1; then
10+
if command -v gh >/dev/null 2>&1 && [[ -n "$GH_TOKEN" ]]; then
1111
local gh_args=()
1212
if [[ -n "$GH_HOST" ]]; then
1313
gh_args+=(--hostname "$GH_HOST")

scripts/macos/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ echo "Prerelease: [$PRERELEASE]"
77

88
github_api_get() {
99
local endpoint="$1"
10-
if command -v gh >/dev/null 2>&1; then
10+
if command -v gh >/dev/null 2>&1 && [[ -n "$GH_TOKEN" ]]; then
1111
local gh_args=()
1212
if [[ -n "$GH_HOST" ]]; then
1313
gh_args+=(--hostname "$GH_HOST")

scripts/windows/install.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ if ($req -and $req.Trim().ToLower() -eq 'latest') {
1212
if ($env:GITHUB_TOKEN) {
1313
$headers['Authorization'] = "Bearer $($env:GITHUB_TOKEN)"
1414
}
15+
$apiBase = if ($env:GH_HOST -and $env:GH_HOST -ne 'github.com') {
16+
"https://$($env:GH_HOST)/api/v3"
17+
} else {
18+
'https://api.github.com'
19+
}
1520
if ($env:PRERELEASE -eq 'true') {
16-
$releases = Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases?per_page=100' -Headers $headers
21+
$releases = Invoke-RestMethod -Uri "$apiBase/repos/PowerShell/PowerShell/releases?per_page=100" -Headers $headers
1722
$latestRelease = $releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1
1823
if (-not $latestRelease) {
1924
Write-Host 'Error: No prerelease PowerShell releases are available from GitHub.'
@@ -22,7 +27,7 @@ if ($req -and $req.Trim().ToLower() -eq 'latest') {
2227
$latest = $latestRelease.tag_name.TrimStart('v')
2328
Write-Host "Latest prerelease PowerShell version detected: $latest"
2429
} else {
25-
$latest = (Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest' -Headers $headers).tag_name.TrimStart('v')
30+
$latest = (Invoke-RestMethod -Uri "$apiBase/repos/PowerShell/PowerShell/releases/latest" -Headers $headers).tag_name.TrimStart('v')
2631
if (-not $latest) {
2732
Write-Host 'Error: Failed to resolve latest stable PowerShell release from GitHub.'
2833
exit 1

0 commit comments

Comments
 (0)