Skip to content

A tool for package developers for working with artifacts.

License

Notifications You must be signed in to change notification settings

pat-alt/ArtifactUtils.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArtifactUtils

Stable Dev Build Status Coverage pkgeval

Provides the function add_artifact!, which makes it easy for Julia projects to ship their own tarballs as Artifacts.

Example

This will download the JuliaMono font from GitHub as a tarball and create a corresponding Artifacts.toml file in the current directory. It allows any Julia code in that directory to access these files with the artifact"..." string macro.

julia> using ArtifactUtils, Artifacts # Artifacts provides the artifact string macro

julia> add_artifact!(
                     "Artifacts.toml",
                     "JuliaMono",
                     "https://github.com/cormullion/juliamono/releases/download/v0.030/JuliaMono.tar.gz",
                     force=true,
                    )
SHA1("6c460cf2eccecd24499618112adbbe7e403fa1ee")

julia> import Pkg; Pkg.ensure_artifact_installed("JuliaMono", "Artifacts.toml")
  Downloaded artifact: JuliaMono
  Downloaded artifact: JuliaMono
"/home/simeon/.julia/artifacts/6c460cf2eccecd24499618112adbbe7e403fa1ee"

julia> artifact"JuliaMono"
"/home/simeon/.julia/artifacts/6c460cf2eccecd24499618112adbbe7e403fa1ee"

julia> run(`ls $ans`);
JuliaMono-Black.ttf	 JuliaMono-Bold.ttf	  JuliaMono-Light.ttf	JuliaMono-RegularLatin.ttf  LICENSE
JuliaMono-BoldLatin.ttf  JuliaMono-ExtraBold.ttf  JuliaMono-Medium.ttf	JuliaMono-Regular.ttf

Archive a directory and upload it to gist

You can create an artifact from a directory using artifact_from_directory and then upload it to gist with upload_to_gist. Note that upload_to_gist requires login with the GitHub CLI gh.

julia> using ArtifactUtils

julia> tempdir = mktempdir();

julia> write(joinpath(tempdir, "file"), "hello");

julia> artifact_id = artifact_from_directory(tempdir)
SHA1("538e83d637ab07ada6d841aa2454e0d5af4e52b3")

julia> gist = upload_to_gist(artifact_id)
- Creating gist...
✓ Created gist
Cloning into '.'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Switched to a new branch '__tmp__'
[__tmp__ (root-commit) f5a58a9] Initial commit
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
HEAD is now at f5a58a9 Initial commit
[master 44dfe9a] Add files
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 538e83d637ab07ada6d841aa2454e0d5af4e52b3.tar.gz
Counting objects: 5, done.
Delta compression using up to 128 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 455 bytes | 455.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To gist.github.com:a9ceed430ff970412fc6606ef1b84b6a
 + 2668e40...44dfe9a master -> master (forced update)
upload_to_gist(SHA1("538e83d637ab07ada6d841aa2454e0d5af4e52b3")) 

[538e83d637ab07ada6d841aa2454e0d5af4e52b3]
git-tree-sha1 = "538e83d637ab07ada6d841aa2454e0d5af4e52b3"

    [[538e83d637ab07ada6d841aa2454e0d5af4e52b3.download]]
    sha256 = "a530e9f7e371eeea4aa4fbce83a00ed32233b7766314670b1c0779eb46a7b68d"
    url = "https://gist.github.com/tkf/a9ceed430ff970412fc6606ef1b84b6a/raw/538e83d637ab07ada6d841aa2454e0d5af4e52b3.tar.gz"

You can copy-and-paste the printed artifact fragment into your Artifacts.toml file. You can also call add_artifact! with the gist result object.

julia> add_artifact!("Artifacts.toml", "hello_world", gist)

Archive a directory and upload it as release

You can also create an artifact from a directory using artifact_from_directory and then upload it as a tagged release with upload_to_release. Note that upload_to_release requires login using your GITHUB_TOKEN, which needs to be available from the environment.

julia> using ArtifactUtils

julia> tempdir = mktempdir();

julia> write(joinpath(tempdir, "file"), "hello");

julia> artifact_id = artifact_from_directory(tempdir)
SHA1("538e83d637ab07ada6d841aa2454e0d5af4e52b3")

julia> release = upload_to_release(artifact_id)
@Info (ArtifactUtils#release_from_file#46): Uploading tarballs to pat-alt/ArtifactUtils.jl tag `artifacts-latest`                                                                          
  │                                                                                                                                                                                        
  ╰──────────────────────────────────────────────── 
                       Sun, 14 Jan 2024 17:05:02 
--> Uploading: 538e83d637ab07ada6d841aa2454e0d5af4e52b3.tar.gz
ArtifactUtils.ReleaseUploadResult(SHA1("538e83d637ab07ada6d841aa2454e0d5af4e52b3"), "538e83d637ab07ada6d841aa2454e0d5af4e52b3.tar.gz", "/var/folders/ct/w1pc0ggd44907l8fkl8m5pdslbh6sh/T/jl_I38b3Z/538e83d637ab07ada6d841aa2454e0d5af4e52b3.tar.gz", "https://github.com/pat-alt/ArtifactUtils.jl/releases/download/artifacts-latest/538e83d637ab07ada6d841aa2454e0d5af4e52b3.tar.gz", "d81c7e810cd9d3588a7aa0aaffb9fbc8c4db6ad2bc27f8ddb8f5382b44a5a4f9", "artifacts-latest")

Simply call the add_artifact! with the release result object.

julia> add_artifact!("Artifacts.toml", "hello_world", release)

About

A tool for package developers for working with artifacts.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 100.0%