Skip to content

Commit 8d4960c

Browse files
committed
stuff
1 parent 0a4180d commit 8d4960c

6 files changed

Lines changed: 87 additions & 13 deletions

File tree

.github/workflows/CI.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ jobs:
6565
- name: Install dependencies
6666
run: julia --color=yes --project -e "using Pkg; Pkg.instantiate()"
6767
- name: Cleanup before we build
68-
run: make nuke
68+
run: |
69+
make clean
70+
make nuke
71+
make purge_download_cache_dir
6972
- name: Download the old versions.json, so we can re-use it
7073
run: curl -LO https://julialang-s3.julialang.org/bin/versions.json
7174
- name: Build versions.json
7275
run: make build
7376
env:
74-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Used to authenticate to GitHub API to get list of tags
7578
- name: Run the post-build tests
7679
run: make test-full
7780
- name: Install NPM deps

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Directories:
2+
cache/
23
node_modules/
34

45
# Files:

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ nuke:
5454
.PHONY: _purge_node_modules
5555
_purge_node_modules:
5656
$(RM) -r test/node/node_modules/
57+
58+
.PHONY: purge_download_cache_dir
59+
purge_download_cache_dir:
60+
$(RM) -r cache/

src/VersionsJSONUtil.jl

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module VersionsJSONUtil
33
##### --------------------------------------------------------------------------------------
44
##### Import dependencies
55

6+
using Downloads: Downloads
67
using EnumX: EnumX, @enumx
78
using GitHub: GitHub
89
using HTTP: HTTP
@@ -26,7 +27,7 @@ include("sha_structs.jl")
2627

2728
include("typed_json.jl")
2829

29-
include("download.jl")
30+
include("web_cache_utilities.jl")
3031

3132
##### --------------------------------------------------------------------------------------
3233
##### Config, OutputJsonContent
@@ -331,16 +332,18 @@ function filedict_is_complete_and_good(filedict::FileDict)
331332

332333
# Now the (compared to the rest of this function) expensive part: Check our Etag.
333334
url = filedict.url
334-
old_headinfo = HeadInfo(;
335-
etag = filedict.etag,
336-
last_modified = filedict.last_modified,
337-
)
335+
old_etag = filedict.etag
336+
old_last_modified = filedict.last_modified
338337
new_headinfo = get_new_headinfo_for_url(url)
339338
if isnothing(new_headinfo)
340339
return false
341340
end
342-
if old_headinfo != new_headinfo
343-
@warn "HeadInfo for URL $url has changed from $old_headinfo to $new_headinfo"
341+
if old_etag != new_headinfo.etag
342+
@warn "ETag for URL $url has changed from $(old_etag) to $(new_headinfo.etag)"
343+
return false
344+
end
345+
if old_last_modified != new_headinfo.last_modified
346+
@warn "Last-Modified for URL $url has changed from $(old_last_modified) to $(new_headinfo.last_modified)"
344347
return false
345348
end
346349

@@ -433,9 +436,13 @@ function get_tags()
433436
else
434437
# The user didn't provide GITHUB_TOKEN, so we have to make an unauthenticated call
435438
# to the GitHub API.
436-
# Warning: The rate limit for unauthenticated calls is very low.
439+
# The rate limit for unauthenticated calls is very low, so we cache this.
437440
@warn "GITHUB_TOKEN not detected. It is recommended that you provide a GITHUB_TOKEN (with read-only access to only public repos)."
438-
return GitHub.gh_get_json(GitHub.DEFAULT_API, "/$request_path"; auth)
441+
tags_json_path = download_to_cache(
442+
"julia_tags.json",
443+
"https://api.github.com/$request_path",
444+
)
445+
return JSON.parse(String(read(tags_json_path)))
439446
end
440447
end
441448

@@ -540,7 +547,7 @@ function main!(content::OutputJsonContent, cfg::Config)
540547

541548
# Download this URL to a local file in a temp directory
542549
number_urls_tried += 1
543-
filepath = Downloads.download(url)
550+
filepath = Downloads.download(string(url))
544551

545552
if filesize(filepath) == 0
546553
# The file is empty
@@ -572,7 +579,7 @@ function main!(content::OutputJsonContent, cfg::Config)
572579
kind = "archive"
573580
extension = "zip"
574581
else
575-
error("Unsupported file extension in filename: $(filename)")
582+
error("Unsupported file extension in filename: filename")
576583
end
577584

578585
if extension == "tar.gz" && !(url in tarball_git_tree_hash_skiplist)

src/download.jl

Whitespace-only changes.

src/web_cache_utilities.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Dates: Dates, now, UTC, unix2datetime, TimePeriod, Hour
2+
using URIs: URI
3+
4+
function download_to_cache(filename::String, url::Union{String, URI})
5+
file_path = _hit_file_cache(filename) do file_path
6+
r = open(io -> HTTP.get(url; response_stream=io), file_path, "w")
7+
if r.status != 200
8+
error("Unable to download $(url) to $(filename)")
9+
end
10+
end
11+
return file_path
12+
end
13+
14+
function _hit_file_cache(creator::Function, filename::String, lifetime::TimePeriod = Hour(24))
15+
cache_dir = abspath(joinpath(@__DIR__, "..", "cache"))
16+
if !isdir(cache_dir)
17+
mkpath(cache_dir)
18+
end
19+
20+
cache_path = joinpath(cache_dir, filename)
21+
if isfile(cache_path)
22+
age = now(UTC) - unix2datetime(stat(cache_path).mtime)
23+
if age < lifetime
24+
@debug "Cache hit" filename isfile(cache_path) age Dates.canonicalize(age) lifetime
25+
return abspath(cache_path)
26+
else
27+
@debug "Cache miss. Cache entry found, but stale (too old)" filename isfile(cache_path) age Dates.canonicalize(age) lifetime
28+
end
29+
else
30+
@debug "Cache miss. Cache entry not found" filename isfile(cache_path)
31+
end
32+
33+
rm(cache_path; force=true)
34+
mktempdir() do tmpdir
35+
tmp_path = joinpath(tmpdir, filename)
36+
37+
creator(tmp_path)
38+
39+
if !isfile(tmp_path)
40+
error("Creator function didn't actually create file: $filename")
41+
end
42+
try
43+
mv(tmp_path, cache_path; force = true)
44+
catch
45+
rm(cache_path; force=true)
46+
rethrow()
47+
end
48+
end
49+
50+
if !isfile(cache_path)
51+
error("Our mv must have somehow failed for file: $filename")
52+
end
53+
# Update the mtime:
54+
touch(cache_path)
55+
56+
@debug "Successfully saved new cache entry" filename
57+
58+
return abspath(cache_path)
59+
end

0 commit comments

Comments
 (0)