Skip to content

Commit 657dcb0

Browse files
Merge pull request #40 from stefanzweifel/v3
Release: v3.0.0
2 parents 99f6ce7 + 1d39bb6 commit 657dcb0

File tree

4 files changed

+60
-53
lines changed

4 files changed

+60
-53
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.5.0...HEAD)
88

9-
> TBD
9+
### Added
10+
- Add `commit_user_name`, `commit_user_email` and `commit_author` input options for full customzation on how the commit is being created [#39](https://github.com/stefanzweifel/git-auto-commit-action/pull/39)
11+
12+
### Changed
13+
- Make the `branch` input option optional [#41](https://github.com/stefanzweifel/git-auto-commit-action/pull/41)
14+
15+
### Removed
16+
- Remove the need of a GITHUB_TOKEN. Users now have to use `actions/checkout@v2` or higher [#36](https://github.com/stefanzweifel/git-auto-commit-action/pull/36)
17+
1018

1119
## [v2.5.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.4.0...v2.5.0) - 2019-12-18
1220

README.md

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
# git-auto-commit-action
22

3-
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the Commit back to GitHub.
4-
The Committer is "GitHub Actions <actions@github.com>" and the Author of the Commit is "Your GitHub Username <github_username@users.noreply.github.com>.
3+
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the commit back to GitHub.
4+
The default committer is "GitHub Actions <actions@github.com>" and the default author of the commit is "Your GitHub Username <github_username@users.noreply.github.com>".
55

6-
If no changes are available, the Actions does nothing.
6+
If no changes are detected, the Action does nothing.
77

88
This Action has been inspired and adapted from the [auto-commit](https://github.com/cds-snc/github-actions/tree/master/auto-commit
99
)-Action of the Canadian Digital Service and this [commit](https://github.com/elstudio/actions-js-build/blob/41d604d6e73d632e22eac40df8cc69b5added04b/commit/entrypoint.sh)-Action by Eric Johnson.
1010

11-
*This action currently can't be used in conjunction with pull requests of forks. See [issue #25](https://github.com/stefanzweifel/git-auto-commit-action/issues/25) for more information.*
11+
*This Action currently can't be used in conjunction with pull requests of forks. See [issue #25](https://github.com/stefanzweifel/git-auto-commit-action/issues/25) for more information.*
1212

1313
## Usage
1414

15+
**Note:** This Action requires that you use `action/checkout@v2` or above to checkout your repository.
16+
1517
Add the following step at the end of your job.
1618

1719
```yaml
18-
- uses: stefanzweifel/git-auto-commit-action@v2.5.0
20+
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
1921
with:
2022
commit_message: Apply automatic changes
23+
24+
# Optional name of the branch the commit should be pushed to
25+
# Required if Action is used in Workflow listening to the `pull_request` event
2126
branch: ${{ github.head_ref }}
2227

2328
# Optional git params
@@ -26,15 +31,15 @@ Add the following step at the end of your job.
2631
# Optional glob pattern of files which should be added to the commit
2732
file_pattern: src/\*.js
2833

29-
# Optional repository path
34+
# Optional local file path to the repository
3035
repository: .
3136

32-
env:
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
# Optional commit user and author settings
38+
commit_user_name: My GitHub Actions Bot
39+
commit_user_email: my-github-actions-bot@example.org
40+
commit_author: Author <actions@gitub.com>
3441
```
3542
36-
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 a Workflow run. (See [the documentation](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token) for details)
37-
3843
The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!
3944
4045
It is recommended to use this Action in Workflows which listen to the `pull_request` event. If you want to use the Action on other events, you have to hardcode the value for `branch` as `github.head_ref` is only available in Pull Requests.
@@ -46,9 +51,6 @@ The most common use case for this, is when you're running a Linter or Code-Style
4651

4752
In this example I'm running `php-cs-fixer` in a PHP project.
4853

49-
50-
### Example with `actions/checkout@v2`
51-
5254
```yaml
5355
name: php-cs-fixer
5456
@@ -66,50 +68,40 @@ jobs:
6668
- name: Run php-cs-fixer
6769
uses: docker://oskarstark/php-cs-fixer-ga
6870
69-
- uses: stefanzweifel/git-auto-commit-action@v2.5.0
71+
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
7072
with:
7173
commit_message: Apply php-cs-fixer changes
7274
branch: ${{ github.head_ref }}
73-
env:
74-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75-
7675
```
7776

78-
### Example with `actions/checkout@v1`
79-
8077
```yaml
8178
name: php-cs-fixer
8279
83-
on:
84-
pull_request:
80+
on: push
8581
8682
jobs:
8783
php-cs-fixer:
8884
runs-on: ubuntu-latest
8985
9086
steps:
91-
- uses: actions/checkout@v1
92-
with:
93-
fetch-depth: 1
87+
- uses: actions/checkout@v2
9488
9589
- name: Run php-cs-fixer
9690
uses: docker://oskarstark/php-cs-fixer-ga
9791
98-
- name: Commit changed files
99-
uses: stefanzweifel/git-auto-commit-action@v2.5.0
92+
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
10093
with:
10194
commit_message: Apply php-cs-fixer changes
102-
branch: ${{ github.head_ref }}
103-
file_pattern: src/\*.php
104-
env:
105-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106-
10795
```
10896

10997
### Inputs
11098

11199
Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml) for a full list of supported inputs.
112100

101+
## Troubleshooting
102+
103+
- If your Workflow can't push the commit to the repository because of authentication issues, please update your Workflow configuration and usage of [`ations/checkout`](https://github.com/actions/checkout#usage). (Updating the `token` value with a Personal Access Token should fix your issues)
104+
113105
## Known Issues
114106

115107
- GitHub currently prohibits Actions like this to push changes from a fork to the upstream repository. See [issue #25](https://github.com/stefanzweifel/git-auto-commit-action/issues/25) for more information.

action.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,33 @@ inputs:
77
commit_message:
88
description: Commit message
99
required: true
10+
branch:
11+
description: Git branch name, where changes should be pushed too. Required if Action is used on the `pull_request` event
12+
required: false
13+
default: ''
1014
commit_options:
1115
description: Commit options (eg. --no-verify)
1216
required: false
13-
branch:
14-
description: Branch name where changes should be pushed too
15-
required: true
1617
file_pattern:
17-
description: File pattern used for "git add"
18+
description: File pattern used for `git add`. For example `src/\*.js`
1819
required: false
1920
default: '.'
2021
repository:
21-
description: Path to git repository
22+
description: Local file path to the git repository. Defaults to the current directory (`.`)
2223
required: false
2324
default: '.'
25+
commit_user_name:
26+
description: Name used for the commit user
27+
required: false
28+
default: GitHub Actions
29+
commit_user_email:
30+
description: Email address used for the commit user
31+
required: false
32+
default: actions@github.com
33+
commit_author:
34+
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
35+
required: false
36+
default: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
2437

2538
runs:
2639
using: 'docker'

entrypoint.sh

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,10 @@ _git_is_dirty() {
3131
[[ -n "$(git status -s)" ]]
3232
}
3333

34-
# Set up .netrc file with GitHub credentials
34+
# Set up git user configuration
3535
_setup_git ( ) {
36-
cat <<- EOF > $HOME/.netrc
37-
machine github.com
38-
login $GITHUB_ACTOR
39-
password $GITHUB_TOKEN
40-
41-
machine api.github.com
42-
login $GITHUB_ACTOR
43-
password $GITHUB_TOKEN
44-
EOF
45-
chmod 600 $HOME/.netrc
46-
47-
git config --global user.email "actions@github.com"
48-
git config --global user.name "GitHub Actions"
36+
git config --global user.name "$INPUT_COMMIT_USER_NAME"
37+
git config --global user.email "$INPUT_COMMIT_USER_EMAIL"
4938
}
5039

5140
_switch_to_branch() {
@@ -62,11 +51,16 @@ _add_files() {
6251

6352
_local_commit() {
6453
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"
65-
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
54+
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
6655
}
6756

6857
_push_to_github() {
69-
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
58+
if [ -z "$INPUT_BRANCH" ]
59+
then
60+
git push origin
61+
else
62+
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
63+
fi
7064
}
7165

7266
_main

0 commit comments

Comments
 (0)