Skip to content
Open
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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Configure Git
shell: bash
run: |
git config --global user.name "Tester"
git config --global user.email "test@example.com"
if [ -n "$GIST_TESTING_TOKEN" ]; then
git config --global credential.https://gist.github.com.helper store
echo "https://julia-artifactutils-bot:$GIST_TESTING_TOKEN@gist.github.com" > ~/.git-credentials
fi
env:
GIST_TESTING_TOKEN: ${{ secrets.GIST_TESTING_TOKEN }}
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
show-versioninfo: true
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
env:
GIST_TESTING_TOKEN: ${{ secrets.GIST_TESTING_TOKEN }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand Down
5 changes: 4 additions & 1 deletion src/ArtifactUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ add it to `"Artifact.toml"` with the name `"name"`.

## Keyword Arguments
- `private`: if `true`, upload the archive to a private gist
- `ssh`: if `true`, use SSH URL for git operations. This requires the user to have SSH keys
set up with GitHub.
- `name`: name of the archive file, including file extension
- `extension`: file extension of the tarball. It can be used for specifying the compression
method.
Expand All @@ -167,14 +169,15 @@ function upload_to_gist(
artifact_id::SHA1,
tarball::AbstractString;
private::Bool = true,
ssh::Bool = true,
archive_options...,
)
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)
url = gist_from_file(tarball; private = private, ssh = ssh)
return GistUploadResult(
artifact_id,
basename(tarball),
Expand Down
20 changes: 12 additions & 8 deletions src/gistutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

Create a new gist from file at `filepath`. Return the "raw" HTTPS URL of the file.
"""
function gist_from_file(filepath::AbstractString; private::Bool = true)
function gist_from_file(filepath::AbstractString; private::Bool = true, ssh::Bool = true)
@assert isfile(filepath)
# Using `with_new_gist` utility defined below instead of simply calling `gh gist create
# $filepath`. This seems to be required when the file at `filepath` is not a text file.
repo_http = with_new_gist(; private = private) do git_dir
repo_http = with_new_gist(; private = private, ssh = ssh) do git_dir
cp(filepath, joinpath(git_dir, basename(filepath)))
end
return rstrip(repo_http, '/') * "/raw/" * basename(filepath)
Expand All @@ -20,20 +20,24 @@ Create a new gist, check it out as a local git repository at a temporary directo
`git_dir`, call `f(git_dir)`, and then push it to remote. Return the canonical gist HTTPS
URL.
"""
function with_new_gist(f; private::Bool = true)
function with_new_gist(f; private::Bool = true, ssh::Bool = true)
cmd = gh_cli_jll.gh()
cmd = `$cmd gist create`
if !private
cmd = `$cmd --public`
end
repo_http = chomp(String(communicate(cmd, "dummy")))

m = match(r"https://gist.github.com/(.*)", repo_http)
if m === nothing
error("Unrecognized output from `gh cli`: ", repo_http)
if ssh
m = match(r"https://gist.github.com/(.*)", repo_http)
if m === nothing
error("Unrecognized output from `gh cli`: ", repo_http)
end
slug = split(m[1], '/')[2] # remove username
git_url = "git@gist.github.com:$slug.git"
else
git_url = repo_http * ".git"
end
slug = split(m[1], '/')[2] # remove username
git_url = "git@gist.github.com:$slug.git"

response = Ref{HTTP.Response}()
@sync begin
Expand Down
28 changes: 24 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ end
@test occursin("url =", str)
end

@testset "upload_to_gist" begin
if haskey(ENV, "GIST_TESTING_TOKEN")
withenv("GH_TOKEN" => ENV["GIST_TESTING_TOKEN"]) do
mktempdir() do tempdir
file = joinpath(tempdir, "hello.txt")
write(file, "Hello, world.\n")
artifact_id = artifact_from_directory(tempdir)
gist = upload_to_gist(artifact_id; ssh = false)

@test gist.id == artifact_id
@test occursin("gist.github.com", gist.url)

artifact_file = joinpath(tempdir, "Artifacts.toml")
add_artifact!(artifact_file, "hello", gist)
artifacts = TOML.parsefile(artifact_file)
@test haskey(artifacts, "hello")
@test artifacts["hello"]["git-tree-sha1"] == string(artifact_id)
end
end
else
@info "Skipping `upload_to_gist` tests since `GIST_TESTING_TOKEN` is not set"
end
end

@testset "artifact_from_directory" begin
mktempdir() do tempdir
file = joinpath(tempdir, "hello.txt")
Expand Down Expand Up @@ -92,10 +116,6 @@ end
git(args) = run(`$(Git.git()) --no-pager -C $git_dir $args`)
git(`init`)

# Setup repository-local user name and email so that it works on CI
git(`config user.email "test@example.com"`)
git(`config user.name "tester"`)

git(`checkout -b new-branch`)
write(joinpath(git_dir, "file-1"), "content")
git(`add file-1`)
Expand Down
Loading