From b67f25cc97aa716a662fc9586ea6d5d7bf6c2da3 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sat, 8 Nov 2025 10:39:46 -0500 Subject: [PATCH] warn if merge commit content differs to branch head (#152) --- test_harness.jl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test_harness.jl b/test_harness.jl index b76c769..a80db03 100644 --- a/test_harness.jl +++ b/test_harness.jl @@ -14,6 +14,34 @@ kwargs = Kwargs.kwargs(; coverage=ENV["COVERAGE"], kwargs_reprs = map(kv -> string(kv[1], "=", repr(kv[2])), collect(kwargs)) kwargs_repr = join(kwargs_reprs, ", ") +# Warn if running on a merge commit (different from branch HEAD) +git_note = "" +if haskey(ENV, "GITHUB_SHA") && get(ENV, "GITHUB_EVENT_NAME", "") == "pull_request" && haskey(ENV, "GITHUB_HEAD_REF") + # For pull_request events, GITHUB_SHA is the merge commit, not the PR head commit + try + merge_commit = ENV["GITHUB_SHA"] + pr_branch = ENV["GITHUB_HEAD_REF"] + base_branch_name = get(ENV, "GITHUB_BASE_REF", "") + + # Check if there's any difference between the merge commit and the PR head + # In GitHub Actions, HEAD^2 is the PR head (second parent of merge commit) + # success() returns true if the command exits with 0 (no differences) + has_diff = !success(`git diff --quiet --exit-code HEAD^2 HEAD`) + + if has_diff + base_branch = isempty(base_branch_name) ? "the base branch" : "'$base_branch_name'" + global git_note = """ + │ Note: This is being run on merge commit $merge_commit (merge of PR branch '$pr_branch' into $base_branch). + │ The content differs from the actual commit on your PR branch. + │ To reproduce locally, update your branch with $base_branch first. + │ + """ + end + catch e + @warn "Error while checking git diff" exception=(e, catch_backtrace()) + end +end + print(""" │ │ To reproduce this CI run locally run the following from the same repository state on julia version $VERSION: @@ -21,6 +49,7 @@ print(""" │ `import Pkg; Pkg.test(;$kwargs_repr)` │ """) +print(git_note) if parse(Bool, ENV["ANNOTATE"]) && v"1.8pre" < VERSION < v"1.9.0-beta3" push!(LOAD_PATH, "@tests-logger-env") # access dependencies