Skip to content

Commit 022b814

Browse files
feat: allow overriding commit identity
Add optional user_name and user_email inputs so workflows can control git commit identity while preserving the current actor-based defaults. Update local tests and README examples to cover the new override behavior.
1 parent ac01a88 commit 022b814

4 files changed

Lines changed: 70 additions & 2 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ This action supports three tag levels for flexible versioning:
6060
amend: false
6161
commit_prefix: "[AUTO]"
6262
commit_message: "Automatic commit"
63+
user_name: ""
64+
user_email: ""
6365
signing_mode: ""
6466
signing_key: ""
6567
signing_passphrase: ""
@@ -79,6 +81,8 @@ This action supports three tag levels for flexible versioning:
7981
| `amend` | No | `false` | Whether to make an amendment to the previous commit (`--amend`). Can be combined with `commit_message` to change the commit message. |
8082
| `commit_prefix` | No | `""` | Prefix added to commit message. Combines with `commit_message`. |
8183
| `commit_message` | No | `""` | Commit message to set. Combines with `commit_prefix`. Can be used with `amend` to change the commit message. |
84+
| `user_name` | No | `""` | Git `user.name` used for created commits. Defaults to `${{ github.actor }}` when empty. |
85+
| `user_email` | No | `""` | Git `user.email` used for created commits. Defaults to `${{ github.actor }}@users.noreply.<organization_domain>` when empty. |
8286
| `signing_mode` | No | `""` | Commit signing mode. Supported values are `gpg` and `ssh`. Leave empty to disable signing. |
8387
| `signing_key` | No | `""` | Signing key material. For `gpg`, provide an ASCII-armored private key export. For `ssh`, provide a private key in OpenSSH or PEM format. |
8488
| `signing_passphrase` | No | `""` | Optional passphrase for the signing key. Passphrase-protected GPG keys are supported. Encrypted SSH signing keys are rejected in the current runtime. |
@@ -222,6 +226,24 @@ jobs:
222226
commit_message: "Update README"
223227
```
224228

229+
### 👤 Custom commit identity example
230+
Override the git author/committer identity used by the action.
231+
232+
```yaml
233+
- name: Commit and push with custom identity
234+
uses: devops-infra/action-commit-push@v1.4.0
235+
with:
236+
github_token: ${{ secrets.GITHUB_TOKEN }}
237+
commit_message: "test(commit-push): custom identity"
238+
user_name: "Release Automation"
239+
user_email: "release-bot@example.com"
240+
```
241+
242+
When `user_name` and `user_email` are empty, the action defaults to:
243+
244+
- `user.name = ${{ github.actor }}`
245+
- `user.email = ${{ github.actor }}@users.noreply.<organization_domain>`
246+
225247
## 🔏 Commit Signing
226248

227249
This action can sign generated commits by configuring repository-local git signing settings at runtime.

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ inputs:
2222
description: Commit message to set
2323
required: false
2424
default: ""
25+
user_name:
26+
description: Git user.name to use for created commits. Defaults to GITHUB_ACTOR when empty.
27+
required: false
28+
default: ""
29+
user_email:
30+
description: Git user.email to use for created commits. Defaults to GITHUB_ACTOR@users.noreply.<organization_domain> when empty.
31+
required: false
32+
default: ""
2533
signing_mode:
2634
description: Commit signing mode. Supported values are gpg and ssh.
2735
required: false

entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ echo " add_timestamp: ${INPUT_ADD_TIMESTAMP}"
1010
echo " amend: ${INPUT_AMEND}"
1111
echo " commit_prefix: ${INPUT_COMMIT_PREFIX}"
1212
echo " commit_message: ${INPUT_COMMIT_MESSAGE}"
13+
echo " user_name: ${INPUT_USER_NAME}"
14+
echo " user_email: ${INPUT_USER_EMAIL}"
1315
echo " signing_mode: ${INPUT_SIGNING_MODE}"
1416
echo " force: ${INPUT_FORCE}"
1517
echo " force_with_lease: ${INPUT_FORCE_WITH_LEASE}"
@@ -242,8 +244,8 @@ echo "[INFO] Using repository path: ${REPO_DIR}"
242244

243245
# Set git credentials
244246
git -C "${REPO_DIR}" remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${INPUT_ORGANIZATION_DOMAIN}/${GITHUB_REPOSITORY}"
245-
git -C "${REPO_DIR}" config user.name "${GITHUB_ACTOR}"
246-
git -C "${REPO_DIR}" config user.email "${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}"
247+
git -C "${REPO_DIR}" config user.name "${INPUT_USER_NAME:-${GITHUB_ACTOR}}"
248+
git -C "${REPO_DIR}" config user.email "${INPUT_USER_EMAIL:-${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}}"
247249
setup_commit_signing
248250

249251
cd "${REPO_DIR}"

tests/docker/local-image.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,42 @@ commandTests:
134134
git -C /tmp/ws config gpg.format ssh
135135
git -C /tmp/ws config gpg.ssh.allowedSignersFile /tmp/allowed_signers
136136
git -C /tmp/ws verify-commit HEAD
137+
138+
- name: Entrypoint overrides commit identity
139+
command: bash
140+
args:
141+
- -lc
142+
- |
143+
set -euo pipefail
144+
rm -rf /tmp/ws /tmp/remote.git /tmp/github_output.txt
145+
mkdir -p /tmp/ws
146+
git init /tmp/ws
147+
git -C /tmp/ws config user.name test
148+
git -C /tmp/ws config user.email test@example.com
149+
touch /tmp/ws/.keep
150+
git -C /tmp/ws add .
151+
git -C /tmp/ws commit -m init
152+
git init --bare /tmp/remote.git
153+
git -C /tmp/ws remote add origin /tmp/remote.git
154+
echo "identity override" > /tmp/ws/e2e-identity.txt
155+
GITHUB_WORKSPACE=/tmp/ws \
156+
GITHUB_ACTOR=tester \
157+
GITHUB_REPOSITORY=owner/repo \
158+
GITHUB_OUTPUT=/tmp/github_output.txt \
159+
GITHUB_TOKEN=fake \
160+
INPUT_ORGANIZATION_DOMAIN=github.com \
161+
INPUT_REPOSITORY_PATH=. \
162+
INPUT_AMEND=false \
163+
INPUT_ALLOW_EMPTY_COMMIT=false \
164+
INPUT_TARGET_BRANCH='' \
165+
INPUT_COMMIT_MESSAGE='identity override commit' \
166+
INPUT_USER_NAME='Release Automation' \
167+
INPUT_USER_EMAIL='release-bot@example.com' \
168+
/entrypoint.sh
169+
test "$(git -C /tmp/ws log -1 --format=%an)" = "Release Automation"
170+
test "$(git -C /tmp/ws log -1 --format=%ae)" = "release-bot@example.com"
171+
test "$(git -C /tmp/ws log -1 --format=%cn)" = "Release Automation"
172+
test "$(git -C /tmp/ws log -1 --format=%ce)" = "release-bot@example.com"
137173
fileExistenceTests:
138174
- name: entrypoint exists
139175
path: /entrypoint.sh

0 commit comments

Comments
 (0)