Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4ab94c0
Remove creation of .netrc file
stefanzweifel Jan 13, 2020
35440b9
Update README
stefanzweifel Feb 4, 2020
b21b1ab
Update Comment
stefanzweifel Feb 4, 2020
959e7d4
Update README
stefanzweifel Feb 4, 2020
ae384f9
Update Changelog
stefanzweifel Feb 4, 2020
d47024e
Add commit_user_name and commit_user_email inputs
stefanzweifel Feb 4, 2020
0822a9b
Add commit_author input option
stefanzweifel Feb 4, 2020
3c60dc1
Update README
stefanzweifel Feb 4, 2020
81fa501
Merge pull request #36 from stefanzweifel/refactor/remove-git-setup
stefanzweifel Feb 5, 2020
0a5fd7e
Merge branch 'v3' into feature/commiter-options
stefanzweifel Feb 5, 2020
5432544
Update Docs
stefanzweifel Feb 5, 2020
3185f2b
Update README
stefanzweifel Feb 5, 2020
a06032e
Update Changelog
stefanzweifel Feb 5, 2020
098f1a8
Merge pull request #39 from stefanzweifel/feature/commiter-options
stefanzweifel Feb 5, 2020
b197c5f
Set default value for branch
stefanzweifel Feb 5, 2020
5df30c8
Update how commit is pushed
stefanzweifel Feb 5, 2020
e20b39e
Remove branch default value
stefanzweifel Feb 5, 2020
5ab45a4
WIP
stefanzweifel Feb 5, 2020
0884c39
WIP
stefanzweifel Feb 5, 2020
5a4e81c
WIP
stefanzweifel Feb 5, 2020
af7b14b
WIP
stefanzweifel Feb 5, 2020
f0354eb
WIP
stefanzweifel Feb 5, 2020
42e5be9
WIP
stefanzweifel Feb 5, 2020
13e2810
Update entrypoint.sh
stefanzweifel Feb 6, 2020
3359269
Update Changelog
stefanzweifel Feb 6, 2020
864c975
Update README
stefanzweifel Feb 6, 2020
1d39bb6
Merge pull request #41 from stefanzweifel/feature/make-branch-optional
stefanzweifel Feb 6, 2020
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: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

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

> TBD
### Added
- 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)

### Changed
- Make the `branch` input option optional [#41](https://github.com/stefanzweifel/git-auto-commit-action/pull/41)

### Removed
- 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)


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

Expand Down
54 changes: 23 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
# 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>.
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the commit back to GitHub.
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>".

If no changes are available, the Actions does nothing.
If no changes are detected, the Action does nothing.

This Action has been inspired and adapted from the [auto-commit](https://github.com/cds-snc/github-actions/tree/master/auto-commit
)-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.

*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.*
*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.*

## Usage

**Note:** This Action requires that you use `action/checkout@v2` or above to checkout your repository.

Add the following step at the end of your job.

```yaml
- uses: stefanzweifel/git-auto-commit-action@v2.5.0
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
with:
commit_message: Apply automatic changes

# Optional name of the branch the commit should be pushed to
# Required if Action is used in Workflow listening to the `pull_request` event
branch: ${{ github.head_ref }}

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

# Optional repository path
# Optional local file path to the repository
repository: .

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Optional commit user and author settings
commit_user_name: My GitHub Actions Bot
commit_user_email: my-github-actions-bot@example.org
commit_author: Author <actions@gitub.com>
```

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)

The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!

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.
Expand All @@ -46,9 +51,6 @@ The most common use case for this, is when you're running a Linter or Code-Style

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


### Example with `actions/checkout@v2`

```yaml
name: php-cs-fixer

Expand All @@ -66,50 +68,40 @@ jobs:
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga

- uses: stefanzweifel/git-auto-commit-action@v2.5.0
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
with:
commit_message: Apply php-cs-fixer changes
branch: ${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

```

### Example with `actions/checkout@v1`

```yaml
name: php-cs-fixer

on:
pull_request:
on: push

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/checkout@v2

- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga

- name: Commit changed files
uses: stefanzweifel/git-auto-commit-action@v2.5.0
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
with:
commit_message: Apply php-cs-fixer changes
branch: ${{ github.head_ref }}
file_pattern: src/\*.php
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

```

### Inputs

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

## Troubleshooting

- 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)

## Known Issues

- 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.
Expand Down
23 changes: 18 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,33 @@ inputs:
commit_message:
description: Commit message
required: true
branch:
description: Git branch name, where changes should be pushed too. Required if Action is used on the `pull_request` event
required: false
default: ''
commit_options:
description: Commit options (eg. --no-verify)
required: false
branch:
description: Branch name where changes should be pushed too
required: true
file_pattern:
description: File pattern used for "git add"
description: File pattern used for `git add`. For example `src/\*.js`
required: false
default: '.'
repository:
description: Path to git repository
description: Local file path to the git repository. Defaults to the current directory (`.`)
required: false
default: '.'
commit_user_name:
description: Name used for the commit user
required: false
default: GitHub Actions
commit_user_email:
description: Email address used for the commit user
required: false
default: actions@github.com
commit_author:
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
required: false
default: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>

runs:
using: 'docker'
Expand Down
26 changes: 10 additions & 16 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,10 @@ _git_is_dirty() {
[[ -n "$(git status -s)" ]]
}

# Set up .netrc file with GitHub credentials
# Set up git user configuration
_setup_git ( ) {
cat <<- EOF > $HOME/.netrc
machine github.com
login $GITHUB_ACTOR
password $GITHUB_TOKEN

machine api.github.com
login $GITHUB_ACTOR
password $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.name "$INPUT_COMMIT_USER_NAME"
git config --global user.email "$INPUT_COMMIT_USER_EMAIL"
}

_switch_to_branch() {
Expand All @@ -62,11 +51,16 @@ _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" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
}

_push_to_github() {
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
if [ -z "$INPUT_BRANCH" ]
then
git push origin
else
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
fi
}

_main