mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-07-30 22:46:13 +08:00
Compare commits
127 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1f4914882d | ||
|
b5320678c1 | ||
|
01ffd8c6f6 | ||
|
5222c758dd | ||
|
bbcb72b1e9 | ||
|
142eb9509a | ||
|
0233fee872 | ||
|
808edcd96b | ||
|
1b1d53f462 | ||
|
ee93725e66 | ||
|
36304edfd2 | ||
|
ff97e958aa | ||
|
90282bf5e2 | ||
|
c9eb2132b2 | ||
|
c8ded2885e | ||
|
f120678ed1 | ||
|
4183594932 | ||
|
49e28abb3f | ||
|
4ebfe28af0 | ||
|
984a26d893 | ||
|
3804c79d2e | ||
|
69a12041a1 | ||
|
91b7d20ead | ||
|
044b6b777c | ||
|
9aab2f8a5c | ||
|
0280d2ccee | ||
|
b0b5ed34dd | ||
|
ae38c94802 | ||
|
3aae7bb63f | ||
|
c180c695f2 | ||
|
c1a70c9013 | ||
|
02c4f2cf78 | ||
|
3c687aa8ba | ||
|
a69eabaead | ||
|
9f2c45c9eb | ||
|
5bf88dc2fd | ||
|
fd2aab7c5b | ||
|
f342c95aa2 | ||
|
1157d7bbe9 | ||
|
58b79711d8 | ||
|
f5f76eb1f4 | ||
|
5513d18f64 | ||
|
6ef5688e81 | ||
|
e02ededdeb | ||
|
2f5e73df85 | ||
|
cc16347545 | ||
|
1ee136f439 | ||
|
7fdc480651 | ||
|
394681d465 | ||
|
a261484cc8 | ||
|
43ed630979 | ||
|
ee9d717e46 | ||
|
68b94ecdf3 | ||
|
2b0a9bca02 | ||
|
13c9c82cae | ||
|
6e0a745133 | ||
|
88ddd5fba5 | ||
|
2dec151b5c | ||
|
1ba0b8765f | ||
|
f278d451d8 | ||
|
1f6bf5e4c0 | ||
|
5dae7dbdb7 | ||
|
fbbf9665a8 | ||
|
e8ab63a01b | ||
|
fdbf836519 | ||
|
8f94f9b7ec | ||
|
e6db1ef8bd | ||
|
d09082150e | ||
|
3e578b5696 | ||
|
c586963a3d | ||
|
a7342eab13 | ||
|
256f31683d | ||
|
8040ba33d6 | ||
|
80c7ed953f | ||
|
dd055f6225 | ||
|
55734408b7 | ||
|
d317154f77 | ||
|
36489f4cb5 | ||
|
2530046e72 | ||
|
172c2a2fc3 | ||
|
480e111bf8 | ||
|
7659782c71 | ||
|
026f88c27c | ||
|
f73d11d461 | ||
|
2b6b90e8f1 | ||
|
e1770ec52b | ||
|
0453bb1c25 | ||
|
da55e4a0cf | ||
|
b1833bd054 | ||
|
6dfda22dd6 | ||
|
94c72aa7c5 | ||
|
87526a8aa1 | ||
|
844c808726 | ||
|
ce08dda6b3 | ||
|
0ad4c8ce73 | ||
|
3387b2f267 | ||
|
d4a53f1779 | ||
|
956a47433b | ||
|
f866b2a854 | ||
|
8744cc88ef | ||
|
57bbd38e56 | ||
|
eef5f33ea3 | ||
|
25e6f0b17d | ||
|
ae885f5d8c | ||
|
33e8fd937f | ||
|
404d2015f4 | ||
|
cd0530ad7a | ||
|
2a957f5c41 | ||
|
7e64e614a1 | ||
|
c887fa4a07 | ||
|
09d175379e | ||
|
cdb861eda0 | ||
|
6a853b60cc | ||
|
76f50fc3ad | ||
|
9b4acb8f10 | ||
|
d11ccd183d | ||
|
a156a1072e | ||
|
d69e5f0850 | ||
|
86f0c11c06 | ||
|
eda98fb9e5 | ||
|
844e852dde | ||
|
cca75e0840 | ||
|
ef107e1d4b | ||
|
e97d20ce65 | ||
|
3c9d7dd29d | ||
|
4ff392a586 | ||
|
69c53bd75e |
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
github: stefanzweifel
|
||||
custom: ["https://buymeacoff.ee/3oQ64YW"]
|
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -7,8 +7,10 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- Before opening an issue, have you tried solving your problem by explicitly setting the `branch`-value in your workflow? -->
|
||||
|
||||
**Version of the Action**
|
||||
`v2.x.x`
|
||||
`v4.x.x`
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
@@ -26,5 +28,11 @@ A clear and concise description of what you expected to happen.
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Used Workflow**
|
||||
|
||||
```yaml
|
||||
# Paste the Workflow you've used here
|
||||
```
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
22
.github/workflows/git-auto-commit.yml
vendored
Normal file
22
.github/workflows/git-auto-commit.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: git-auto-commit
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
git-auto-commit:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Use git-auto-commit-action
|
||||
id: "auto-commit-action"
|
||||
uses: ./
|
||||
|
||||
- name: "no changes detected"
|
||||
if: steps.auto-commit-action.outputs.changes_detected == false
|
||||
run: "echo \"No changes detected\""
|
||||
|
||||
- name: "changes detected"
|
||||
if: steps.auto-commit-action.outputs.changes_detected == true
|
||||
run: "echo \"Changes detected\""
|
15
.github/workflows/versioning.yml
vendored
Normal file
15
.github/workflows/versioning.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: Keep the versions up-to-date
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published, edited]
|
||||
|
||||
jobs:
|
||||
actions-tagger:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: Actions-R-Us/actions-tagger@latest
|
||||
env:
|
||||
GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}"
|
||||
with:
|
||||
- publish_latest_tag: true
|
81
CHANGELOG.md
81
CHANGELOG.md
@@ -4,16 +4,93 @@ 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/v3.0.0...HEAD)
|
||||
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.4.1...HEAD)
|
||||
|
||||
> TBD
|
||||
|
||||
|
||||
## [v4.4.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.4.0...v4.4.1) - 2020-08-016
|
||||
|
||||
### Changed
|
||||
- Include given `file_pattern` in git dirty check [#91](https://github.com/stefanzweifel/git-auto-commit-action/pull/91)
|
||||
|
||||
|
||||
## [v4.4.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.3.0...v4.4.0) - 2020-06-26
|
||||
|
||||
### Added
|
||||
- Add option to skipt the dirty check and always try to create and push a commit [#82](https://github.com/stefanzweifel/git-auto-commit-action/issues/82), [#84](https://github.com/stefanzweifel/git-auto-commit-action/pull/84)
|
||||
|
||||
|
||||
## [v4.3.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.2.0...v4.3.0) - 2020-05-16
|
||||
|
||||
Note: Since v4.3.0 we provide major version tags. You can now use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of a major version. See [#77](https://github.com/stefanzweifel/git-auto-commit-action/issues/77) for details.
|
||||
|
||||
### Added
|
||||
- Add new `push_options`-input. This feature makes it easier for you to force-push commits to a repository. [#78](https://github.com/stefanzweifel/git-auto-commit-action/pull/78), [#72](https://github.com/stefanzweifel/git-auto-commit-action/issues/72)
|
||||
|
||||
|
||||
## [v4.2.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.6...v4.2.0) - 2020-05-10
|
||||
|
||||
### Changed
|
||||
- Use `${{ github.head_ref }}` as default branch value. Therefore, the branch name when listening for `pull_request`-events is optional. [#75](https://github.com/stefanzweifel/git-auto-commit-action/pull/75), [#73](https://github.com/stefanzweifel/git-auto-commit-action/pull/73)
|
||||
|
||||
|
||||
## [v4.1.6](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.5...v4.1.6) - 2020-04-28
|
||||
|
||||
### Fixes
|
||||
- Fix issue where tags could not be created correctly [#68](https://github.com/stefanzweifel/git-auto-commit-action/pull/68)
|
||||
|
||||
## [v4.1.5](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.4...v4.1.5) - 2020-04-23
|
||||
|
||||
### Added
|
||||
- Update `file_pattern` to support multiple file paths [#65](https://github.com/stefanzweifel/git-auto-commit-action/pull/65)
|
||||
|
||||
### Changes
|
||||
- Revert changes made in v4.1.4 [#63](https://github.com/stefanzweifel/git-auto-commit-action/pull/63)
|
||||
|
||||
### Fixes
|
||||
- Fix issue with `commit_options` [#64](https://github.com/stefanzweifel/git-auto-commit-action/pull/64)
|
||||
|
||||
## [v4.1.4](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.3...v4.1.4) - 2020-04-22
|
||||
|
||||
### Fixed
|
||||
- Fix bug introduced in previous version, where git user configuration has been placed inline [#62](https://github.com/stefanzweifel/git-auto-commit-action/pull/62)
|
||||
|
||||
|
||||
## [v4.1.3](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.2...v4.1.3) - 2020-04-18
|
||||
|
||||
### Changed
|
||||
- Place Git user configuration inline [#59](https://github.com/stefanzweifel/git-auto-commit-action/pull/59)
|
||||
|
||||
## [v4.1.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.1...v4.1.2) - 2020-04-03
|
||||
|
||||
### Fixes
|
||||
- Fix Issue with `changes_detected`-output [#57](https://github.com/stefanzweifel/git-auto-commit-action/pull/57)
|
||||
|
||||
## [v4.1.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.0...v4.1.1) - 2020-03-14
|
||||
|
||||
### Fixes
|
||||
- Fix issue where commit has not been pushed to remote repository, when no `branch`-option has been given [#54](https://github.com/stefanzweifel/git-auto-commit-action/pull/54)
|
||||
|
||||
|
||||
## [v4.1.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.0.0...v4.1.0) - 2020-03-05
|
||||
|
||||
### Added
|
||||
- Add `changes_detected` output [#49](https://github.com/stefanzweifel/git-auto-commit-action/pull/49), [#46](https://github.com/stefanzweifel/git-auto-commit-action/issues/46)
|
||||
- Add `tagging_message` input option to create and push tags [#50](https://github.com/stefanzweifel/git-auto-commit-action/pull/50), [#47](https://github.com/stefanzweifel/git-auto-commit-action/issues/47)
|
||||
|
||||
|
||||
## [v4.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v3.0.0...v4.0.0) - 2020-02-24
|
||||
|
||||
### Changed
|
||||
- Switch Action to use `node12`-environment instead of `docker`. [#45](https://github.com/stefanzweifel/git-auto-commit-action/pull/45)
|
||||
|
||||
## [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
|
||||
### Changed
|
||||
- Make the `branch` input option optional [#41](https://github.com/stefanzweifel/git-auto-commit-action/pull/41)
|
||||
|
||||
### Removed
|
||||
|
16
Dockerfile
16
Dockerfile
@@ -1,16 +0,0 @@
|
||||
FROM alpine/git:1.0.7
|
||||
|
||||
LABEL "com.github.actions.name"="Auto Commit changed files"
|
||||
LABEL "com.github.actions.description"="Automatically commits files which have been changed during the workflow run and push changes back to remote repository."
|
||||
LABEL "com.github.actions.icon"="git-commit"
|
||||
LABEL "com.github.actions.color"="orange"
|
||||
|
||||
LABEL "repository"="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>"
|
||||
|
||||
RUN apk add git-lfs
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
175
README.md
175
README.md
@@ -1,35 +1,35 @@
|
||||
# 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.
|
||||
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>".
|
||||
> The GitHub Action for committing files for the 80% use case.
|
||||
|
||||
If no changes are detected, the Action does nothing.
|
||||
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>".
|
||||
|
||||
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.*
|
||||
|
||||
## 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, after other steps that might add or change files.
|
||||
|
||||
```yaml
|
||||
- uses: stefanzweifel/git-auto-commit-action@v3.0.0
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
# Required
|
||||
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 branch to push to, defaults to the current branch
|
||||
branch: feature-123
|
||||
|
||||
# Optional git params
|
||||
# Optional options appended to `git-commit`
|
||||
# See https://git-scm.com/docs/git-commit for a list of available options
|
||||
commit_options: '--no-verify --signoff'
|
||||
|
||||
# Optional glob pattern of files which should be added to the commit
|
||||
file_pattern: src/\*.js
|
||||
# See the `pathspec`-documentation for git
|
||||
# - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203
|
||||
# - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
|
||||
file_pattern: src/*.js tests/*.js
|
||||
|
||||
# Optional local file path to the repository
|
||||
repository: .
|
||||
@@ -37,24 +37,34 @@ Add the following step at the end of your job.
|
||||
# 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>
|
||||
commit_author: Author <actions@github.com>
|
||||
|
||||
# Optional tag message
|
||||
# Action will create and push a new tag to the remote repository and the defined branch
|
||||
tagging_message: 'v1.0.0'
|
||||
|
||||
# Optional options appended to `git-push`
|
||||
push_options: '--force'
|
||||
|
||||
# Optional: Disable dirty check and always try to create a commit and push
|
||||
skip_dirty_check: true
|
||||
```
|
||||
|
||||
The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!
|
||||
## Example
|
||||
|
||||
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.
|
||||
In this example, we're running `php-cs-fixer` in a PHP project to fix the codestyle automatically, then commit possible changed files back to the repository.
|
||||
|
||||
## Example Usage
|
||||
|
||||
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.
|
||||
Note that we explicitly specify `${{ github.head_ref }}` in the checkout Action.
|
||||
This is required in order to work with the `pull_request` event (or any other non-`push` event).
|
||||
|
||||
```yaml
|
||||
name: php-cs-fixer
|
||||
|
||||
on: pull_request
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
jobs:
|
||||
php-cs-fixer:
|
||||
@@ -68,48 +78,111 @@ jobs:
|
||||
- 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
|
||||
branch: ${{ github.head_ref }}
|
||||
```
|
||||
|
||||
```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
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: Apply php-cs-fixer changes
|
||||
```
|
||||
|
||||
### Inputs
|
||||
## Inputs
|
||||
|
||||
Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml) for a full list of supported inputs.
|
||||
|
||||
## Outputs
|
||||
|
||||
You can use these outputs to trigger other Actions in your Workflow run based on the result of `git-auto-commit-action`.
|
||||
|
||||
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
|
||||
|
||||
## Limitations & Gotchas
|
||||
|
||||
### Checkout the correct branch
|
||||
|
||||
You must use `action/checkout@v2` or later versions to checkout the repository.
|
||||
In non-`push` events, such as `pull_request`, make sure to specify the `ref` to checkout:
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
```
|
||||
|
||||
You have to do this do avoid that the `checkout`-Action clones your repository in a detached state.
|
||||
|
||||
### Commits of this Action do not trigger new Workflow runs
|
||||
|
||||
The resulting commit **will not trigger** another GitHub Actions Workflow run.
|
||||
This is due to [limititations set by GitHub](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).
|
||||
|
||||
> When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.
|
||||
|
||||
You can change this by creating a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new),
|
||||
storing the token as a secret in your repository and then passing the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
```
|
||||
|
||||
### Unable to commit into PRs from forks
|
||||
|
||||
GitHub currently prohibits Actions to push commits to forks, even when they created a PR and allow edits.
|
||||
See [issue #25](https://github.com/stefanzweifel/git-auto-commit-action/issues/25) for more information.
|
||||
|
||||
### Signing Commits & Other Git Command Line Options
|
||||
|
||||
Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regulary
|
||||
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
|
||||
|
||||
## 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)
|
||||
### Action does not push commit to repository
|
||||
|
||||
## Known Issues
|
||||
Make sure to [checkout the correct branch](#checkout-the-correct-branch).
|
||||
|
||||
- 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 does not push commit to repository: Authentication Issue
|
||||
|
||||
If your Workflow can't push the commit to the repository because of authentication issues,
|
||||
please update your Workflow configuration and usage of [`actions/checkout`](https://github.com/actions/checkout#usage).
|
||||
|
||||
Updating the `token` value with a Personal Access Token should fix your issues.
|
||||
|
||||
### Push to protected branches
|
||||
|
||||
If your repository uses [protected branches](https://help.github.com/en/github/administering-a-repository/configuring-protected-branches) you have to do the following changes to your Workflow for the Action to work properly.
|
||||
|
||||
You have to enable force pushes to a protected branch (See [documentation](https://help.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)) and update your Workflow to use force push like this.
|
||||
|
||||
```yaml
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: Apply php-cs-fixer changes
|
||||
push_options: --force
|
||||
```
|
||||
|
||||
In addition, you have to create a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new),
|
||||
store the token as a secret in your repository and pass the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
```
|
||||
You can learn more about Personal Access Token in the [GitHub documentation](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
|
||||
|
||||
Note: If you're working in an organisation and you don't want to create the PAT from your personal account, we recommend using a bot-account for such tokens.
|
||||
|
||||
### No new workflows are triggered by the commit of this action
|
||||
|
||||
This is due to limitations set up by GitHub, [commits of this Action do not trigger new Workflow runs](#commits-of-this-action-do-not-trigger-new-workflow-runs).
|
||||
|
||||
## 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).
|
||||
|
||||
We also provide major version tags to make it easier to always use the latest release of a major version. For example you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version.
|
||||
(More information about this [here](https://help.github.com/en/actions/building-actions/about-actions#versioning-your-action).)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/LICENSE) file for details.
|
||||
|
23
action.yml
23
action.yml
@@ -10,10 +10,11 @@ inputs:
|
||||
branch:
|
||||
description: Git branch name, where changes should be pushed too. Required if Action is used on the `pull_request` event
|
||||
required: false
|
||||
default: ''
|
||||
default: ${{ github.head_ref }}
|
||||
commit_options:
|
||||
description: Commit options (eg. --no-verify)
|
||||
required: false
|
||||
default: ''
|
||||
file_pattern:
|
||||
description: File pattern used for `git add`. For example `src/\*.js`
|
||||
required: false
|
||||
@@ -34,10 +35,26 @@ inputs:
|
||||
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>
|
||||
tagging_message:
|
||||
description: Message used to create a new git tag with the commit. Keep this empty, if no tag should be created.
|
||||
required: false
|
||||
default: ''
|
||||
push_options:
|
||||
description: Push options (eg. --force)
|
||||
required: false
|
||||
default: ''
|
||||
skip_dirty_check:
|
||||
description: Skip the check if the git repository is dirty and always try to create a commit.
|
||||
required: false
|
||||
default: false
|
||||
|
||||
outputs:
|
||||
changes_detected:
|
||||
description: Value is "true", if the repository was dirty and file changes have been detected. Value is "false", if no changes have been detected.
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
using: 'node12'
|
||||
main: 'index.js'
|
||||
|
||||
branding:
|
||||
icon: 'git-commit'
|
||||
|
@@ -5,9 +5,9 @@ set -eu
|
||||
_main() {
|
||||
_switch_to_repository
|
||||
|
||||
if _git_is_dirty; then
|
||||
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
|
||||
|
||||
_setup_git
|
||||
echo "::set-output name=changes_detected::true";
|
||||
|
||||
_switch_to_branch
|
||||
|
||||
@@ -15,51 +15,85 @@ _main() {
|
||||
|
||||
_local_commit
|
||||
|
||||
_tag_commit
|
||||
|
||||
_push_to_github
|
||||
else
|
||||
echo "Working tree clean. Nothing to commit."
|
||||
|
||||
echo "::set-output name=changes_detected::false";
|
||||
|
||||
echo "Working tree clean. Nothing to commit.";
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
_switch_to_repository() {
|
||||
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
|
||||
cd $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"
|
||||
[ -n "$(git status -s -- $INPUT_FILE_PATTERN)" ]
|
||||
}
|
||||
|
||||
_switch_to_branch() {
|
||||
echo "INPUT_BRANCH value: $INPUT_BRANCH";
|
||||
|
||||
# Switch to branch from current Workflow run
|
||||
git checkout $INPUT_BRANCH
|
||||
git checkout $INPUT_BRANCH;
|
||||
}
|
||||
|
||||
_add_files() {
|
||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
|
||||
git add "${INPUT_FILE_PATTERN}"
|
||||
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"}
|
||||
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}";
|
||||
echo "::debug::Apply commit options ${INPUT_COMMIT_OPTIONS}";
|
||||
|
||||
INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS );
|
||||
|
||||
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" \
|
||||
commit -m "$INPUT_COMMIT_MESSAGE" \
|
||||
--author="$INPUT_COMMIT_AUTHOR" \
|
||||
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};
|
||||
}
|
||||
|
||||
_tag_commit() {
|
||||
echo "INPUT_TAGGING_MESSAGE: ${INPUT_TAGGING_MESSAGE}"
|
||||
|
||||
if [ -n "$INPUT_TAGGING_MESSAGE" ]
|
||||
then
|
||||
echo "::debug::Create tag $INPUT_TAGGING_MESSAGE";
|
||||
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE";
|
||||
else
|
||||
echo " No tagging message supplied. No tag will be added.";
|
||||
fi
|
||||
}
|
||||
|
||||
_push_to_github() {
|
||||
|
||||
echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS}";
|
||||
echo "::debug::Apply push options ${INPUT_PUSH_OPTIONS}";
|
||||
|
||||
INPUT_PUSH_OPTIONS_ARRAY=( $INPUT_PUSH_OPTIONS );
|
||||
|
||||
if [ -z "$INPUT_BRANCH" ]
|
||||
then
|
||||
git push origin
|
||||
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
|
||||
if [ -n "$INPUT_TAGGING_MESSAGE" ]
|
||||
then
|
||||
echo "::debug::git push origin --tags";
|
||||
git push origin --tags ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
else
|
||||
echo "::debug::git push origin";
|
||||
git push origin ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
fi
|
||||
|
||||
else
|
||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
|
||||
echo "::debug::Push commit to remote branch $INPUT_BRANCH";
|
||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --tags ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
fi
|
||||
}
|
||||
|
||||
|
34
index.js
Normal file
34
index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Most of this code has been copied from the following GitHub Action
|
||||
* to make it simpler or not necessary to install a lot of
|
||||
* JavaScript packages to execute a shell script.
|
||||
*
|
||||
* https://github.com/ad-m/github-push-action/blob/fe38f0a751bf9149f0270cc1fe20bf9156854365/start.js
|
||||
*/
|
||||
|
||||
const spawn = require('child_process').spawn;
|
||||
const path = require("path");
|
||||
|
||||
const exec = (cmd, args=[]) => new Promise((resolve, reject) => {
|
||||
console.log(`Started: ${cmd} ${args.join(" ")}`)
|
||||
const app = spawn(cmd, args, { stdio: 'inherit' });
|
||||
app.on('close', code => {
|
||||
if(code !== 0){
|
||||
err = new Error(`Invalid status code: ${code}`);
|
||||
err.code = code;
|
||||
return reject(err);
|
||||
};
|
||||
return resolve(code);
|
||||
});
|
||||
app.on('error', reject);
|
||||
});
|
||||
|
||||
const main = async () => {
|
||||
await exec('bash', [path.join(__dirname, './entrypoint.sh')]);
|
||||
};
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
console.error(err.stack);
|
||||
process.exit(err.code || -1);
|
||||
})
|
Reference in New Issue
Block a user