Remove setup-git-user in favor of setting fallback only when identity is missing (#688)

* Experiment with skipping setup-git-user more often

* drop setup-git-user

* fix tests
This commit is contained in:
Mateusz Burzyński
2026-07-27 05:02:39 +00:00
committed by GitHub
parent 469993ce57
commit 219ea82e52
10 changed files with 52 additions and 26 deletions
+28 -2
View File
@@ -93,10 +93,35 @@ export class GitHub {
};
}
async setupUser() {
if (this.commitMode === "github-api") {
async ensureGitUser() {
// Check the exact identities that Git would use for commits without
// allowing Git to fall back to auto-detected values like user@hostname.
// This covers explicit GIT_AUTHOR_* / GIT_COMMITTER_* env vars, local
// config, and global config. A partial identity, with only a name or only
// an email, does not pass this check. If either identity is missing,
// configure our default bot user as a fallback.
const authorIdentity = await getExecOutput(
"git",
["-c", "user.useConfigOnly=true", "var", "GIT_AUTHOR_IDENT"],
{
cwd: this.cwd,
ignoreReturnCode: true,
silent: true,
},
);
const committerIdentity = await getExecOutput(
"git",
["-c", "user.useConfigOnly=true", "var", "GIT_COMMITTER_IDENT"],
{
cwd: this.cwd,
ignoreReturnCode: true,
silent: true,
},
);
if (authorIdentity.exitCode === 0 && committerIdentity.exitCode === 0) {
return;
}
core.info("Setting Git user to github-actions[bot]");
await exec("git", ["config", "user.name", `"github-actions[bot]"`], {
cwd: this.cwd,
});
@@ -159,6 +184,7 @@ export class GitHub {
return;
}
if (!(await checkIfClean({ cwd: this.cwd }))) {
await this.ensureGitUser();
await commitAll(message, { cwd: this.cwd });
}
await push(branch, {