Skip to content

Commit

Permalink
Try #443:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Nov 17, 2022
2 parents 8946ec1 + 2aa0b63 commit d3f230b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 65 deletions.
33 changes: 12 additions & 21 deletions src/dependencies.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
const LOCAL_REPO_NAME = "REPO"

function get_project_deps(
api::Forge,
ci::CIService,
repo::Union{GitHub.Repo,GitLab.Project};
options::Options,
subdir::AbstractString,
function get_local_clone(
api::Forge, ci::CIService, repo::Union{GitHub.Repo,GitLab.Project}; options
)
mktempdir() do f
url_with_auth = get_url_with_auth(api, ci, repo)
local_path = joinpath(f, LOCAL_REPO_NAME)
@mock git_clone(url_with_auth, local_path)

@mock cd(local_path) do
master_branch = @mock git_get_master_branch(options.master_branch)
@mock git_checkout(master_branch)
end

# Get all the compat dependencies from the local Project.toml file
project_file = @mock joinpath(local_path, subdir, "Project.toml")
deps = get_project_deps(project_file; include_jll=options.include_jll)

return deps
f = mktempdir()
url_with_auth = get_url_with_auth(api, ci, repo)
local_path = joinpath(f, LOCAL_REPO_NAME)
@mock git_clone(url_with_auth, local_path)

@mock cd(local_path) do
master_branch = @mock git_get_master_branch(options.master_branch)
@mock git_checkout(master_branch)
end

return local_path
end

function get_project_deps(project_file::AbstractString; include_jll::Bool=false)
Expand Down
5 changes: 4 additions & 1 deletion src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ function main(

api, repo = get_api_and_repo(ci_cfg)

local_path = get_local_clone(api, ci_cfg, repo; options)

for subdir in options.subdirs
deps = get_project_deps(api, ci_cfg, repo; options, subdir)
project_file = @mock joinpath(local_path, subdir, "Project.toml")
deps = get_project_deps(project_file; include_jll=options.include_jll)

if options.use_existing_registries
get_existing_registries!(deps, options.depot; options)
Expand Down
48 changes: 18 additions & 30 deletions test/dependencies.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
@testset "get_project_deps" begin
@testset "no jll" begin
apply([git_clone_patch, project_toml_patch, cd_patch]) do
options = CompatHelper.Options()
subdir = only(options.subdirs)
deps = CompatHelper.get_project_deps(
GitForge.GitHub.GitHubAPI(; token=GitHub.Token("token")),
GitHubActions(),
GitHub.Repo(; full_name="foobar");
options=options,
subdir=subdir,
)

@test length(deps) == 1
end
@testset "get_local_clone" begin
apply([git_clone_patch, cd_patch]) do
options = CompatHelper.Options()
local_path = CompatHelper.get_local_clone(
GitForge.GitHub.GitHubAPI(; token=GitHub.Token("token")),
GitHubActions(),
GitHub.Repo(; full_name="foobar");
options,
)
@test local_path isa String
end
end

@testset "include_jll" begin
apply([git_clone_patch, project_toml_patch, cd_patch]) do
options = CompatHelper.Options(; include_jll=true)
subdir = only(options.subdirs)
deps = CompatHelper.get_project_deps(
GitForge.GitHub.GitHubAPI(; token=GitHub.Token("token")),
GitHubActions(),
GitHub.Repo(; full_name="foobar");
options=options,
subdir=subdir,
)

@test length(deps) == 2
end
end
@testset "get_project_deps" begin
project = joinpath(@__DIR__, "deps", "Project.toml")

deps = CompatHelper.get_project_deps(project; include_jll=true)
@test length(deps) == 2
deps = CompatHelper.get_project_deps(project; include_jll=false)
@test length(deps) == 1
end

@testset "clone_all_registries" begin
Expand Down
26 changes: 13 additions & 13 deletions test/utilities/git.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc
@testset "git_push" begin
function create_local_remote(dir::AbstractString)
remote_path = joinpath(dir, "localremote.git")
run(`git init --bare $remote_path`)
run(`git init --initial-branch=master --bare $remote_path`)

return remote_path
end
Expand All @@ -35,7 +35,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc
local_remote_path = create_local_remote(local_remote_dir)

cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`git remote add origin $local_remote_path`)

run(`touch foobar.txt`)
Expand All @@ -60,7 +60,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc
local_remote_path = create_local_remote(local_remote_dir)

cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`git remote add origin $local_remote_path`)

run(`touch foobar.txt`)
Expand Down Expand Up @@ -104,7 +104,7 @@ QQDtEmQvWdgz+HtIuTG1ySJ9FYO6LeCEXHtQX78aOfNaj2jqLTXHdqrMr0V5exJcNV4XSc
local_remote_path = create_local_remote(local_remote_dir)

cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`git remote add origin $local_remote_path`)

run(`touch foobar.txt`)
Expand All @@ -127,7 +127,7 @@ end
@testset "git_reset" begin
mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)

@test !isfile("foobar.txt")

Expand Down Expand Up @@ -163,7 +163,7 @@ end
@testset "success" begin
mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`touch foobar.txt`)
CompatHelper.git_add()

Expand All @@ -175,7 +175,7 @@ end
@testset "failure" begin
mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`touch foobar.txt`)
CompatHelper.git_add()

Expand All @@ -194,7 +194,7 @@ end
@testset "no checkout" begin
mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`touch foobar.txt`)
CompatHelper.git_add()
CompatHelper.git_commit("Message")
Expand All @@ -218,7 +218,7 @@ end
@testset "with checkout" begin
mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`touch foobar.txt`)
CompatHelper.git_add()
CompatHelper.git_commit("Message")
Expand All @@ -241,7 +241,7 @@ end

mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`touch foo.txt`)
run(`touch bar.txt`)

Expand Down Expand Up @@ -314,7 +314,7 @@ end

mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
# Need to create a commit before hand, see below
# https://stackoverflow.com/a/63480330/1327636
run(`touch foobar.txt`)
Expand All @@ -334,7 +334,7 @@ end
branch = "master"
mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=$(branch)`)
run(`touch foobar.txt`)
CompatHelper.git_add()
CompatHelper.git_commit("Message")
Expand All @@ -350,7 +350,7 @@ end
branch = "main"
mktempdir() do f
cd(f) do
run(`git init`)
run(`git init --initial-branch=master`)
run(`git branch -m $branch`)
run(`touch foobar.txt`)
CompatHelper.git_add()
Expand Down

0 comments on commit d3f230b

Please sign in to comment.