Skip to content

Commit 5e7b466

Browse files
vchuravysloederanocha
authored
Use GITHUB_TOKEN to authenticate downloads in CI (#2415)
* Allow Trixi.download to read the GH_TOKEN from the environment * expose GH_TOKEN in CI * fixup! expose GH_TOKEN in CI * Apply suggestions from code review Co-authored-by: Hendrik Ranocha <[email protected]> * Update src/auxiliary/auxiliary.jl --------- Co-authored-by: Michael Schlottke-Lakemper <[email protected]> Co-authored-by: Hendrik Ranocha <[email protected]>
1 parent 94179af commit 5e7b466

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ jobs:
119119
env:
120120
PYTHON: ''
121121
TRIXI_TEST: ${{ matrix.trixi_test }}
122+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # for authenticated downloads without strict rate limits
122123
- uses: julia-actions/julia-processcoverage@v1
123124
if: ${{ !cancelled() }}
124125
with:

src/auxiliary/auxiliary.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,24 @@ Download a file from given `src_url` to given `file_path` if
311311
`file_path`.
312312
This is a small wrapper of `Downloads.download(src_url, file_path)`
313313
that avoids race conditions when multiple MPI ranks are used.
314+
Furthermore, when run as part of a GitHub Action, it uses
315+
token-authenticated downloads to avoid GitHub's rate limiting
316+
for unauthenticated HTTP request. To use this feature, provide
317+
the environment variable `GITHUB_TOKEN`.
314318
"""
315319
function download(src_url, file_path)
316320
# Note that `mpi_isroot()` is also `true` if running
317321
# in serial (without MPI).
318322
if mpi_isroot()
319-
isfile(file_path) || Downloads.download(src_url, file_path)
323+
if !isfile(file_path)
324+
headers = Pair{String, String}[]
325+
# Pass the GITHUB_TOKEN through to prevent rate-limiting
326+
token = get(ENV, "GITHUB_TOKEN", nothing)
327+
if token !== nothing
328+
push!(headers, "authorization" => "Bearer $token")
329+
end
330+
Downloads.download(src_url, file_path; headers)
331+
end
320332
end
321333

322334
if mpi_isparallel()

0 commit comments

Comments
 (0)