diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4321f55..20c6d0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,6 @@ name: CI on: pull_request: - branches: - - master push: branches: - master @@ -61,7 +59,15 @@ jobs: arch: ${{ matrix.arch }} - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 + - name: On Linux and Windows, ssh-keyscan github.com and store in known-hosts + shell: bash + run: | + mkdir -p ~/.ssh + ssh-keyscan github.com >> ~/.ssh/known_hosts + if: runner.os == 'Linux' || runner.os == 'Windows' - uses: julia-actions/julia-runtest@v1 + env: + CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY: ${{ secrets.CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY }} - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v5 with: diff --git a/Project.toml b/Project.toml index 3ebb083..2619f85 100644 --- a/Project.toml +++ b/Project.toml @@ -1,19 +1,21 @@ name = "Git" uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2" +version = "1.4.0" authors = ["Dilum Aluthge", "contributors"] -version = "1.3.1" [deps] Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb" +JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" +OpenSSH_jll = "9bd350c2-7e96-507f-8002-3f2e150b4e1b" [compat] Git_jll = "2.44" JLLWrappers = "1.1" +OpenSSH_jll = "9, 10" julia = "1.6" [extras] -JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["JLLWrappers", "Test"] +test = ["Test"] diff --git a/src/git_function.jl b/src/git_function.jl index 867f697..1e34733 100644 --- a/src/git_function.jl +++ b/src/git_function.jl @@ -1,3 +1,6 @@ +using OpenSSH_jll: OpenSSH_jll +using JLLWrappers: pathsep, LIBPATH_env + """ git() @@ -18,8 +21,8 @@ julia> run(git(["clone", "https://github.com/JuliaRegistries/General"])) to bypass the parsing of the command string. """ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) - @static if Sys.iswindows() - return Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd + git_cmd = @static if Sys.iswindows() + Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd else root = Git_jll.artifact_dir @@ -45,8 +48,26 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) end original_cmd = Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd - return addenv(original_cmd, env_mapping...)::Cmd + addenv(original_cmd, env_mapping...)::Cmd end + + # Use OpenSSH from the JLL: . + if !Sys.iswindows() && OpenSSH_jll.is_available() + path = split(get(ENV, "PATH", ""), pathsep) + libpath = split(get(ENV, LIBPATH_env, ""), pathsep) + + path = vcat(dirname(OpenSSH_jll.ssh_path), path) + libpath = vcat(OpenSSH_jll.LIBPATH_list, libpath) + path = vcat(dirname(Git_jll.git_path), path) + libpath = vcat(Git_jll.LIBPATH_list, libpath) + + unique!(filter!(!isempty, path)) + unique!(filter!(!isempty, libpath)) + + git_cmd = addenv(git_cmd, "PATH" => join(path, pathsep), LIBPATH_env => join(libpath, pathsep)) + end + + return git_cmd end function git(args::AbstractVector{<:AbstractString}; kwargs...) diff --git a/test/runtests.jl b/test/runtests.jl index 5095d81..6c539a2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -71,3 +71,39 @@ end @test dir1_log == dir2_log end; end end + +# https://github.com/JuliaVersionControl/Git.jl/issues/51 +@testset "OpenSSH integration" begin + is_ci = parse(Bool, strip(get(ENV, "CI", "false"))) + is_gha = parse(Bool, strip(get(ENV, "GITHUB_ACTIONS", "false"))) + if is_ci && is_gha + @info "This is GitHub Actions CI, so running the OpenSSH test..." + mktempdir() do sshprivkeydir + privkey_filepath = joinpath(sshprivkeydir, "my_private_key") + open(privkey_filepath, "w") do io + ssh_privkey = ENV["CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY"] + println(io, ssh_privkey) + end # open + # We need to chmod our private key to 600, or SSH will ignore it. + chmod(privkey_filepath, 0o600) + + # ssh_verbose = "-vvv" # comment this line back out when you are finished debugging + ssh_verbose = "" # uncomment this line when you are finished debugging + + withenv("GIT_SSH_COMMAND" => "ssh $(ssh_verbose) -i \"$(privkey_filepath)\"") do + withtempdir() do workdir + @test !isdir("Git.jl") + @test !isfile(joinpath("Git.jl", "Project.toml")) + # We use `run()` so that we can see the stdout and stderr in the CI logs: + proc = run(`$(git()) clone --depth=1 git@github.com:JuliaVersionControl/Git.jl.git`) + @test success(proc) + @test isdir("Git.jl") + @test isfile(joinpath("Git.jl", "Project.toml")) + end # withtempdir/workdir + end # withenv + end # withtempdir/sshprivkeydir + else + # Mark this test as skipped if we are not running in CI + @test_skip false + end # if +end # testset