Skip to content

Commit

Permalink
Bugfix: in the second push (force_ci_trigger()), make sure to actua…
Browse files Browse the repository at this point in the history
…lly push to the SSH remote (#505)

* Create a new remote with the url

* Bump version

* Apply suggestions from code review

Co-authored-by: Dilum Aluthge <[email protected]>

* Fix function signatures, move remote add closer to point of use

* Fix tests, check remotes to determine add vs seturl

* Downgrade version number bump to minor

* Remove unneeded patch

* Extract `remote_exists()`, add tests for new functions

* Make tests more sensible

* Expand seturl test

---------

Co-authored-by: Dilum Aluthge <[email protected]>
  • Loading branch information
penelopeysm and DilumAluthge authored Sep 24, 2024
1 parent 69d49c0 commit 370e3db
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
authors = ["Dilum Aluthge", "Brown Center for Biomedical Informatics", "contributors"]
version = "3.11.0"
version = "3.12.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
11 changes: 11 additions & 0 deletions src/utilities/git.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ function git_get_master_branch(master_branch::DefaultBranch)
return string(strip(read(`git rev-parse --abbrev-ref HEAD`, String)))
end
git_get_master_branch(master_branch::AbstractString) = master_branch

function remote_exists(remote_name::AbstractString)
return remote_name in split(strip(read(`git remote`, String)), '\n')
end

function git_remote_add_or_seturl(remote_name::AbstractString, url::AbstractString)
git_remote_subcommand = remote_exists(remote_name) ? "set-url" : "add"
run(`git remote $git_remote_subcommand $remote_name $url`)

return nothing
end
12 changes: 11 additions & 1 deletion src/utilities/new_versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ function continue_with_pr(dep::DepInfo, bump_compat_containing_equality_specifie
return true
end

const COMPATHELPER_SSH_REMOTE_NAME = "compathelper-ssh-remote"

function make_pr_for_new_version(
forge::Forge,
repo::Union{GitHub.Repo,GitLab.Project},
Expand Down Expand Up @@ -286,6 +288,8 @@ function make_pr_for_new_version(
if commit_was_success
@info("Commit was a success")
api_retry() do
# For the first push, we intentionally push to the HTTPS remote (`origin`),
# because we want to avoid triggering duplicate CI runs.
@mock git_push(
"origin", new_branch_name, pkey_filename; force=true, env=env
)
Expand All @@ -297,6 +301,12 @@ function make_pr_for_new_version(

options.cc_user && cc_mention_user(forge, repo, new_pr; env=env)
options.unsub_from_prs && unsub_from_pr(forge, new_pr)

# If we have an SSH key, we need to create a new remote (or update
# it) with the appropriate URL (ssh/https) so that force_ci_trigger()
# can use it
git_remote_add_or_seturl(COMPATHELPER_SSH_REMOTE_NAME, repo_git_url)

force_ci_trigger(forge, new_pr_title, new_branch_name, pkey_filename; env=env)

# Return to the master branch
Expand Down Expand Up @@ -345,7 +355,7 @@ function force_ci_trigger(
# Force push the changes to trigger the PR
api_retry() do
@debug "force_ci_trigger: force-pushing the changes to trigger CI on the PR"
@mock git_push("origin", branch_name, pkey_filename; force=true, env=env)
@mock git_push(COMPATHELPER_SSH_REMOTE_NAME, branch_name, pkey_filename; force=true, env=env)
end
end

Expand Down
45 changes: 45 additions & 0 deletions test/utilities/git.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,48 @@ end
end
end
end

@testset "remote_exists" begin
mktempdir() do f
cd(f) do
run(`git init`)
run(`git remote add origin foo-url`)
run(`git remote add upstream bar-url`)

@testset "remote exists" begin
@test CompatHelper.remote_exists("origin")
@test CompatHelper.remote_exists("upstream")
end
@testset "remote does not exist" begin
@test !CompatHelper.remote_exists("nonexistent")
end
end
end
end

@testset "git_remote_add_or_seturl" begin
mktempdir() do f
cd(f) do
run(`git init`)
run(`git remote add origin foo-url`)

@testset "set existing remote" begin
url = "bar-url"
CompatHelper.git_remote_add_or_seturl("origin", url)
output = strip(read(`git remote get-url origin`, String))
@test output == url

url2 = "bar-url2"
CompatHelper.git_remote_add_or_seturl("origin", url2)
output = strip(read(`git remote get-url origin`, String))
@test output == url2
end
@testset "add new remote" begin
url = "baz-url"
CompatHelper.git_remote_add_or_seturl("upstream", url)
output = strip(read(`git remote get-url upstream`, String))
@test output == url
end
end
end
end

2 comments on commit 370e3db

@DilumAluthge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115803

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.12.0 -m "<description of version>" 370e3db84398bfab22609760a3a1c07625a5e6a7
git push origin v3.12.0

Please sign in to comment.