Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom author #26

Closed
Closed
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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.
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.

Expand All @@ -19,6 +19,11 @@ Add the following step at the end of your job.
with:
commit_message: Apply automatic changes
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
commit_options: '--no-verify --signoff'
Expand All @@ -28,9 +33,6 @@ Add the following step at the end of your job.

# Optional repository path
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)
Expand Down
17 changes: 11 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ inputs:
commit_message:
description: Commit message
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:
description: Commit options (eg. --no-verify)
required: false
github_token:
description: Github Token
required: true
branch:
description: Branch name where changes should be pushed too
required: true
Expand All @@ -25,12 +36,6 @@ inputs:
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.commit_message }}
- ${{ inputs.commit_options }}
- ${{ inputs.branch }}
- ${{ inputs.file_pattern }}
- ${{ inputs.repository }}

branding:
icon: 'git-commit'
Expand Down
10 changes: 5 additions & 5 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ _setup_git ( ) {
cat <<- EOF > $HOME/.netrc
machine github.com
login $GITHUB_ACTOR
password $GITHUB_TOKEN
password $INPUT_GITHUB_TOKEN

machine api.github.com
login $GITHUB_ACTOR
password $GITHUB_TOKEN
password $INPUT_GITHUB_TOKEN
EOF
chmod 600 $HOME/.netrc

git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git config --global user.email "$INPUT_COMMIT_AUTHOR_EMAIL"
git config --global user.name "$INPUT_COMMIT_AUTHOR_NAME"
}

_switch_to_branch() {
Expand All @@ -40,7 +40,7 @@ _add_files() {

_local_commit() {
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() {
Expand Down