Compare commits

...

38 Commits
v2 ... v3

Author SHA1 Message Date
Stefan Zweifel
8563bc2c47 Tag v3.0.0 2020-02-06 21:15:35 +01:00
Stefan Zweifel
657dcb0873 Merge pull request #40 from stefanzweifel/v3
Release: v3.0.0
2020-02-06 21:14:31 +01:00
Stefan Zweifel
1d39bb676c Merge pull request #41 from stefanzweifel/feature/make-branch-optional
Make branch option optional
2020-02-06 20:51:13 +01:00
Stefan Zweifel
864c975b87 Update README 2020-02-06 20:49:03 +01:00
Stefan Zweifel
33592697c4 Update Changelog 2020-02-06 20:43:04 +01:00
Stefan Zweifel
13e281008a Update entrypoint.sh 2020-02-06 17:51:55 +01:00
Stefan Zweifel
42e5be9ebb WIP 2020-02-05 21:39:14 +01:00
Stefan Zweifel
f0354eba45 WIP 2020-02-05 21:36:48 +01:00
Stefan Zweifel
af7b14b2cf WIP 2020-02-05 21:32:57 +01:00
Stefan Zweifel
5a4e81ccd7 WIP 2020-02-05 21:31:46 +01:00
Stefan Zweifel
0884c39e7e WIP 2020-02-05 21:28:18 +01:00
Stefan Zweifel
5ab45a4eef WIP 2020-02-05 21:26:30 +01:00
Stefan Zweifel
e20b39e8ed Remove branch default value 2020-02-05 21:24:36 +01:00
Stefan Zweifel
5df30c89b8 Update how commit is pushed 2020-02-05 21:22:54 +01:00
Stefan Zweifel
b197c5ff8c Set default value for branch 2020-02-05 21:12:20 +01:00
Stefan Zweifel
098f1a8051 Merge pull request #39 from stefanzweifel/feature/commiter-options
Add Options to change Commit User Name and Email and Author
2020-02-05 20:38:20 +01:00
Stefan Zweifel
a06032e34f Update Changelog 2020-02-05 20:36:12 +01:00
Stefan Zweifel
3185f2bd2a Update README 2020-02-05 20:27:14 +01:00
Stefan Zweifel
5432544bdb Update Docs 2020-02-05 20:24:25 +01:00
Stefan Zweifel
0a5fd7e510 Merge branch 'v3' into feature/commiter-options
# Conflicts:
#	README.md
#	entrypoint.sh
2020-02-05 20:12:29 +01:00
Stefan Zweifel
81fa501ea5 Merge pull request #36 from stefanzweifel/refactor/remove-git-setup
Remove need for GITHUB_TOKEN
2020-02-05 19:52:36 +01:00
Stefan Zweifel
3c60dc19b2 Update README 2020-02-04 21:27:15 +01:00
Stefan Zweifel
0822a9b930 Add commit_author input option 2020-02-04 21:02:40 +01:00
Stefan Zweifel
d47024e59c Add commit_user_name and commit_user_email inputs 2020-02-04 20:14:27 +01:00
Stefan Zweifel
ae384f95d0 Update Changelog 2020-02-04 19:43:08 +01:00
Stefan Zweifel
959e7d4eab Update README 2020-02-04 19:42:37 +01:00
Stefan Zweifel
b21b1abc6d Update Comment 2020-02-04 19:37:58 +01:00
Stefan Zweifel
35440b9386 Update README 2020-02-04 19:37:00 +01:00
Stefan Zweifel
99f6ce74b4 Update README.md 2020-01-14 14:44:34 +01:00
Stefan Zweifel
4ab94c0ec4 Remove creation of .netrc file 2020-01-13 21:23:03 +01:00
Stefan Zweifel
1a9ba81dae Merge pull request #32 from yelizariev/patch-2
delete args as not used
2020-01-11 21:40:52 +01:00
Stefan Zweifel
2043118160 Update Dockerfile 2020-01-11 21:35:29 +01:00
Stefan Zweifel
9879efa581 Merge pull request #34 from yelizariev/refactoring
refactoring: combine merge lib.sh to entrypoint.sh
2020-01-11 21:34:15 +01:00
Stefan Zweifel
3525430c70 Update README 2020-01-11 21:32:17 +01:00
Stefan Zweifel
db25cb8fde Add checkout@v2 example
Closes #33
2020-01-11 21:32:11 +01:00
Ivan Yelizariev
5dd90bb58c refactoring: combine merge lib.sh to entrypoint.sh
If we use "source /lib.sh", bash will point to wrong line in case of an error.
It's confusing on debuggin new features
2020-01-10 13:08:35 +05:00
Ivan Yelizariev
36610a4da0 delete args as not used
closes #31
2020-01-07 12:27:14 +05:00
Stefan Zweifel
26a56d2023 Add note to README about forks and PRs 2020-01-04 17:54:44 +01:00
6 changed files with 135 additions and 95 deletions

View File

@@ -4,10 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.5.0...HEAD)
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v3.0.0...HEAD)
> TBD
## [v3.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.5.0...v3.0.0) - 2020-02-06
### 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
### Added

View File

@@ -11,7 +11,6 @@ LABEL "maintainer"="Stefan Zweifel <hello@stefanzweifel.io>"
RUN apk add git-lfs
COPY lib.sh /lib.sh
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["sh", "/entrypoint.sh"]

View File

@@ -1,21 +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 the [commit](https://github.com/elstudio/actions-js-build/blob/41d604d6e73d632e22eac40df8cc69b5added04b/commit/entrypoint.sh)-Action by Eric Johnson.
)-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.*
## 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
@@ -24,62 +31,81 @@ 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 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)
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.
## Example Usage
This Action will only work, if the job in your workflow changes project files.
This Action will only work, if the job in your Workflow changes project files.
The most common use case for this, is when you're running a Linter or Code-Style fixer on GitHub Actions.
In this example I'm running `php-cs-fixer` in a PHP project.
```yaml
name: php-cs-fixer
on:
pull_request:
paths:
- '**.php'
on: pull_request
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 1
ref: ${{ github.head_ref }}
- 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 }}
```
```yaml
name: php-cs-fixer
on: push
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
with:
commit_message: Apply php-cs-fixer changes
```
### 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.
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags).

View File

@@ -7,30 +7,37 @@ 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'
image: 'Dockerfile'
args:
- ${{ inputs.commit_message }}
- ${{ inputs.commit_options }}
- ${{ inputs.branch }}
- ${{ inputs.file_pattern }}
- ${{ inputs.repository }}
branding:
icon: 'git-commit'

View File

@@ -2,21 +2,65 @@
set -eu
source /lib.sh
_main() {
_switch_to_repository
_switch_to_repository
if _git_is_dirty; then
if _git_is_dirty; then
_setup_git
_setup_git
_switch_to_branch
_switch_to_branch
_add_files
_add_files
_local_commit
_local_commit
_push_to_github
else
echo "Working tree clean. Nothing to commit."
fi
}
_push_to_github
else
echo "Working tree clean. Nothing to commit."
fi
_switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
cd $INPUT_REPOSITORY
}
_git_is_dirty() {
[[ -n "$(git status -s)" ]]
}
# Set up git user configuration
_setup_git ( ) {
git config --global user.name "$INPUT_COMMIT_USER_NAME"
git config --global user.email "$INPUT_COMMIT_USER_EMAIL"
}
_switch_to_branch() {
echo "INPUT_BRANCH value: $INPUT_BRANCH";
# Switch to branch from current Workflow run
git checkout $INPUT_BRANCH
}
_add_files() {
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
git add "${INPUT_FILE_PATTERN}"
}
_local_commit() {
echo "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() {
if [ -z "$INPUT_BRANCH" ]
then
git push origin
else
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
fi
}
_main

48
lib.sh
View File

@@ -1,48 +0,0 @@
#!/bin/bash
_switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
cd $INPUT_REPOSITORY
}
_git_is_dirty() {
[[ -n "$(git status -s)" ]]
}
# Set up .netrc file with GitHub credentials
_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"
}
_switch_to_branch() {
echo "INPUT_BRANCH value: $INPUT_BRANCH";
# Switch to branch from current Workflow run
git checkout $INPUT_BRANCH
}
_add_files() {
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
git add "${INPUT_FILE_PATTERN}"
}
_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"}
}
_push_to_github() {
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
}