allow custom author

This commit is contained in:
Ivan Yelizariev 2020-01-05 18:10:53 +05:00
parent 26a56d2023
commit 48a57dfee8
No known key found for this signature in database
GPG Key ID: B87954F73B65AC8A
3 changed files with 22 additions and 15 deletions

View File

@ -1,7 +1,7 @@
# git-auto-commit-action # git-auto-commit-action
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the Commit back to GitHub. This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the Commit back to GitHub.
The Committer is "GitHub Actions <actions@github.com>" and the Author of the Commit is "Your GitHub Username <github_username@users.noreply.github.com>. Default committer and author is "GitHub Actions <actions@github.com>".
If no changes are available, the Actions does nothing. If no changes are available, the Actions does nothing.
@ -19,6 +19,11 @@ Add the following step at the end of your job.
with: with:
commit_message: Apply automatic changes commit_message: Apply automatic changes
branch: ${{ github.head_ref }} branch: ${{ github.head_ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}
# Optional committer info
commit_author_name: "My Bot"
commit_author_email: "bot@example.com"
# Optional git params # Optional git params
commit_options: '--no-verify --signoff' commit_options: '--no-verify --signoff'
@ -28,9 +33,6 @@ Add the following step at the end of your job.
# Optional repository path # Optional repository path
repository: . repository: .
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
You **do not** have to create a new secret called `GITHUB_TOKEN` in your repository. `GITHUB_TOKEN` is a special token GitHub creates automatically during an Action run. (See [the documentation](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) for details) You **do not** have to create a new secret called `GITHUB_TOKEN` in your repository. `GITHUB_TOKEN` is a special token GitHub creates automatically during an Action run. (See [the documentation](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) for details)

View File

@ -7,9 +7,20 @@ inputs:
commit_message: commit_message:
description: Commit message description: Commit message
required: true required: true
commit_author_email:
description: Author's email
required: true
default: actions@github.com
commit_author_name:
description: Author Name
required: true
default: Github Actions
commit_options: commit_options:
description: Commit options (eg. --no-verify) description: Commit options (eg. --no-verify)
required: false required: false
github_token:
description: Github Token
required: true
branch: branch:
description: Branch name where changes should be pushed too description: Branch name where changes should be pushed too
required: true required: true
@ -25,12 +36,6 @@ inputs:
runs: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'
args:
- ${{ inputs.commit_message }}
- ${{ inputs.commit_options }}
- ${{ inputs.branch }}
- ${{ inputs.file_pattern }}
- ${{ inputs.repository }}
branding: branding:
icon: 'git-commit' icon: 'git-commit'

10
lib.sh
View File

@ -14,16 +14,16 @@ _setup_git ( ) {
cat <<- EOF > $HOME/.netrc cat <<- EOF > $HOME/.netrc
machine github.com machine github.com
login $GITHUB_ACTOR login $GITHUB_ACTOR
password $GITHUB_TOKEN password $INPUT_GITHUB_TOKEN
machine api.github.com machine api.github.com
login $GITHUB_ACTOR login $GITHUB_ACTOR
password $GITHUB_TOKEN password $INPUT_GITHUB_TOKEN
EOF EOF
chmod 600 $HOME/.netrc chmod 600 $HOME/.netrc
git config --global user.email "actions@github.com" git config --global user.email "$INPUT_COMMIT_AUTHOR_EMAIL"
git config --global user.name "GitHub Actions" git config --global user.name "$INPUT_COMMIT_AUTHOR_NAME"
} }
_switch_to_branch() { _switch_to_branch() {
@ -40,7 +40,7 @@ _add_files() {
_local_commit() { _local_commit() {
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}" echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR_NAME <$INPUT_COMMIT_AUTHOR_EMAIL>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
} }
_push_to_github() { _push_to_github() {