Skip to content

Commit cd4f408

Browse files
feat: implement Git identity resolution for commits in GitHub Actions
1 parent c08a8d8 commit cd4f408

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ The project follows [Semantic Versioning](https://semver.org/) and adheres to th
88

99
- Nothing yet.
1010

11+
## [1.5.0] - 2025-10-10
12+
13+
### Fixed
14+
15+
- Default commit author identity to GitHub Actions metadata so PR creation succeeds without custom Git configuration.
16+
1117
## [1.4.0] - 2025-10-10
1218

1319
### Added

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ permissions:
219219
pull-requests: write
220220
221221
In addition to per-job permissions, the repository (or organization) wide setting under **Settings → Actions → General → Workflow permissions** must grant **Read and write permissions** and enable **“Allow GitHub Actions to create and approve pull requests”**. If that toggle cannot be enabled, provide a classic personal access token with `repo` scope via a secret (for example `PATCH_PR_TOKEN`) and export it as `GITHUB_TOKEN` when running the action.
222+
223+
Commits authored by the action default to the current `GITHUB_ACTOR` (falling back to `github-actions[bot]`). Override this by setting `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL` (and matching `GIT_COMMITTER_*`) in the workflow environment before invoking the action if you need a custom identity.
222224
```
223225

224226
## FAQ

dist/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80188,6 +80188,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8018880188
Object.defineProperty(exports, "__esModule", ({ value: true }));
8018980189
exports.executeAction = executeAction;
8019080190
const promises_1 = __nccwpck_require__(51455);
80191+
const node_process_1 = __importDefault(__nccwpck_require__(1708));
8019180192
const node_path_1 = __importDefault(__nccwpck_require__(76760));
8019280193
const pr_body_1 = __nccwpck_require__(62706);
8019380194
const DEFAULT_IGNORES = ['**/node_modules/**', '**/.git/**', '**/dist/**'];
@@ -80228,6 +80229,19 @@ async function applyVersionUpdates(workspace, groupedMatches, newVersion) {
8022880229
}
8022980230
}
8023080231
}
80232+
function resolveGitIdentity() {
80233+
const actor = (node_process_1.default.env.GITHUB_ACTOR ?? '').trim();
80234+
const envAuthorName = (node_process_1.default.env.GIT_AUTHOR_NAME ?? '').trim();
80235+
const envAuthorEmail = (node_process_1.default.env.GIT_AUTHOR_EMAIL ?? '').trim();
80236+
const name = envAuthorName || actor || 'github-actions[bot]';
80237+
if (envAuthorEmail) {
80238+
return { name, email: envAuthorEmail };
80239+
}
80240+
if (actor) {
80241+
return { name, email: `${actor}@users.noreply.github.com` };
80242+
}
80243+
return { name, email: '41898282+github-actions[bot]@users.noreply.github.com' };
80244+
}
8023180245
function determineMissingRunners(availability) {
8023280246
if (!availability) {
8023380247
return ['linux', 'mac', 'win'];
@@ -80420,11 +80434,14 @@ async function executeAction(options, dependencies) {
8042080434
}
8042180435
try {
8042280436
await applyVersionUpdates(workspace, groupedMatches, latestVersion);
80437+
const { name: authorName, email: authorEmail } = resolveGitIdentity();
8042380438
const commitResult = await dependencies.createBranchAndCommit({
8042480439
repoPath: workspace,
8042580440
track,
8042680441
files: filesChanged,
8042780442
commitMessage: `chore: bump python ${track} to ${latestVersion}`,
80443+
authorName,
80444+
authorEmail,
8042880445
});
8042980446
if (!commitResult.commitCreated) {
8043080447
return {

src/action-execution.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { readFile, writeFile } from 'node:fs/promises';
2+
import process from 'node:process';
23
import path from 'node:path';
34
import {
45
determineSingleTrack,
@@ -139,6 +140,24 @@ async function applyVersionUpdates(
139140
}
140141
}
141142

143+
function resolveGitIdentity(): { name: string; email: string } {
144+
const actor = (process.env.GITHUB_ACTOR ?? '').trim();
145+
const envAuthorName = (process.env.GIT_AUTHOR_NAME ?? '').trim();
146+
const envAuthorEmail = (process.env.GIT_AUTHOR_EMAIL ?? '').trim();
147+
148+
const name = envAuthorName || actor || 'github-actions[bot]';
149+
150+
if (envAuthorEmail) {
151+
return { name, email: envAuthorEmail };
152+
}
153+
154+
if (actor) {
155+
return { name, email: `${actor}@users.noreply.github.com` };
156+
}
157+
158+
return { name, email: '41898282+github-actions[bot]@users.noreply.github.com' };
159+
}
160+
142161
function determineMissingRunners(
143162
availability: Awaited<ReturnType<typeof fetchRunnerAvailability>>,
144163
): string[] {
@@ -391,11 +410,15 @@ export async function executeAction(
391410
try {
392411
await applyVersionUpdates(workspace, groupedMatches, latestVersion);
393412

413+
const { name: authorName, email: authorEmail } = resolveGitIdentity();
414+
394415
const commitResult = await dependencies.createBranchAndCommit({
395416
repoPath: workspace,
396417
track,
397418
files: filesChanged,
398419
commitMessage: `chore: bump python ${track} to ${latestVersion}`,
420+
authorName,
421+
authorEmail,
399422
});
400423

401424
if (!commitResult.commitCreated) {

0 commit comments

Comments
 (0)