Skip to content

Commit 0ed482b

Browse files
committed
allow auth to be disabled
sending a bad auth token to github causes a 401. If you're using gitea, then the token is never valid, so allow it to be disabled
1 parent 21fff2b commit 0ed482b

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

action.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ inputs:
2323
Similar to the `-Prerelease` switch on `Install-PSResource`.
2424
required: false
2525
default: 'false'
26+
NoAuth:
27+
description: |
28+
If 'true', do not send an Authorization header with GitHub API requests.
29+
Useful for avoiding rate limit issues when a token is not provided or desired.
30+
required: false
31+
default: 'false'
2632

2733
runs:
2834
using: composite
@@ -34,6 +40,7 @@ runs:
3440
env:
3541
REQUESTED_VERSION: ${{ inputs.Version }}
3642
PRERELEASE: ${{ inputs.Prerelease }}
43+
NO_AUTH: ${{ inputs.NoAuth }}
3744
GITHUB_TOKEN: ${{ github.token }}
3845
run:
3946
| # zizmor: ignore[github-env] GITHUB_PATH writes use hardcoded install dirs, not user input
@@ -42,14 +49,20 @@ runs:
4249
echo "Requested version: [$REQUESTED_VERSION]"
4350
echo "Prerelease: [$PRERELEASE]"
4451

52+
# Prepare curl arguments for GitHub API
53+
CURL_AUTH=(-H "Authorization: Bearer $GITHUB_TOKEN")
54+
if [[ "$NO_AUTH" == "true" ]]; then
55+
CURL_AUTH=()
56+
fi
57+
4558
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
4659
case "${REQUESTED_VERSION:-}" in
4760
[Ll][Aa][Tt][Ee][Ss][Tt])
4861
if [[ "$PRERELEASE" == "true" ]]; then
4962
REQUESTED_VERSION=$(
5063
curl -s -f \
5164
-H "Accept: application/vnd.github+json" \
52-
-H "Authorization: Bearer $GITHUB_TOKEN" \
65+
"${CURL_AUTH[@]}" \
5366
-H "X-GitHub-Api-Version: 2022-11-28" \
5467
'https://api.github.com/repos/PowerShell/PowerShell/releases?per_page=100' |
5568
jq -r '[.[] | select(.prerelease == true)] | (.[0].tag_name // empty)' | sed 's/^v//'
@@ -63,7 +76,7 @@ runs:
6376
REQUESTED_VERSION=$(
6477
curl -s -f \
6578
-H "Accept: application/vnd.github+json" \
66-
-H "Authorization: Bearer $GITHUB_TOKEN" \
79+
"${CURL_AUTH[@]}" \
6780
-H "X-GitHub-Api-Version: 2022-11-28" \
6881
https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
6982
jq -r '.tag_name' | sed 's/^v//'
@@ -101,7 +114,7 @@ runs:
101114
RELEASE_JSON=$(
102115
curl -s -f \
103116
-H "Accept: application/vnd.github+json" \
104-
-H "Authorization: Bearer $GITHUB_TOKEN" \
117+
"${CURL_AUTH[@]}" \
105118
-H "X-GitHub-Api-Version: 2022-11-28" \
106119
"https://api.github.com/repos/PowerShell/PowerShell/releases/tags/v${REQUESTED_VERSION}"
107120
)
@@ -222,6 +235,7 @@ runs:
222235
env:
223236
REQUESTED_VERSION: ${{ inputs.Version }}
224237
PRERELEASE: ${{ inputs.Prerelease }}
238+
NO_AUTH: ${{ inputs.NoAuth }}
225239
GITHUB_TOKEN: ${{ github.token }}
226240
run:
227241
| # zizmor: ignore[github-env] GITHUB_PATH writes use hardcoded install dirs, not user input
@@ -230,14 +244,20 @@ runs:
230244
echo "Requested version: [$REQUESTED_VERSION]"
231245
echo "Prerelease: [$PRERELEASE]"
232246

247+
# Prepare curl arguments for GitHub API
248+
CURL_AUTH=(-H "Authorization: Bearer $GITHUB_TOKEN")
249+
if [[ "$NO_AUTH" == "true" ]]; then
250+
CURL_AUTH=()
251+
fi
252+
233253
# Only resolve to latest version if explicitly set to 'latest' (case-insensitive)
234254
case "${REQUESTED_VERSION:-}" in
235255
[Ll][Aa][Tt][Ee][Ss][Tt])
236256
if [[ "$PRERELEASE" == "true" ]]; then
237257
REQUESTED_VERSION=$(
238258
curl -s -f \
239259
-H "Accept: application/vnd.github+json" \
240-
-H "Authorization: Bearer $GITHUB_TOKEN" \
260+
"${CURL_AUTH[@]}" \
241261
-H "X-GitHub-Api-Version: 2022-11-28" \
242262
'https://api.github.com/repos/PowerShell/PowerShell/releases?per_page=100' |
243263
jq -r '[.[] | select(.prerelease == true)] | (.[0].tag_name // empty)' | sed 's/^v//'
@@ -251,7 +271,7 @@ runs:
251271
REQUESTED_VERSION=$(
252272
curl -s -f \
253273
-H "Accept: application/vnd.github+json" \
254-
-H "Authorization: Bearer $GITHUB_TOKEN" \
274+
"${CURL_AUTH[@]}" \
255275
-H "X-GitHub-Api-Version: 2022-11-28" \
256276
https://api.github.com/repos/PowerShell/PowerShell/releases/latest |
257277
jq -r '.tag_name' | sed 's/^v//'
@@ -321,6 +341,7 @@ runs:
321341
env:
322342
REQUESTED_VERSION: ${{ inputs.Version }}
323343
PRERELEASE: ${{ inputs.Prerelease }}
344+
NO_AUTH: ${{ inputs.NoAuth }}
324345
GITHUB_TOKEN: ${{ github.token }}
325346
run:
326347
| # zizmor: ignore[github-env] GITHUB_PATH writes use hardcoded install dirs, not user input
@@ -333,9 +354,12 @@ runs:
333354
if ($req -and $req.Trim().ToLower() -eq 'latest') {
334355
$headers = @{
335356
'Accept' = 'application/vnd.github+json'
336-
'Authorization' = "Bearer $($env:GITHUB_TOKEN)"
337357
'X-GitHub-Api-Version' = '2022-11-28'
338358
}
359+
if ($env:NO_AUTH -ne 'true') {
360+
$headers['Authorization'] = "Bearer $($env:GITHUB_TOKEN)"
361+
}
362+
339363
if ($env:PRERELEASE -eq 'true') {
340364
$releases = Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases?per_page=100' -Headers $headers
341365
$latestRelease = $releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1

0 commit comments

Comments
 (0)