From 18e421fac6cf7f8e3c682500033d98934ea086ee Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Wed, 20 Sep 2023 12:41:28 +0200 Subject: [PATCH] Don't override authentication callbacks in libgit2 clone (#319) Use the supported callbacks interface rather than trying to re-do the low level interface. As reported in https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/1287, we currently try to error when attempting to clone a repository over ssh (either directly or via the insteadOf git setting), because we accidentally override the base callback to provide ssh credentials. Fixes https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/1287 --- .github/workflows/ci.yml | 6 +++ src/Sources.jl | 23 ++++------- test/dependencies.jl | 41 +++++++++++-------- ...id_ecdsa_deploy_helloworld_c_jll_read_only | 9 ++++ 4 files changed, 48 insertions(+), 31 deletions(-) create mode 100644 test/id_ecdsa_deploy_helloworld_c_jll_read_only diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82c5cd2c..205cfcf8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,12 @@ jobs: run: julia --project=. --color=yes -e "using BinaryBuilderBase; BinaryBuilderBase.versioninfo()" - name: Run tests run: | + eval `ssh-agent` + chmod 0600 test/id_ecdsa_deploy_helloworld_c_jll_read_only + mkdir -p ~/.ssh + touch ~/.ssh/known_hosts + ssh-keyscan github.com >> ~/.ssh/known_hosts + ssh-add test/id_ecdsa_deploy_helloworld_c_jll_read_only julia --check-bounds=yes --color=yes --depwarn=yes --inline=yes --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.test(coverage=true)' - uses: julia-actions/julia-uploadcodecov@v0.1 continue-on-error: true diff --git a/src/Sources.jl b/src/Sources.jl index 6a481d99..ba1ea202 100644 --- a/src/Sources.jl +++ b/src/Sources.jl @@ -186,7 +186,8 @@ struct GitTransferProgress received_bytes::Csize_t end -function transfer_progress(progress::Ptr{GitTransferProgress}, p::Any) +function transfer_progress(progress::Ptr{GitTransferProgress}, payloads::Dict) + p = payloads[:transfer_progress] progress = unsafe_load(progress) p.n = progress.total_objects if progress.total_deltas != 0 @@ -225,25 +226,19 @@ function cached_git_clone(url::String; if verbose @info("Cloning git repository", url, repo_path) end + callbacks = LibGit2.Callbacks() + p = Progress(0, dt=1, desc="Cloning: ") if progressbar - # Clone with a progress bar - p = Progress(0, 1, "Cloning: ") - GC.@preserve p begin - callbacks = LibGit2.RemoteCallbacks( - transfer_progress=@cfunction( + callbacks[:transfer_progress] = ( + @cfunction( transfer_progress, Cint, (Ptr{GitTransferProgress}, Any) ), - payload = p - ) - fetch_opts = LibGit2.FetchOptions(; callbacks) - clone_opts = LibGit2.CloneOptions(; fetch_opts, bare = Cint(true)) - LibGit2.clone(url, repo_path, clone_opts) - end - else - LibGit2.clone(url, repo_path; isbare=true) + p + ) end + LibGit2.clone(url, repo_path; isbare=true, callbacks) end return repo_path end diff --git a/test/dependencies.jl b/test/dependencies.jl index 863c79b2..7998281e 100644 --- a/test/dependencies.jl +++ b/test/dependencies.jl @@ -275,24 +275,31 @@ end end # Dependency as a local directory - with_temp_project() do dir - mktempdir() do pkgdir - prefix = Prefix(dir) - # Clone if necessary the remote repository and check out its - # working directory in a temporary space. - cache_dir = cached_git_clone("https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl") - LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo - LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5") + for remote_url in ( + "https://github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl", + "ssh://git@github.com/JuliaBinaryWrappers/HelloWorldC_jll.jl" + ) + for progressbar in (true, false) + with_temp_project() do dir + mktempdir() do pkgdir + prefix = Prefix(dir) + # Clone if necessary the remote repository and check out its + # working directory in a temporary space. + cache_dir = cached_git_clone(remote_url; progressbar) + LibGit2.with(LibGit2.clone(cache_dir, pkgdir)) do repo + LibGit2.checkout!(repo, "c7f2e95d9c04e218931c14954ecd31ebde72cca5") + end + dependencies = [ + PackageSpec( + name="HelloWorldC_jll", + path=pkgdir, + ), + ] + platform = Platform("x86_64", "linux"; libc="glibc") + @test_logs setup_dependencies(prefix, dependencies, platform) + @test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"] + end end - dependencies = [ - PackageSpec( - name="HelloWorldC_jll", - path=pkgdir, - ), - ] - platform = Platform("x86_64", "linux"; libc="glibc") - @test_logs setup_dependencies(prefix, dependencies, platform) - @test readdir(joinpath(destdir(dir, platform), "bin")) == ["hello_world"] end end diff --git a/test/id_ecdsa_deploy_helloworld_c_jll_read_only b/test/id_ecdsa_deploy_helloworld_c_jll_read_only new file mode 100644 index 00000000..b972fd9a --- /dev/null +++ b/test/id_ecdsa_deploy_helloworld_c_jll_read_only @@ -0,0 +1,9 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS +1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQQg84ce7J+he7ByXanYD0nGVpw2b7h2 +1PJLi1MjyDTiT2iSZyLe9GMB1O5wx8/XS3NjAPghz5Y1vxfcGlw64DlbAAAAwIVGhjKFRo +YyAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCDzhx7sn6F7sHJd +qdgPScZWnDZvuHbU8kuLUyPINOJPaJJnIt70YwHU7nDHz9dLc2MA+CHPljW/F9waXDrgOV +sAAAAhAJ6u+41H8CUK5xnn1NiP3KODYU8iS3o0b3/+2emYw/03AAAAImtlbm9AS2Vub3Mt +TWFjQm9vay1Qcm8tMi5mcml0ei5ib3gBAgMEBQ== +-----END OPENSSH PRIVATE KEY-----