Skip to content

Commit ebde551

Browse files
Add tarball git-tree-sha1 metadata
Co-authored-by: OpenAI Codex GPT-5 <codex@openai.com>
1 parent f369eb9 commit ebde551

File tree

4 files changed

+77
-17
lines changed

4 files changed

+77
-17
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1010
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
1111
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1212
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
13+
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
1314
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
1415
WebCacheUtilities = "0c1c26de-fc5f-47ff-87a8-a157289a9bac"
1516

schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"sha256": {
4242
"type": "string"
4343
},
44+
"git-tree-sha1": {
45+
"type": "string"
46+
},
4447
"size": {
4548
"type": "integer"
4649
},

src/VersionsJSONUtil.jl

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module VersionsJSONUtil
22

3-
using HTTP, JSON, Pkg.BinaryPlatforms, WebCacheUtilities, SHA, Lazy
3+
using HTTP, JSON, Pkg.BinaryPlatforms, WebCacheUtilities, SHA, Lazy, Tar
44
import Pkg.BinaryPlatforms: triplet, arch
5+
import Pkg.PlatformEngines: exe7z
56

67
"Wrapper types to define three jlext methods for portable, tarball and installer Windows"
78
struct WindowsPortable
@@ -109,6 +110,11 @@ julia_platforms = [
109110
FreeBSD(:x86_64),
110111
]
111112

113+
const tarball_git_tree_sha1_skiplist = [
114+
# Corrupt gzip stream: `7z` reports a CRC failure for the embedded tarball.
115+
"https://julialang-s3.julialang.org/bin/linux/x86/0.7/julia-0.7.0-alpha-linux-i686.tar.gz",
116+
]
117+
112118
function vnum_maybe(x::AbstractString)
113119
try
114120
return VersionNumber(x)
@@ -122,6 +128,10 @@ function is_stable(v::VersionNumber)
122128
return v.prerelease == () && v.build == ()
123129
end
124130

131+
function tarball_git_tree_sha1(tarball_path::AbstractString)
132+
return open(Tar.tree_hash, `$(exe7z()) x $tarball_path -so`)
133+
end
134+
125135
# Get list of tags from the Julia repo
126136
function get_tags()
127137
@info("Probing for tag list...")
@@ -160,6 +170,22 @@ function main(out_path)
160170
number_urls_success += 1
161171
println(stdout, "")
162172

173+
if endswith(filename, ".dmg")
174+
kind = "archive"
175+
extension = "dmg"
176+
elseif endswith(filename, ".exe")
177+
kind = "installer"
178+
extension = "exe"
179+
elseif endswith(filename, ".tar.gz")
180+
kind = "archive"
181+
extension = "tar.gz"
182+
elseif endswith(filename, ".zip")
183+
kind = "archive"
184+
extension = "zip"
185+
else
186+
error("Unsupported file extension in filename: $(filename)")
187+
end
188+
163189
tarball_hash_path = hit_file_cache("$(filename).sha256") do tarball_hash_path
164190
open(filepath, "r") do io
165191
open(tarball_hash_path, "w") do hash_io
@@ -169,6 +195,17 @@ function main(out_path)
169195
end
170196
tarball_hash = String(read(tarball_hash_path))
171197

198+
tarball_git_tree_hash = if extension == "tar.gz" && !(url in tarball_git_tree_sha1_skiplist)
199+
tarball_git_tree_hash_path = hit_file_cache("$(filename).git-tree-sha1") do tree_hash_path
200+
open(tree_hash_path, "w") do hash_io
201+
write(hash_io, tarball_git_tree_sha1(filepath))
202+
end
203+
end
204+
String(read(tarball_git_tree_hash_path))
205+
else
206+
nothing
207+
end
208+
172209
# Initialize overall version key, if needed
173210
if !haskey(meta, version)
174211
meta[version] = Dict(
@@ -196,21 +233,6 @@ function main(out_path)
196233
end
197234

198235
# Build up metadata about this file
199-
if endswith(filename, ".dmg")
200-
kind = "archive"
201-
extension = "dmg"
202-
elseif endswith(filename, ".exe")
203-
kind = "installer"
204-
extension = "exe"
205-
elseif endswith(filename, ".tar.gz")
206-
kind = "archive"
207-
extension = "tar.gz"
208-
elseif endswith(filename, ".zip")
209-
kind = "archive"
210-
extension = "zip"
211-
else
212-
error("Unsupported file extension in filename: $(filename)")
213-
end
214236
file_dict = Dict(
215237
"triplet" => triplet(platform),
216238
"os" => meta_os(platform),
@@ -222,6 +244,9 @@ function main(out_path)
222244
"extension" => extension,
223245
"url" => url,
224246
)
247+
if tarball_git_tree_hash !== nothing
248+
file_dict["git-tree-sha1"] = tarball_git_tree_hash
249+
end
225250
# Add in `.asc` signature content, if applicable
226251
if asc_signature !== nothing
227252
file_dict["asc"] = asc_signature

test/runtests.jl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using Pkg.BinaryPlatforms, JSON
1+
using Pkg.BinaryPlatforms, JSON, Tar
22
using VersionsJSONUtil
33
import VersionsJSONUtil: WindowsPortable, WindowsTarball, MacOSTarball
4+
import VersionsJSONUtil: tarball_git_tree_sha1, tarball_git_tree_sha1_skiplist
5+
import Pkg.PlatformEngines: exe7z
46
using Test
57

68
const download_urls = Dict(
@@ -32,4 +34,33 @@ const download_urls = Dict(
3234
@test VersionsJSONUtil.download_url(v, p) == url
3335
end
3436
end
37+
38+
@testset "Tarball git-tree-sha1" begin
39+
mktempdir() do tempdir
40+
srcdir = joinpath(tempdir, "src")
41+
mkpath(joinpath(srcdir, "bin"))
42+
write(joinpath(srcdir, "README.txt"), "VersionsJSONUtil test fixture\n")
43+
write(joinpath(srcdir, "bin", "julia"), "#!/bin/sh\n")
44+
45+
tar_path = joinpath(tempdir, "fixture.tar")
46+
tar_gz_path = joinpath(tempdir, "fixture.tar.gz")
47+
Tar.create(srcdir, tar_path)
48+
run(`$(exe7z()) a -tgzip $tar_gz_path $tar_path`)
49+
50+
@test tarball_git_tree_sha1(tar_gz_path) == Tar.tree_hash(tar_path)
51+
end
52+
end
53+
54+
@testset "Tarball git-tree-sha1 skiplist" begin
55+
@test "https://julialang-s3.julialang.org/bin/linux/x86/0.7/julia-0.7.0-alpha-linux-i686.tar.gz" in tarball_git_tree_sha1_skiplist
56+
end
57+
58+
@testset "Schema tarball requirements" begin
59+
schema = JSON.parsefile(joinpath(dirname(@__DIR__), "schema.json"))
60+
file_properties = schema["definitions"]["File"]["properties"]
61+
file_required = Set(schema["definitions"]["File"]["required"])
62+
63+
@test haskey(file_properties, "git-tree-sha1")
64+
@test !("git-tree-sha1" in file_required)
65+
end
3566
end

0 commit comments

Comments
 (0)