Skip to content

Commit e737237

Browse files
Marius StorhaugCopilot
authored andcommitted
Fix install action host handling
Restrict release API requests to github.com and avoid forwarding a GHE token by default. Keep metadata and package downloads on the same supported host across every platform. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 3cd7a26 commit e737237

5 files changed

Lines changed: 25 additions & 26 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ jobs:
5050
| ----- | -------- | ------- | ----------- |
5151
| `Version` | `false` | `latest` | Desired PowerShell Core version (e.g. `7.4.1`, `7.6.0-preview.6`). Use `latest` to install the newest stable release (or newest prerelease when `Prerelease` is `true`). |
5252
| `Prerelease` | `false` | `false` | Install a prerelease version. When `true` and `Version` is `latest`, resolves to the latest prerelease. Similar to `-Prerelease` on `Install-PSResource`. |
53-
| `Token` | `false` | `${{ github.token }}` | Token used for GitHub API requests. Set to an empty string (`''`) for anonymous API calls. |
54-
| `Host` | `false` | `github.com` | GitHub host used by the CLI/API path. Keep `github.com` for GitHub.com, or set your GHES hostname. |
53+
| `Token` | `false` | `${{ github.token }}` on GitHub.com; empty elsewhere | Token used for GitHub API requests to `github.com`. Set to an empty string (`''`) for anonymous API calls. |
54+
| `Host` | `false` | `github.com` | GitHub API host. Only `github.com` is supported because the action installs assets from the official `PowerShell/PowerShell` repository. |
5555

5656
## Secrets
5757

58-
This action does **not** require custom secrets by default because it uses `${{ github.token }}`.
58+
This action does **not** require custom secrets on GitHub.com because it uses `${{ github.token }}`. On GitHub Enterprise Cloud with data residency, it defaults to anonymous access to avoid forwarding that instance's token to `github.com`.
5959

60-
If needed, provide `Token` with a custom PAT. To force anonymous API access, set `Token: ''`.
60+
If needed, provide `Token` with a custom PAT for `github.com`. To force anonymous API access, set `Token: ''`.
61+
Release metadata and installation packages are always fetched from the official `PowerShell/PowerShell` repository on `github.com`.
6162

6263
## Outputs
6364

action.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ inputs:
2525
default: 'false'
2626
Token:
2727
description: |
28-
Token used for GitHub API calls.
29-
Defaults to github.token. Set to an empty string for anonymous API access.
28+
Token used for GitHub API calls to github.com.
29+
Defaults to github.token on GitHub.com. Set to an empty string for anonymous API access.
3030
required: false
31-
default: ${{ github.token }}
31+
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
3232
Host:
3333
description: |
34-
GitHub host used by gh CLI for API calls.
35-
Use github.com for GitHub.com or your GHES hostname.
34+
GitHub API host. Only github.com is supported because PowerShell releases are hosted there.
3635
required: false
3736
default: github.com
3837

39-
40-
4138
runs:
4239
using: composite
4340
steps:
@@ -50,7 +47,6 @@ runs:
5047
PRERELEASE: ${{ inputs.Prerelease }}
5148
GITHUB_TOKEN: ${{ inputs.Token }}
5249
GH_TOKEN: ${{ inputs.Token }}
53-
GH_ENTERPRISE_TOKEN: ${{ inputs.Token }}
5450
GH_HOST: ${{ inputs.Host }}
5551
run: bash ./scripts/linux/install.sh
5652

@@ -63,7 +59,6 @@ runs:
6359
PRERELEASE: ${{ inputs.Prerelease }}
6460
GITHUB_TOKEN: ${{ inputs.Token }}
6561
GH_TOKEN: ${{ inputs.Token }}
66-
GH_ENTERPRISE_TOKEN: ${{ inputs.Token }}
6762
GH_HOST: ${{ inputs.Host }}
6863
run: bash ./scripts/macos/install.sh
6964

@@ -75,7 +70,5 @@ runs:
7570
REQUESTED_VERSION: ${{ inputs.Version }}
7671
PRERELEASE: ${{ inputs.Prerelease }}
7772
GITHUB_TOKEN: ${{ inputs.Token }}
78-
GH_TOKEN: ${{ inputs.Token }}
79-
GH_ENTERPRISE_TOKEN: ${{ inputs.Token }}
8073
GH_HOST: ${{ inputs.Host }}
8174
run: ./scripts/windows/install.ps1

scripts/linux/install.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ set -e
55
echo "Requested version: [$REQUESTED_VERSION]"
66
echo "Prerelease: [$PRERELEASE]"
77

8+
if [[ "$GH_HOST" != "github.com" ]]; then
9+
echo "Error: Unsupported GitHub host '$GH_HOST'. PowerShell releases are fetched from github.com." >&2
10+
exit 1
11+
fi
12+
813
github_api_get() {
914
local endpoint="$1"
1015
if command -v gh >/dev/null 2>&1 && [[ -n "$GH_TOKEN" ]]; then
@@ -22,9 +27,6 @@ github_api_get() {
2227
fi
2328

2429
local api_base="https://api.github.com"
25-
if [[ -n "$GH_HOST" && "$GH_HOST" != "github.com" ]]; then
26-
api_base="https://${GH_HOST}/api/v3"
27-
fi
2830

2931
curl -s -f \
3032
-H "Accept: application/vnd.github+json" \

scripts/macos/install.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ set -e
55
echo "Requested version: [$REQUESTED_VERSION]"
66
echo "Prerelease: [$PRERELEASE]"
77

8+
if [[ "$GH_HOST" != "github.com" ]]; then
9+
echo "Error: Unsupported GitHub host '$GH_HOST'. PowerShell releases are fetched from github.com." >&2
10+
exit 1
11+
fi
12+
813
github_api_get() {
914
local endpoint="$1"
1015
if command -v gh >/dev/null 2>&1 && [[ -n "$GH_TOKEN" ]]; then
@@ -22,9 +27,6 @@ github_api_get() {
2227
fi
2328

2429
local api_base="https://api.github.com"
25-
if [[ -n "$GH_HOST" && "$GH_HOST" != "github.com" ]]; then
26-
api_base="https://${GH_HOST}/api/v3"
27-
fi
2830

2931
curl -s -f \
3032
-H "Accept: application/vnd.github+json" \

scripts/windows/install.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ param()
66
Write-Host "Requested version: [$env:REQUESTED_VERSION]"
77
Write-Host "Prerelease: [$env:PRERELEASE]"
88

9+
if ($env:GH_HOST -ne 'github.com') {
10+
Write-Error "Unsupported GitHub host '$env:GH_HOST'. PowerShell releases are fetched from github.com."
11+
exit 1
12+
}
13+
914
# GitHub API headers used throughout the script
1015
$headers = @{
1116
'Accept' = 'application/vnd.github+json'
@@ -14,11 +19,7 @@ $headers = @{
1419
if ($env:GITHUB_TOKEN) {
1520
$headers['Authorization'] = "Bearer $($env:GITHUB_TOKEN)"
1621
}
17-
$apiBase = if ($env:GH_HOST -and $env:GH_HOST -ne 'github.com') {
18-
"https://$($env:GH_HOST)/api/v3"
19-
} else {
20-
'https://api.github.com'
21-
}
22+
$apiBase = 'https://api.github.com'
2223

2324
# Resolve 'latest' -> concrete version
2425
$req = $env:REQUESTED_VERSION

0 commit comments

Comments
 (0)