Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ This action supports three tag levels for flexible versioning:
amend: false
commit_prefix: "[AUTO]"
commit_message: "Automatic commit"
user_name: ""
user_email: ""
signing_mode: ""
signing_key: ""
signing_passphrase: ""
Expand All @@ -79,6 +81,8 @@ This action supports three tag levels for flexible versioning:
| `amend` | No | `false` | Whether to make an amendment to the previous commit (`--amend`). Can be combined with `commit_message` to change the commit message. |
| `commit_prefix` | No | `""` | Prefix added to commit message. Combines with `commit_message`. |
| `commit_message` | No | `""` | Commit message to set. Combines with `commit_prefix`. Can be used with `amend` to change the commit message. |
| `user_name` | No | `""` | Git `user.name` used for created commits. Defaults to `${{ github.actor }}` when empty. |
| `user_email` | No | `""` | Git `user.email` used for created commits. Defaults to `${{ github.actor }}@users.noreply.<organization_domain>` when empty. |
| `signing_mode` | No | `""` | Commit signing mode. Supported values are `gpg` and `ssh`. Leave empty to disable signing. |
| `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. |
| `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. |
Expand Down Expand Up @@ -222,6 +226,24 @@ jobs:
commit_message: "Update README"
```

### 👤 Custom commit identity example
Override the git author/committer identity used by the action.

```yaml
- name: Commit and push with custom identity
uses: devops-infra/action-commit-push@v1.4.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: "test(commit-push): custom identity"
user_name: "Release Automation"
user_email: "release-bot@example.com"
```

When `user_name` and `user_email` are empty, the action defaults to:

- `user.name = ${{ github.actor }}`
- `user.email = ${{ github.actor }}@users.noreply.<organization_domain>`

## 🔏 Commit Signing

This action can sign generated commits by configuring repository-local git signing settings at runtime.
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ inputs:
description: Commit message to set
required: false
default: ""
user_name:
description: Git user.name to use for created commits. Defaults to GITHUB_ACTOR when empty.
required: false
default: ""
user_email:
description: Git user.email to use for created commits. Defaults to GITHUB_ACTOR@users.noreply.<organization_domain> when empty.
required: false
default: ""
signing_mode:
description: Commit signing mode. Supported values are gpg and ssh.
required: false
Expand Down
10 changes: 8 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ echo " add_timestamp: ${INPUT_ADD_TIMESTAMP}"
echo " amend: ${INPUT_AMEND}"
echo " commit_prefix: ${INPUT_COMMIT_PREFIX}"
echo " commit_message: ${INPUT_COMMIT_MESSAGE}"
echo " user_name: ${INPUT_USER_NAME}"
echo " user_email: ${INPUT_USER_EMAIL}"
echo " signing_mode: ${INPUT_SIGNING_MODE}"
echo " force: ${INPUT_FORCE}"
echo " force_with_lease: ${INPUT_FORCE_WITH_LEASE}"
Expand Down Expand Up @@ -242,8 +244,12 @@ echo "[INFO] Using repository path: ${REPO_DIR}"

# Set git credentials
git -C "${REPO_DIR}" remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${INPUT_ORGANIZATION_DOMAIN}/${GITHUB_REPOSITORY}"
git -C "${REPO_DIR}" config user.name "${GITHUB_ACTOR}"
git -C "${REPO_DIR}" config user.email "${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}"
git -C "${REPO_DIR}" config user.name "${INPUT_USER_NAME:-${GITHUB_ACTOR}}"
git -C "${REPO_DIR}" config user.email "${INPUT_USER_EMAIL:-${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}}"
export GIT_AUTHOR_NAME="${INPUT_USER_NAME:-${GITHUB_ACTOR}}"
export GIT_AUTHOR_EMAIL="${INPUT_USER_EMAIL:-${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}}"
export GIT_COMMITTER_NAME="${INPUT_USER_NAME:-${GITHUB_ACTOR}}"
export GIT_COMMITTER_EMAIL="${INPUT_USER_EMAIL:-${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}}"
setup_commit_signing

cd "${REPO_DIR}"
Expand Down
36 changes: 36 additions & 0 deletions tests/docker/local-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,42 @@ commandTests:
git -C /tmp/ws config gpg.format ssh
git -C /tmp/ws config gpg.ssh.allowedSignersFile /tmp/allowed_signers
git -C /tmp/ws verify-commit HEAD

- name: Entrypoint overrides commit identity
command: bash
args:
- -lc
- |
set -euo pipefail
rm -rf /tmp/ws /tmp/remote.git /tmp/github_output.txt
mkdir -p /tmp/ws
git init /tmp/ws
git -C /tmp/ws config user.name test
git -C /tmp/ws config user.email test@example.com
touch /tmp/ws/.keep
git -C /tmp/ws add .
git -C /tmp/ws commit -m init
git init --bare /tmp/remote.git
git -C /tmp/ws remote add origin /tmp/remote.git
echo "identity override" > /tmp/ws/e2e-identity.txt
export GITHUB_WORKSPACE=/tmp/ws
export GITHUB_ACTOR=tester
export GITHUB_REPOSITORY=owner/repo
export GITHUB_OUTPUT=/tmp/github_output.txt
export GITHUB_TOKEN=fake
export INPUT_ORGANIZATION_DOMAIN=github.com
export INPUT_REPOSITORY_PATH=.
export INPUT_AMEND=false
export INPUT_ALLOW_EMPTY_COMMIT=false
export INPUT_TARGET_BRANCH=''
export INPUT_COMMIT_MESSAGE='identity override commit'
export INPUT_USER_NAME='Release Automation'
export INPUT_USER_EMAIL='release-bot@example.com'
/entrypoint.sh || true
test "$(git -C /tmp/ws log -1 --format=%an)" = "Release Automation"
test "$(git -C /tmp/ws log -1 --format=%ae)" = "release-bot@example.com"
test "$(git -C /tmp/ws log -1 --format=%cn)" = "Release Automation"
test "$(git -C /tmp/ws log -1 --format=%ce)" = "release-bot@example.com"
fileExistenceTests:
- name: entrypoint exists
path: /entrypoint.sh
Expand Down
Loading