Skip to content

Commit 5978de2

Browse files
Merge pull request #16 from PumasAI/mh/artifacts
Allow creating `Artifacts.toml` and associated `.tar.gz` as `outputs`
2 parents 3ee45b1 + 7a42f95 commit 5978de2

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

src/PackageBundler.jl

+40-15
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ should your dependencies change.
6868
6969
The `outputs` field is the target for the bundle. It can be a directory, a
7070
tarball, or an `Artifacts.toml` file. Or it can be an array of multiple targets.
71+
For `Artifacts.toml` files the `artifacts_url` field must be specified, which
72+
points at the URL where the tarball can be downloaded from.
7173
7274
The `key` field is the name of the private and public key files. The private key
7375
is used to sign the bundled packages and the public key is included in the
@@ -101,10 +103,7 @@ listed below. The valid names for handlers are:
101103
- `code_injector.jl`: A function that injects extra code into the bundled
102104
packages. Takes `filename` as an argument.
103105
"""
104-
function bundle(
105-
config::AbstractString = "PackageBundler.toml";
106-
clean::Bool = false,
107-
)
106+
function bundle(config::AbstractString = "PackageBundler.toml"; clean::Bool = false)
108107
config = abspath(config)
109108
endswith(config, ".toml") || error("Config file must be a TOML file: `$config`.")
110109
isfile(config) || error("Config file not found: `$config`.")
@@ -164,6 +163,9 @@ function bundle(
164163
outputs = String.(vcat(outputs))
165164
outputs = isempty(outputs) ? [name] : outputs
166165

166+
# Artifact URL for `Artifacts.toml` files.
167+
artifact_url = get(config, "artifacts_url", nothing)::Union{String,Nothing}
168+
167169
# Multiplexers. The list of multiplexer programs to try to use to select
168170
# specific versions of Julia for each environment based on it's
169171
# `julia_version`.
@@ -208,18 +210,41 @@ function bundle(
208210
end
209211
isdir(output) || mkpath(output)
210212
cp(temp_dir, output; force = true)
211-
else
212-
if is_artifacts
213-
# TODO: implement.
214-
error("unsupported output type: $output")
215-
else
216-
@info "Generating tarball bundle." output
217-
isdir(dirname(output)) || mkpath(dirname(output))
218-
tar_gz = open(output, write = true)
219-
tar = CodecZlib.GzipCompressorStream(tar_gz)
220-
Tar.create(temp_dir, tar)
221-
close(tar)
213+
elseif is_tarball
214+
@info "Generating tarball bundle." output
215+
isdir(dirname(output)) || mkpath(dirname(output))
216+
tar_gz = open(output, write = true)
217+
tar = CodecZlib.GzipCompressorStream(tar_gz)
218+
Tar.create(temp_dir, tar)
219+
close(tar)
220+
elseif is_artifacts
221+
@info "Generating Artifacts.toml bundle." output
222+
if isnothing(artifact_url)
223+
error("`artifacts_url` must be specified for Artifacts.toml output.")
224+
end
225+
artifact_toml = joinpath(temp_dir, "Artifacts.toml")
226+
product_hash = Pkg.Artifacts.create_artifact() do artifact_dir
227+
cp(temp_dir, artifact_dir; force = true)
222228
end
229+
artifact_name = "$name.tar.gz"
230+
temp_artifact = joinpath(temp_dir, artifact_name)
231+
download_hash = Pkg.Artifacts.archive_artifact(product_hash, temp_artifact)
232+
Pkg.Artifacts.bind_artifact!(
233+
artifact_toml,
234+
name,
235+
product_hash,
236+
force = true,
237+
download_info = Tuple[("$artifact_url/$artifact_name", download_hash)],
238+
)
239+
if clean && isdir(dirname(output))
240+
@warn "Cleaning directory." dirname(output)
241+
rm(dirname(output); recursive = true)
242+
end
243+
isdir(dirname(output)) || mkpath(dirname(output))
244+
cp(artifact_toml, output; force = true)
245+
cp(temp_artifact, joinpath(dirname(output), artifact_name); force = true)
246+
else
247+
error("Invalid output target: $output")
223248
end
224249
end
225250
end

test/PackageBundler.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
name = "LocalCustomRegistry"
22
uuid = "a0e467e0-8c5a-11e4-9d3f-823b93f75cbb"
33
environments = ["envs/CustomEnv"]
4-
outputs = ["build/LocalCustomRegistry", "build/LocalCustomRegistry.tar.gz"]
4+
outputs = [
5+
"build/LocalCustomRegistry",
6+
"build/LocalCustomRegistry.tar.gz",
7+
"build/LocalCustomRegistryArtifacts/Artifacts.toml"
8+
]
9+
artifacts_url = "URL_GOES_HERE"
510
key = "key"
611
clean = true
712

test/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
2+
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
23
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Test, PackageBundler
1+
using Test, TOML, PackageBundler
22

33
@testset "PackageBundler" begin
44
key = PackageBundler.keypair()
@@ -16,6 +16,12 @@ using Test, PackageBundler
1616
remove_script = joinpath(registry_path, "remove.jl")
1717
@test isfile(remove_script)
1818

19+
artifact_toml = TOML.parsefile(
20+
joinpath(@__DIR__, "build", "LocalCustomRegistryArtifacts", "Artifacts.toml"),
21+
)
22+
@test artifact_toml["LocalCustomRegistry"]["download"][1]["url"] ==
23+
"URL_GOES_HERE/LocalCustomRegistry.tar.gz"
24+
1925
mktempdir() do temp_depot
2026
withenv("JULIA_DEPOT_PATH" => temp_depot, "JULIA_PKG_SERVER" => "") do
2127
run(

0 commit comments

Comments
 (0)