Compare commits

...

78 Commits

Author SHA1 Message Date
Stefan Zweifel
cc7755497c Release v4.5.0 2020-09-10 19:48:26 +02:00
Stefan Zweifel
5c3c72f20e Merge pull request #95 from StrongMonkey/master
Creating orphan branch
2020-09-10 19:44:31 +02:00
Daishan
505389d146 Creating orphan branch 2020-09-01 18:12:58 -07:00
Stefan Zweifel
303ce37181 Merge pull request #93 from stefanzweifel/add-note-about-forks
Update README with instructions for forks
2020-08-22 14:45:20 +02:00
Stefan Zweifel
13efc066dd Small little improvements 2020-08-22 14:42:29 +02:00
Stefan Zweifel
3c204cdee3 Update README.md 2020-08-22 14:21:01 +02:00
Stefan Zweifel
0429047166 Update README with instructions for forks
GitHub recently introduced ways for Actions to run on forks.

This update now finally allows repository maintainers to write Workflows to run code linters and fixers which can also work on the forks.
2020-08-22 14:13:11 +02:00
Stefan Zweifel
09d3315401 Update Versioning Workflow 2020-08-16 20:05:44 +02:00
Stefan Zweifel
1f4914882d Release v4.4.1 2020-08-16 20:03:54 +02:00
Stefan Zweifel
b5320678c1 Merge pull request #91 from HarrisonGrodin/patch-1
Only check status of files matching file_pattern
2020-08-16 19:31:45 +02:00
Harrison Grodin
01ffd8c6f6 Only check status of files matching file_pattern 2020-08-15 22:11:45 -04:00
Stefan Zweifel
5222c758dd Add FUNDING.yml 2020-07-29 13:22:07 +02:00
Stefan Zweifel
bbcb72b1e9 Update README 2020-07-26 12:53:22 +02:00
Stefan Zweifel
142eb9509a Update README 2020-07-24 21:11:32 +02:00
Stefan Zweifel
0233fee872 Update Protected Branch Section in README 2020-07-24 20:59:16 +02:00
Stefan Zweifel
808edcd96b Add links to pathspec documentation 2020-07-24 20:44:56 +02:00
Stefan Zweifel
1b1d53f462 Move Inputs and Outputs 2020-07-24 20:24:23 +02:00
Stefan Zweifel
ee93725e66 Merge pull request #86 from TGTGamer/master
Docs: #85 Add small information about command line options
2020-07-18 13:50:16 +02:00
Jonathan S
36304edfd2 Update README.md 2020-07-18 12:42:58 +01:00
Stefan Zweifel
ff97e958aa Update README.md 2020-07-16 11:03:50 +02:00
Stefan Zweifel
90282bf5e2 Release v4.4.0 2020-06-26 21:07:28 +02:00
Stefan Zweifel
c9eb2132b2 Merge pull request #84 from stefanzweifel/feature/skip-dirty-check
Add a "Skip Dirty Check" Option
2020-06-26 21:02:58 +02:00
Stefan Zweifel
c8ded2885e Simplify IF Condition 2020-06-26 21:00:48 +02:00
Stefan Zweifel
f120678ed1 WIP 2020-06-25 20:40:31 +02:00
Stefan Zweifel
4183594932 WIP 2020-06-25 20:38:28 +02:00
Stefan Zweifel
49e28abb3f WIP 2020-06-25 20:31:48 +02:00
Stefan Zweifel
4ebfe28af0 Add skip_dirty_check option 2020-06-25 20:18:20 +02:00
Stefan Zweifel
984a26d893 Update link to versioning info in README 2020-05-17 10:20:34 +02:00
Stefan Zweifel
3804c79d2e Add Versioning GitHub Actions 2020-05-17 10:08:37 +02:00
Stefan Zweifel
69a12041a1 Release v4.3.0 2020-05-16 13:47:17 +02:00
Stefan Zweifel
91b7d20ead Merge pull request #78 from stefanzweifel/feature/push-options
Feature: Push Options
2020-05-16 13:30:24 +02:00
Stefan Zweifel
044b6b777c Fix Typo 2020-05-16 13:26:59 +02:00
Stefan Zweifel
9aab2f8a5c Add example for protected branches 2020-05-16 13:22:34 +02:00
Stefan Zweifel
0280d2ccee Add push_options to README 2020-05-16 13:17:00 +02:00
Stefan Zweifel
b0b5ed34dd Update entrypoint to handle push_options 2020-05-16 11:42:40 +02:00
Stefan Zweifel
ae38c94802 Add push_options to action.yml 2020-05-16 11:42:24 +02:00
Stefan Zweifel
3aae7bb63f Remove continous-deployment.yml 2020-05-16 11:24:57 +02:00
Stefan Zweifel
c180c695f2 Release v4.2.0 2020-05-10 13:16:25 +02:00
Stefan Zweifel
c1a70c9013 Update Changelog 2020-05-10 13:12:24 +02:00
Stefan Zweifel
02c4f2cf78 Merge pull request #73 from spawnia/restructure-readme
Bundle limitations and gotchas together in the README.md
2020-05-10 13:11:32 +02:00
Stefan Zweifel
3c687aa8ba Replace head_ref with branch name example 2020-05-10 13:09:18 +02:00
spawnia
a69eabaead clarify branch option 2020-05-10 12:55:07 +02:00
spawnia
9f2c45c9eb Remove unneeded hints to re-specify the default branch 2020-05-10 12:51:21 +02:00
spawnia
5bf88dc2fd Merge branch 'master' into restructure-readme 2020-05-10 12:48:11 +02:00
Stefan Zweifel
fd2aab7c5b Merge pull request #75 from stefanzweifel/use-head-ref-as-default-value
Use github.head_ref as branch default value
2020-05-10 12:31:26 +02:00
Stefan Zweifel
f342c95aa2 Use github.head_ref as branch default value 2020-05-09 12:44:07 +02:00
Benedikt Franke
1157d7bbe9 Shorten 2020-05-06 00:22:05 +02:00
Benedikt Franke
58b79711d8 Add example 2020-05-06 00:21:35 +02:00
Benedikt Franke
f5f76eb1f4 Consolidate more 2020-05-06 00:00:33 +02:00
Benedikt Franke
5513d18f64 Bundle limitations and gotchas together in the README.md 2020-05-05 23:54:32 +02:00
Stefan Zweifel
6ef5688e81 Update bug_report.md 2020-05-01 12:56:39 +02:00
Stefan Zweifel
e02ededdeb Update README with instructions and limitations
Closes #69
2020-05-01 12:56:23 +02:00
Stefan Zweifel
2f5e73df85 Release v4.1.6 2020-04-28 13:28:19 +02:00
Stefan Zweifel
cc16347545 Merge pull request #68 from stefanzweifel/fix-67
Inline User Configuration when creating a Tag
2020-04-28 13:27:03 +02:00
Stefan Zweifel
1ee136f439 Inline user config with tag command 2020-04-28 13:12:43 +02:00
Stefan Zweifel
7fdc480651 Update README.md 2020-04-24 10:14:37 +02:00
Stefan Zweifel
394681d465 Release v4.1.5 2020-04-23 20:46:50 +02:00
Stefan Zweifel
a261484cc8 Update file_pattern Example in README 2020-04-23 20:46:41 +02:00
Stefan Zweifel
43ed630979 Merge pull request #64 from stefanzweifel/fix-61
Fix Issue with Commit Options
2020-04-23 20:35:56 +02:00
Stefan Zweifel
ee9d717e46 Merge branch 'master' into fix-61
# Conflicts:
#	entrypoint.sh
2020-04-23 20:20:10 +02:00
Stefan Zweifel
68b94ecdf3 Merge pull request #65 from cristianpb/master
 Allow to add multiple files
2020-04-23 16:20:11 +02:00
cristianpb
2b0a9bca02 Allow to add multiple files 2020-04-23 15:55:10 +02:00
Stefan Zweifel
13c9c82cae Merge pull request #63 from stefanzweifel/revert-62-revert-59-no-override-global-git
Revert "Revert "Place git user configuration inline before commit""
2020-04-22 21:20:00 +02:00
Stefan Zweifel
6e0a745133 Use Array 2020-04-22 21:17:10 +02:00
Stefan Zweifel
88ddd5fba5 WIP 2020-04-22 21:04:17 +02:00
Stefan Zweifel
2dec151b5c WIP 2020-04-22 20:49:36 +02:00
Stefan Zweifel
1ba0b8765f WIP 2020-04-22 20:43:52 +02:00
Stefan Zweifel
f278d451d8 Revert hard coded options 2020-04-22 20:39:17 +02:00
Stefan Zweifel
1f6bf5e4c0 Set default value for commit_options 2020-04-22 20:39:08 +02:00
Stefan Zweifel
5dae7dbdb7 Hard Code Options 2020-04-22 20:36:26 +02:00
Stefan Zweifel
fbbf9665a8 Output git version and debugging message 2020-04-22 20:21:08 +02:00
Stefan Zweifel
e8ab63a01b Add ; in more places 2020-04-22 20:17:05 +02:00
Stefan Zweifel
fdbf836519 Split git-commit command 2020-04-22 20:07:31 +02:00
Stefan Zweifel
8f94f9b7ec Revert "Revert "Place git user configuration inline before commit"" 2020-04-22 20:04:52 +02:00
Stefan Zweifel
e6db1ef8bd Release v4.1.4 2020-04-22 12:58:51 +02:00
Stefan Zweifel
d09082150e Merge pull request #62 from stefanzweifel/revert-59-no-override-global-git
Revert "Place git user configuration inline before commit"
2020-04-22 12:56:36 +02:00
Stefan Zweifel
3e578b5696 Revert "Place git user configuration inline before commit" 2020-04-22 12:55:25 +02:00
Stefan Zweifel
c586963a3d Update README 2020-04-18 10:55:30 +02:00
8 changed files with 291 additions and 131 deletions

2
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,2 @@
github: stefanzweifel
custom: ["https://buymeacoff.ee/3oQ64YW"]

View File

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

View File

@@ -1,31 +0,0 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Continuous Deployment"
on:
push:
tags:
- "**"
jobs:
release:
name: "Release"
runs-on: "ubuntu-latest"
steps:
- name: "Determine tag"
id: "determine-tag"
run: "echo \"::set-output name=tag::${GITHUB_REF#refs/tags/}\""
- name: "Create release"
uses: "actions/create-release@v1.0.0"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
draft: false
prerelease: false
body: |
See [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) for details.
release_name: "${{ steps.determine-tag.outputs.tag }}"
tag_name: "${{ steps.determine-tag.outputs.tag }}"

15
.github/workflows/versioning.yml vendored Normal file
View 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

View File

@@ -4,11 +4,67 @@ 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/v4.1.3...HEAD)
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.5.0...HEAD)
> TBD
## [v4.5.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.4.1...v4.5.0) - 2020-09-10
### Added
- Create orphan branch if branch name does not exist [#95](https://github.com/stefanzweifel/git-auto-commit-action/pull/95)
## [v4.4.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.4.0...v4.4.1) - 2020-08-16
### 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
### 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
@@ -39,7 +95,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### 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

230
README.md
View File

@@ -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@v4.1.2
- 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 *.php
# Optional local file path to the repository
repository: .
@@ -39,28 +39,33 @@ Add the following step at the end of your job.
commit_user_email: my-github-actions-bot@example.org
commit_author: Author <actions@github.com>
# Optional tag message. Will create and push a new tag to the remote repository
# 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`
# See git-push documentation for details: https://git-scm.com/docs/git-push#_options
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
We recommend to use this Action in Workflows, which listen to the `pull_request` event. You can then use the option `branch: ${{ github.head_ref }}` to set up the branch name correctly.
If you don't pass a branch name, the Action will try to push the commit to a branch with the same name, as with which the repo has been checked out.
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 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.
### Example on `pull_request` event
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:
@@ -74,90 +79,167 @@ jobs:
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4.1.2
with:
commit_message: Apply php-cs-fixer changes
branch: ${{ github.head_ref }}
```
### Example on `push` event
```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@v4.1.2
- 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.
## Troubleshooting
## Limitations & Gotchas
### Can't push commit to repository
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)
### Checkout the correct branch
### Commit of this Action does not trigger a new Workflow run
As mentioned in the [Usage](#Usage) section, the commit created by this Action **will not trigger** a new Workflow run automatically.
This is due to limitations set up by GitHub:
> An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.
[Source](https://help.github.com/en/actions/reference/events-that-trigger-workflows)
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.
#### Example Workflow
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
name: php-cs-fixer
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
```
on: push
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 }}
```
If you work in an organization and don't want to create a PAT from your personal account, we recommend using a [robot account](https://docs.github.com/en/github/getting-started-with-github/types-of-github-accounts) for the token.
### Using the Action in forks from public repositories
By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.)
If you want that a Workflow using this Action runs on Pull Requests opened by forks, 2 things have to be changed:
1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target).
2. GitHub Action has to be enabled on the forked repository. \
For security reasons, GitHub does not automatically enable GitHub Actions on forks. The user has to explicitly enable GitHub Actions in the "Actions"-tab of the forked repository. (Mention this in your projects README or CONTRIBUTING.md!)
After you have added the `pull_request_target` to your desired Workflow and the forked repository has enabled Actions and a new Pull Request is opened, the Workflow will run **on the forked repository**.
Due to the fact that the Workflow is not run on the repository the Pull Request is opened in, you won't see any status indicators inside the Pull Request.
#### Example
The following workflow runs `php-cs-fixer` (a code linter and fixer for PHP) when a `pull_request` is opened. We've added the `pull_request_target`-trigger too, to make it work for forks.
```yaml
name: Format PHP
on: [pull_request, pull_request_target]
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT_TOKEN }}
ref: ${{ github.head_ref }}
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4.1.2
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes
```
## Known Issues
Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the the forked repository and will push commits to the same 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.
Here's how the Pull Request will look like:
![Screenshot of a Pull Request from a Fork](https://user-images.githubusercontent.com/1080923/90955964-9c74c080-e482-11ea-8097-aa7f5161f50e.png)
As you can see, your contributors have to go through hoops to make this work. For Workflows which runter linters and fixers (like the example above) we recommend running them when a push happens on the `master`-branch.
For more information about running Actions on forks, see [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/).
### Push to forks from private repositories
By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings.
See [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) or the [GitHub docs](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) for details.
### 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
### Action does not push commit to repository
Make sure to [checkout the correct branch](#checkout-the-correct-branch).
### 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.

View File

@@ -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
@@ -38,6 +39,14 @@ inputs:
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:

View File

@@ -1,13 +1,14 @@
#!/bin/bash
set -eu
set -x
_main() {
_switch_to_repository
if _git_is_dirty; then
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
echo "::set-output name=changes_detected::true"
echo "::set-output name=changes_detected::true";
_switch_to_branch
@@ -20,37 +21,49 @@ _main() {
_push_to_github
else
echo "::set-output name=changes_detected::false"
echo "::set-output name=changes_detected::false";
echo "Working tree clean. Nothing to commit."
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)" ]
[ -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
if git show-ref --verify --quiet refs/heads/$INPUT_BRANCH; then
# Switch to branch from current Workflow run
git checkout $INPUT_BRANCH;
else
git checkout --orphan $INPUT_BRANCH
git rm -rf .
fi
}
_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 -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"}
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() {
@@ -58,29 +71,35 @@ _tag_commit() {
if [ -n "$INPUT_TAGGING_MESSAGE" ]
then
echo "::debug::Create tag $INPUT_TAGGING_MESSAGE"
git tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE"
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."
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
# 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
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
echo "::debug::git push origin";
git push origin ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
fi
else
echo "::debug::Push commit to remote branch $INPUT_BRANCH"
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --tags
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
}