Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save artifact download size #25

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,23 @@ jobs:
strategy:
matrix:
version:
- '1.6'
- 'lts'
- '1'
- 'nightly'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
- 'default'
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
show-versioninfo: true
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
Expand All @@ -51,8 +42,8 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- run: |
Expand Down
16 changes: 12 additions & 4 deletions src/ArtifactUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function add_artifact!(

tarball_path = download(tarball_url)
sha256 = sha256sum(tarball_path)
tarball_size = filesize(tarball_path)
iszero(tarball_size) && error("tarball has zero filesize")

git_tree_sha1 = create_artifact() do artifact_dir
unpack(tarball_path, artifact_dir)
Expand All @@ -73,7 +75,7 @@ function add_artifact!(
artifacts_toml,
name,
git_tree_sha1;
download_info = [(tarball_url, sha256)],
download_info = [(tarball_url, sha256, tarball_size)],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a little surprised to see this works, I suppose it's good I didn't specify the types in the tuple originally!

options...,
)

Expand Down Expand Up @@ -123,6 +125,7 @@ struct GistUploadResult
localpath::Union{String,Nothing}
url::String
sha256::String
size::UInt64
private::Bool
end

Expand Down Expand Up @@ -169,13 +172,16 @@ function upload_to_gist(
mkpath(dirname(tarball))
archive_artifact(artifact_id, tarball; archive_options...)
sha256 = sha256sum(tarball)
tarball_size = filesize(tarball)
iszero(tarball_size) && error("tarball has zero filesize")
url = gist_from_file(tarball; private = private)
return GistUploadResult(
artifact_id,
basename(tarball),
abspath(tarball),
url,
sha256,
tarball_size,
private,
)
end
Expand Down Expand Up @@ -245,7 +251,9 @@ function upload_all_to_gist!(
tarball_path = joinpath(tmpdir, up.name * extension)
archive_artifact(up.git_tree_sha1, tarball_path)
sha256 = sha256sum(tarball_path)
push!(artifacts[up.name]["download"], Dict{String,Any}("sha256" => sha256))
tarball_size = filesize(tarball_path)
iszero(tarball_size) && error("tarball has zero filesize")
push!(artifacts[up.name]["download"], Dict{String,Any}("sha256" => sha256, "size" => tarball_size))
end
@info "Uploading archive to gist"
repo_http = with_new_gist(; private) do git_dir
Expand Down Expand Up @@ -277,7 +285,7 @@ function add_artifact!(
artifacts_toml,
name,
gist.artifact_id;
download_info = [(gist.url, gist.sha256)],
download_info = [(gist.url, gist.sha256, gist.size)],
options...,
)
end
Expand All @@ -292,7 +300,7 @@ function print_artifact_entry(
dict = Dict(
name => Dict(
"git-tree-sha1" => string(gist.artifact_id),
"download" => [Dict("url" => gist.url, "sha256" => gist.sha256)],
"download" => [Dict("url" => gist.url, "sha256" => gist.sha256, "size" => gist.size)],
),
)
TOML.print(io, dict; sorted = true)
Expand Down
40 changes: 18 additions & 22 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ function _artifact(name, loc)
eval(Expr(:macrocall, Symbol("@artifact_str"), LineNumberNode(1, Symbol(loc)), name))
end

expected_artifacts = Dict{String,Any}(
"JuliaMono" => Dict{String,Any}(
"git-tree-sha1" => "65279f9c8a3dd1e2cb654fdedbe8cd58889ae1bc",
"download" => Any[
Dict{String,Any}(
"sha256" => "f1ab65231cda7981531398644a58fd5fde8f367b681e1b8e9c35d9b2aacfcb1c",
"url" => "https://github.com/cormullion/juliamono/releases/download/v0.007/JuliaMono.tar.gz",
"size" => UInt64(5752883),
),
],
),
)
expected_artifacts_nosize = deepcopy(expected_artifacts)
delete!(expected_artifacts_nosize["JuliaMono"]["download"][1], "size")

@testset "ArtifactUtils.jl" begin
mktempdir() do tempdir
artifact_file = joinpath(tempdir, "Artifacts.toml")
Expand All @@ -19,17 +34,7 @@ end
force=true,
)
artifacts = TOML.parsefile(artifact_file)
@test artifacts == Dict{String,Any}(
"JuliaMono" => Dict{String,Any}(
"git-tree-sha1" => "65279f9c8a3dd1e2cb654fdedbe8cd58889ae1bc",
"download" => Any[
Dict{String,Any}(
"sha256" => "f1ab65231cda7981531398644a58fd5fde8f367b681e1b8e9c35d9b2aacfcb1c",
"url" => "https://github.com/cormullion/juliamono/releases/download/v0.007/JuliaMono.tar.gz",
),
],
),
)
@test artifacts == expected_artifacts || artifacts == expected_artifacts_nosize
ensure_artifact_installed("JuliaMono", artifact_file)
@test ispath(_artifact("JuliaMono", tempdir))
hash = ArtifactUtils.sha256sum(joinpath(_artifact("JuliaMono", tempdir), "JuliaMono-Regular.ttf"))
Expand All @@ -45,23 +50,14 @@ end
"<localpath>",
"https://github.com/cormullion/juliamono/releases/download/v0.007/JuliaMono.tar.gz",
"f1ab65231cda7981531398644a58fd5fde8f367b681e1b8e9c35d9b2aacfcb1c",
UInt64(5752883),
false,
)
mktempdir() do tempdir
artifact_file = joinpath(tempdir, "Artifacts.toml")
add_artifact!(artifact_file, "JuliaMono", gist)
artifacts = TOML.parsefile(artifact_file)
@test artifacts == Dict{String,Any}(
"JuliaMono" => Dict{String,Any}(
"git-tree-sha1" => "65279f9c8a3dd1e2cb654fdedbe8cd58889ae1bc",
"download" => Any[
Dict{String,Any}(
"sha256" => "f1ab65231cda7981531398644a58fd5fde8f367b681e1b8e9c35d9b2aacfcb1c",
"url" => "https://github.com/cormullion/juliamono/releases/download/v0.007/JuliaMono.tar.gz",
),
],
),
)
@test artifacts == expected_artifacts || artifacts == expected_artifacts_nosize
end
str = sprint(show, "text/plain", gist)
@test occursin("upload_to_gist(", str)
Expand Down
Loading