Skip to content

Commit f588510

Browse files
Add OpenSSH_jll as a direct dependency, and force our Git to use OpenSSH_jll (instead of the system ssh) (#55)
* Use `ssh` from `OpenSSH_jll` instead of relying on system one * Add tests * Remove unnecessary `cd()` in tests * Mark a test as skipped if not CI * Apply suggestions from code review Co-authored-by: Mosè Giordano <[email protected]> * Make sure secret is available * Use `run()` so we can see stdout and stder * Add back also `Git_jll` paths * ssh -vvv * chmod 600 our private key * Linux github.com known hosts * mkdir -p ~/.ssh (linux) * Windows known hosts * Whitespace * Update runtests.jl * Don't do the `OpenSSH_jll` stuff on Windows (#62) * Don't do the `OpenSSH_jll` stuff on Windows * Run CI on all PRs (regardless of the target branch) * Test suite: turn off SSH verbosity * Apply suggestions from code review --------- Co-authored-by: Mosè Giordano <[email protected]>
1 parent f818f5a commit f588510

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: CI
22

33
on:
44
pull_request:
5-
branches:
6-
- master
75
push:
86
branches:
97
- master
@@ -61,7 +59,15 @@ jobs:
6159
arch: ${{ matrix.arch }}
6260
- uses: julia-actions/cache@v2
6361
- uses: julia-actions/julia-buildpkg@v1
62+
- name: On Linux and Windows, ssh-keyscan github.com and store in known-hosts
63+
shell: bash
64+
run: |
65+
mkdir -p ~/.ssh
66+
ssh-keyscan github.com >> ~/.ssh/known_hosts
67+
if: runner.os == 'Linux' || runner.os == 'Windows'
6468
- uses: julia-actions/julia-runtest@v1
69+
env:
70+
CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY: ${{ secrets.CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY }}
6571
- uses: julia-actions/julia-processcoverage@v1
6672
- uses: codecov/codecov-action@v5
6773
with:

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
name = "Git"
22
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
3+
version = "1.4.0"
34
authors = ["Dilum Aluthge", "contributors"]
4-
version = "1.3.1"
55

66
[deps]
77
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"
8+
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
9+
OpenSSH_jll = "9bd350c2-7e96-507f-8002-3f2e150b4e1b"
810

911
[compat]
1012
Git_jll = "2.44"
1113
JLLWrappers = "1.1"
14+
OpenSSH_jll = "9, 10"
1215
julia = "1.6"
1316

1417
[extras]
15-
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
1618
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1719

1820
[targets]
19-
test = ["JLLWrappers", "Test"]
21+
test = ["Test"]

src/git_function.jl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using OpenSSH_jll: OpenSSH_jll
2+
using JLLWrappers: pathsep, LIBPATH_env
3+
14
"""
25
git()
36
@@ -18,8 +21,8 @@ julia> run(git(["clone", "https://github.com/JuliaRegistries/General"]))
1821
to bypass the parsing of the command string.
1922
"""
2023
function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
21-
@static if Sys.iswindows()
22-
return Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
24+
git_cmd = @static if Sys.iswindows()
25+
Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
2326
else
2427
root = Git_jll.artifact_dir
2528

@@ -45,8 +48,26 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
4548
end
4649

4750
original_cmd = Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
48-
return addenv(original_cmd, env_mapping...)::Cmd
51+
addenv(original_cmd, env_mapping...)::Cmd
4952
end
53+
54+
# Use OpenSSH from the JLL: <https://github.com/JuliaVersionControl/Git.jl/issues/51>.
55+
if !Sys.iswindows() && OpenSSH_jll.is_available()
56+
path = split(get(ENV, "PATH", ""), pathsep)
57+
libpath = split(get(ENV, LIBPATH_env, ""), pathsep)
58+
59+
path = vcat(dirname(OpenSSH_jll.ssh_path), path)
60+
libpath = vcat(OpenSSH_jll.LIBPATH_list, libpath)
61+
path = vcat(dirname(Git_jll.git_path), path)
62+
libpath = vcat(Git_jll.LIBPATH_list, libpath)
63+
64+
unique!(filter!(!isempty, path))
65+
unique!(filter!(!isempty, libpath))
66+
67+
git_cmd = addenv(git_cmd, "PATH" => join(path, pathsep), LIBPATH_env => join(libpath, pathsep))
68+
end
69+
70+
return git_cmd
5071
end
5172

5273
function git(args::AbstractVector{<:AbstractString}; kwargs...)

test/runtests.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,39 @@ end
7171
@test dir1_log == dir2_log
7272
end; end
7373
end
74+
75+
# https://github.com/JuliaVersionControl/Git.jl/issues/51
76+
@testset "OpenSSH integration" begin
77+
is_ci = parse(Bool, strip(get(ENV, "CI", "false")))
78+
is_gha = parse(Bool, strip(get(ENV, "GITHUB_ACTIONS", "false")))
79+
if is_ci && is_gha
80+
@info "This is GitHub Actions CI, so running the OpenSSH test..."
81+
mktempdir() do sshprivkeydir
82+
privkey_filepath = joinpath(sshprivkeydir, "my_private_key")
83+
open(privkey_filepath, "w") do io
84+
ssh_privkey = ENV["CI_READONLY_DEPLOYKEY_FOR_CI_TESTSUITE_PRIVATEKEY"]
85+
println(io, ssh_privkey)
86+
end # open
87+
# We need to chmod our private key to 600, or SSH will ignore it.
88+
chmod(privkey_filepath, 0o600)
89+
90+
# ssh_verbose = "-vvv" # comment this line back out when you are finished debugging
91+
ssh_verbose = "" # uncomment this line when you are finished debugging
92+
93+
withenv("GIT_SSH_COMMAND" => "ssh $(ssh_verbose) -i \"$(privkey_filepath)\"") do
94+
withtempdir() do workdir
95+
@test !isdir("Git.jl")
96+
@test !isfile(joinpath("Git.jl", "Project.toml"))
97+
# We use `run()` so that we can see the stdout and stderr in the CI logs:
98+
proc = run(`$(git()) clone --depth=1 [email protected]:JuliaVersionControl/Git.jl.git`)
99+
@test success(proc)
100+
@test isdir("Git.jl")
101+
@test isfile(joinpath("Git.jl", "Project.toml"))
102+
end # withtempdir/workdir
103+
end # withenv
104+
end # withtempdir/sshprivkeydir
105+
else
106+
# Mark this test as skipped if we are not running in CI
107+
@test_skip false
108+
end # if
109+
end # testset

0 commit comments

Comments
 (0)