Skip to content

Commit

Permalink
Support setting GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL
Browse files Browse the repository at this point in the history
Our autobump workflow sets the author and committer to the user who
triggered the workflow, defaulting to @BrewTestBot for scheduled runs.

This can be confusing for maintainers when GitHub shows up as
"Unverified" because the commit is signed with @BrewTestBot's key.[^1]

Let's fix that by configuring our autobump workflow to always commit as
@BrewTestBot, so that the committer matches the GPG signature. To do
that, we need to add support for setting `GIT_COMMITTER_NAME` and
`GIT_COMMITTER_EMAIL`.

[^1]: See, for example, Homebrew/homebrew-core#197234.
  • Loading branch information
carlocab committed Nov 11, 2024
1 parent 284035d commit 1fbe436
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,19 @@ module EnvConfig
HOMEBREW_GITHUB_PACKAGES_USER: {
description: "Use this username when accessing the GitHub Packages Registry (where bottles may be stored).",
},
HOMEBREW_GIT_COMMITTER_EMAIL: {
description: "Set the Git committer email to this value.",
},
HOMEBREW_GIT_COMMITTER_NAME: {
description: "Set the Git committer name to this value.",
},
HOMEBREW_GIT_EMAIL: {
description: "Set the Git author and committer email to this value.",
description: "Set the Git author name and, if `HOMEBREW_GIT_COMMITTER_EMAIL` is unset, committer email to " \
"this value.",
},
HOMEBREW_GIT_NAME: {
description: "Set the Git author and committer name to this value.",
description: "Set the Git author name and, if `HOMEBREW_GIT_COMMITTER_NAME` is unset, committer name to " \
"this value.",
},
HOMEBREW_GIT_PATH: {
description: "Linux only: Set this value to a new enough `git` executable for Homebrew to use.",
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions Library/Homebrew/utils/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,19 @@ def self.set_name_email!(author: true, committer: true)
ENV["GIT_COMMITTER_NAME"] = Homebrew::EnvConfig.git_name if committer
end

return unless Homebrew::EnvConfig.git_email
if Homebrew::EnvConfig.git_committer_name && committer
ENV["GIT_COMMITTER_NAME"] = Homebrew::EnvConfig.git_committer_name
end

if Homebrew::EnvConfig.git_email
ENV["GIT_AUTHOR_EMAIL"] = Homebrew::EnvConfig.git_email if author
ENV["GIT_COMMITTER_EMAIL"] = Homebrew::EnvConfig.git_email if committer
end

return unless committer
return unless Homebrew::EnvConfig.git_committer_email

ENV["GIT_AUTHOR_EMAIL"] = Homebrew::EnvConfig.git_email if author
ENV["GIT_COMMITTER_EMAIL"] = Homebrew::EnvConfig.git_email if committer
ENV["GIT_COMMITTER_EMAIL"] = Homebrew::EnvConfig.git_committer_email

Check warning on line 134 in Library/Homebrew/utils/git.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/git.rb#L134

Added line #L134 was not covered by tests
end

def self.setup_gpg!
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/utils/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ def self.create_bump_pr(info, args:)

safe_system "git", "add", *changed_files
safe_system "git", "checkout", "--no-track", "-b", branch, "#{remote}/#{remote_branch}" unless args.commit?
Utils::Git.set_name_email!

Check warning on line 759 in Library/Homebrew/utils/github.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/github.rb#L759

Added line #L759 was not covered by tests
safe_system "git", "commit", "--no-edit", "--verbose",
"--message=#{commit_message}",
"--", *changed_files
Expand Down

0 comments on commit 1fbe436

Please sign in to comment.