mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-08-03 00:56:08 +08:00
Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8563bc2c47 | ||
|
657dcb0873 | ||
|
1d39bb676c | ||
|
864c975b87 | ||
|
33592697c4 | ||
|
13e281008a | ||
|
42e5be9ebb | ||
|
f0354eba45 | ||
|
af7b14b2cf | ||
|
5a4e81ccd7 | ||
|
0884c39e7e | ||
|
5ab45a4eef | ||
|
e20b39e8ed | ||
|
5df30c89b8 | ||
|
b197c5ff8c | ||
|
098f1a8051 | ||
|
a06032e34f | ||
|
3185f2bd2a | ||
|
5432544bdb | ||
|
0a5fd7e510 | ||
|
81fa501ea5 | ||
|
3c60dc19b2 | ||
|
0822a9b930 | ||
|
d47024e59c | ||
|
ae384f95d0 | ||
|
959e7d4eab | ||
|
b21b1abc6d | ||
|
35440b9386 | ||
|
99f6ce74b4 | ||
|
4ab94c0ec4 | ||
|
1a9ba81dae | ||
|
2043118160 | ||
|
9879efa581 | ||
|
3525430c70 | ||
|
db25cb8fde | ||
|
5dd90bb58c | ||
|
36610a4da0 | ||
|
26a56d2023 | ||
|
6d7a33192e | ||
|
d625ec8b28 | ||
|
e870f94840 | ||
|
4a6ffd0603 | ||
|
dcfe3115ff | ||
|
3f6e990b1e | ||
|
560cf49647 | ||
|
c62363dd62 | ||
|
7c85ce3dee | ||
|
8bb153baaa | ||
|
68035425ff | ||
|
3273c330f8 | ||
|
4280601118 | ||
|
3c148f8a94 | ||
|
d3ceacae7d | ||
|
d338d7dd00 | ||
|
f7e2c0f118 | ||
|
8db04fa14f | ||
|
44a415d3cb | ||
|
af9e1689a5 | ||
|
2b22ba6212 | ||
|
b1b8ae8b5c | ||
|
fb3de05451 | ||
|
284d0b78f0 | ||
|
188fc2bd58 | ||
|
65d8bdf167 | ||
|
40255153c4 |
12
.github/workflows/shellcheck.yml
vendored
Normal file
12
.github/workflows/shellcheck.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
name: Shellcheck
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
shellcheck:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: shellcheck
|
||||||
|
uses: ludeeus/action-shellcheck@0.1.0
|
35
CHANGELOG.md
35
CHANGELOG.md
@@ -4,17 +4,50 @@ 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/)
|
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).
|
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.3.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
|
||||||
|
- Add new `repository`-argument [#22](https://github.com/stefanzweifel/git-auto-commit-action/pull/22)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Extract logic of the Action into methods and into a separate file [#24](https://github.com/stefanzweifel/git-auto-commit-action/pull/24)
|
||||||
|
|
||||||
|
|
||||||
|
## [v2.4.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.3.0...v2.4.0) - 2019-11-30
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Commit untracked files [#19](https://github.com/stefanzweifel/git-auto-commit-action/pull/19) (fixes [#16](https://github.com/stefanzweifel/git-auto-commit-action/issues/16))
|
||||||
|
- Add support for Git-LFS [#21](https://github.com/stefanzweifel/git-auto-commit-action/pull/21) (fixes [#20](https://github.com/stefanzweifel/git-auto-commit-action/issues/20))
|
||||||
|
|
||||||
|
|
||||||
## [v2.3.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.2.0...v2.3.0) - 2019-11-04
|
## [v2.3.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.2.0...v2.3.0) - 2019-11-04
|
||||||
|
|
||||||
|
### Added
|
||||||
- Add a new `commit_option`-argument. Allows users to define additional commit options for the `git-commit` command. [#14](https://github.com/stefanzweifel/git-auto-commit-action/pull/15)
|
- Add a new `commit_option`-argument. Allows users to define additional commit options for the `git-commit` command. [#14](https://github.com/stefanzweifel/git-auto-commit-action/pull/15)
|
||||||
|
|
||||||
|
|
||||||
## [v2.2.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.1.0...v2.2.0) - 2019-10-26
|
## [v2.2.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.1.0...v2.2.0) - 2019-10-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Add new `file_pattern`-argument. Allows users to define which files should be added in the commit. [#13](https://github.com/stefanzweifel/git-auto-commit-action/pull/13)
|
- Add new `file_pattern`-argument. Allows users to define which files should be added in the commit. [#13](https://github.com/stefanzweifel/git-auto-commit-action/pull/13)
|
||||||
|
|
||||||
|
|
||||||
## [v2.1.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.0.0...v2.1.0) - 2019-09-20
|
## [v2.1.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.0.0...v2.1.0) - 2019-09-20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@@ -9,6 +9,8 @@ LABEL "repository"="http://github.com/stefanzweifel/git-auto-commit-action"
|
|||||||
LABEL "homepage"="http://github.com/stefanzweifel/git-auto-commit-action"
|
LABEL "homepage"="http://github.com/stefanzweifel/git-auto-commit-action"
|
||||||
LABEL "maintainer"="Stefan Zweifel <hello@stefanzweifel.io>"
|
LABEL "maintainer"="Stefan Zweifel <hello@stefanzweifel.io>"
|
||||||
|
|
||||||
|
RUN apk add git-lfs
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
||||||
|
76
README.md
76
README.md
@@ -1,21 +1,28 @@
|
|||||||
# 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>.
|
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
|
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
|
## 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.
|
Add the following step at the end of your job.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v2.3.0
|
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
|
||||||
with:
|
with:
|
||||||
commit_message: Apply automatic changes
|
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 }}
|
branch: ${{ github.head_ref }}
|
||||||
|
|
||||||
# Optional git params
|
# Optional git params
|
||||||
@@ -23,11 +30,15 @@ Add the following step at the end of your job.
|
|||||||
|
|
||||||
# Optional glob pattern of files which should be added to the commit
|
# Optional glob pattern of files which should be added to the commit
|
||||||
file_pattern: src/\*.js
|
file_pattern: src/\*.js
|
||||||
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)
|
# Optional local file path to the repository
|
||||||
|
repository: .
|
||||||
|
|
||||||
|
# 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>
|
||||||
|
```
|
||||||
|
|
||||||
The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!
|
The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!
|
||||||
|
|
||||||
@@ -35,46 +46,65 @@ It is recommended to use this Action in Workflows which listen to the `pull_requ
|
|||||||
|
|
||||||
## Example Usage
|
## 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.
|
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.
|
In this example I'm running `php-cs-fixer` in a PHP project.
|
||||||
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: php-cs-fixer
|
name: php-cs-fixer
|
||||||
|
|
||||||
on:
|
on: pull_request
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- '**.php'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
php-cs-fixer:
|
php-cs-fixer:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
ref: ${{ github.head_ref }}
|
||||||
|
|
||||||
- name: Run php-cs-fixer
|
- name: Run php-cs-fixer
|
||||||
uses: docker://oskarstark/php-cs-fixer-ga
|
uses: docker://oskarstark/php-cs-fixer-ga
|
||||||
|
|
||||||
- name: Commit changed files
|
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
|
||||||
uses: stefanzweifel/git-auto-commit-action@v2.3.0
|
|
||||||
with:
|
with:
|
||||||
commit_message: Apply php-cs-fixer changes
|
commit_message: Apply php-cs-fixer changes
|
||||||
branch: ${{ github.head_ref }}
|
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
|
### Inputs
|
||||||
|
|
||||||
Checkout [`actions.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/actions.yml) for a full list of supported 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
|
## Versioning
|
||||||
|
|
||||||
|
34
action.yml
34
action.yml
@@ -7,25 +7,37 @@ inputs:
|
|||||||
commit_message:
|
commit_message:
|
||||||
description: Commit message
|
description: Commit message
|
||||||
required: true
|
required: true
|
||||||
commit_options:
|
|
||||||
description: Commit options
|
|
||||||
required: false
|
|
||||||
branch:
|
branch:
|
||||||
description: Branch where changes should be pushed too
|
description: Git branch name, where changes should be pushed too. Required if Action is used on the `pull_request` event
|
||||||
required: true
|
required: false
|
||||||
|
default: ''
|
||||||
|
commit_options:
|
||||||
|
description: Commit options (eg. --no-verify)
|
||||||
|
required: false
|
||||||
file_pattern:
|
file_pattern:
|
||||||
description: File pattern used for "git add"
|
description: File pattern used for `git add`. For example `src/\*.js`
|
||||||
required: false
|
required: false
|
||||||
default: '.'
|
default: '.'
|
||||||
|
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:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
args:
|
|
||||||
- ${{ inputs.commit_message }}
|
|
||||||
- ${{ inputs.commit_options }}
|
|
||||||
- ${{ inputs.branch }}
|
|
||||||
- ${{ inputs.file_pattern }}
|
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'git-commit'
|
icon: 'git-commit'
|
||||||
|
@@ -1,44 +1,66 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Set up .netrc file with GitHub credentials
|
_main() {
|
||||||
git_setup ( ) {
|
_switch_to_repository
|
||||||
cat <<- EOF > $HOME/.netrc
|
|
||||||
machine github.com
|
|
||||||
login $GITHUB_ACTOR
|
|
||||||
password $GITHUB_TOKEN
|
|
||||||
|
|
||||||
machine api.github.com
|
if _git_is_dirty; then
|
||||||
login $GITHUB_ACTOR
|
|
||||||
password $GITHUB_TOKEN
|
|
||||||
EOF
|
|
||||||
chmod 600 $HOME/.netrc
|
|
||||||
|
|
||||||
git config --global user.email "actions@github.com"
|
_setup_git
|
||||||
git config --global user.name "GitHub Actions"
|
|
||||||
|
_switch_to_branch
|
||||||
|
|
||||||
|
_add_files
|
||||||
|
|
||||||
|
_local_commit
|
||||||
|
|
||||||
|
_push_to_github
|
||||||
|
else
|
||||||
|
echo "Working tree clean. Nothing to commit."
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# This section only runs if there have been file changes
|
|
||||||
echo "Checking for uncommitted changes in the git working tree."
|
|
||||||
if ! git diff --quiet
|
|
||||||
then
|
|
||||||
git_setup
|
|
||||||
|
|
||||||
|
_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";
|
echo "INPUT_BRANCH value: $INPUT_BRANCH";
|
||||||
|
|
||||||
# Switch to branch from current Workflow run
|
# Switch to branch from current Workflow run
|
||||||
git checkout $INPUT_BRANCH
|
git checkout $INPUT_BRANCH
|
||||||
|
}
|
||||||
|
|
||||||
|
_add_files() {
|
||||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
|
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
|
||||||
|
|
||||||
git add "${INPUT_FILE_PATTERN}"
|
git add "${INPUT_FILE_PATTERN}"
|
||||||
|
}
|
||||||
|
|
||||||
|
_local_commit() {
|
||||||
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"
|
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"
|
||||||
|
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR" ${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() {
|
||||||
|
if [ -z "$INPUT_BRANCH" ]
|
||||||
|
then
|
||||||
|
git push origin
|
||||||
|
else
|
||||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
|
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
|
||||||
else
|
fi
|
||||||
echo "Working tree clean. Nothing to commit."
|
}
|
||||||
fi
|
|
||||||
|
_main
|
||||||
|
Reference in New Issue
Block a user