Compare commits

...

64 Commits

Author SHA1 Message Date
Stefan Zweifel
050015d406
Add Scope/Permissions documentation for PATs
Some checks failed
Lint Code Base / Lint Code Base (push) Failing after 4s
git-auto-commit / git-auto-commit (push) Successful in 8s
Release Drafter / update_release_draft (push) Failing after 5s
tests / tests (push) Failing after 7s
Closes #347
2024-10-06 10:39:09 +02:00
scarf
573710f3d0
docs(README): fix broken protected branch docs link (#346) 2024-10-04 08:56:00 +02:00
Marcelo Trylesinski
e961da7576
Update README.md (#343) 2024-09-22 16:50:21 +02:00
dependabot[bot]
ac8823709a
Bump github/super-linter from 6 to 7 (#342)
Bumps [github/super-linter](https://github.com/github/super-linter) from 6 to 7.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/super-linter/compare/v6...v7)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-02 08:16:51 +02:00
dependabot[bot]
be823a7e51
Bump github/super-linter from 5 to 6 (#335)
Bumps [github/super-linter](https://github.com/github/super-linter) from 5 to 6.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/super-linter/compare/v5...v6)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-08 08:26:25 +02:00
Stefan Zweifel
55a82ca24f
Add Section on preventing infinite loops to README 2024-07-06 15:14:44 +02:00
Stefan Zweifel
18157e6f3b
Update bug.yaml 2024-07-06 12:07:25 +02:00
Stefan Zweifel
7d779d0067
Update Bug Repo Form 2024-07-06 12:06:47 +02:00
Stefan Zweifel
efd424db0f
Fix link to "new feature request" 2024-07-06 12:00:09 +02:00
Stefan Zweifel
5f3fa8aed3
Add docs about .github/workflows pushes
See #322
2024-07-06 11:43:22 +02:00
Stefan Zweifel
ee5525316d
Update GPG Signing section in README 2024-07-02 20:41:34 +02:00
Stefan Zweifel
4b8a201e31
Add with ref github.head_ref to README 2024-04-13 10:35:11 +02:00
stefanzweifel
896cc0d225 Update CHANGELOG 2024-04-12 06:47:58 +00:00
Constantin Comendant
8621497c8c
Fail if attempting to execute git commands in a directory that is not a git-repo. (#326)
Some checks failed
Lint Code Base / Lint Code Base (push) Failing after 4s
* Fail (and log message) if attempting to execute git commands in a directory that is not a git-repo.

* Add Test

* Code Formatting

---------

Co-authored-by: Constantin Comendant <constantin@uberagent.com>
Co-authored-by: Stefan Zweifel <stefan@stefanzweifel.dev>
2024-04-11 21:00:36 +02:00
dependabot[bot]
b0f4d47f59
Bump bats from 1.10.0 to 1.11.0 (#325)
Bumps [bats](https://github.com/bats-core/bats-core) from 1.10.0 to 1.11.0.
- [Release notes](https://github.com/bats-core/bats-core/releases)
- [Changelog](https://github.com/bats-core/bats-core/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bats-core/bats-core/compare/v1.10.0...v1.11.0)

---
updated-dependencies:
- dependency-name: bats
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-26 08:29:07 +01:00
Christian Vermeulen
9b5e5ee10a
Add step id explanation for output in README.md (#324) 2024-03-15 16:06:58 +01:00
Philip Couling
e040c596f0
Linux is not UNIX (#321) 2024-02-22 08:26:06 +01:00
dependabot[bot]
4d160c5e4d
Bump release-drafter/release-drafter from 5 to 6 (#319) 2024-02-06 07:16:57 +01:00
Nikita Panuhin
12f68633e4
Clarify commit_author input option (#315)
* Clarify `commit_author` input option

* Update README.md

---------

Co-authored-by: Stefan Zweifel <stefanzweifel@users.noreply.github.com>
2023-12-24 07:35:30 +01:00
Stefan Zweifel
29183a25ec
Remove outdated docs 2023-12-12 20:45:33 +01:00
Stefan Zweifel
2818fe7949
Add Alert about pull_request_target
https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1837270114
2023-12-12 20:42:25 +01:00
Stefan Zweifel
8d90676eef
Little Doc Updates 2023-12-12 20:38:26 +01:00
Stefan Zweifel
8036286d37
Use new Markdown Alerts in README 2023-12-12 20:38:06 +01:00
Stefan Zweifel
e8f94e4dd2
Merge branch 'master' of github.com:stefanzweifel/git-auto-commit-action 2023-10-06 19:56:36 +02:00
Stefan Zweifel
98d2782f49
Use v5 in README 2023-10-06 19:56:33 +02:00
Stefan Zweifel
eb38c210f2
Use v5 in update-changelog Workflow 2023-10-06 19:56:27 +02:00
stefanzweifel
e27a68931b Update CHANGELOG 2023-10-06 17:55:19 +00:00
高井
8756aa072e
Update node version to node20 (#300)
Some checks failed
Lint Code Base / Lint Code Base (push) Failing after 4s
Co-authored-by: ryudai.takai
2023-10-06 19:43:01 +02:00
Stefan Zweifel
17a44b07bf
Merge branch 'master' of github.com:stefanzweifel/git-auto-commit-action 2023-10-06 19:31:58 +02:00
Stefan Zweifel
43818d5044
Fix Typo 2023-10-06 19:30:48 +02:00
Stefan Zweifel
10944650cd
Use actions/checkout v4 in examples
https://github.com/stefanzweifel/git-auto-commit-action/pull/302#issuecomment-1745974288
2023-10-04 15:33:04 +02:00
dependabot[bot]
3d1b5e078a
Bump actions/checkout from 3 to 4 (#302)
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-11 10:32:33 +02:00
dependabot[bot]
47a8ad5f38
Bump bats from 1.9.0 to 1.10.0 (#293)
Bumps [bats](https://github.com/bats-core/bats-core) from 1.9.0 to 1.10.0.
- [Release notes](https://github.com/bats-core/bats-core/releases)
- [Changelog](https://github.com/bats-core/bats-core/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bats-core/bats-core/compare/v1.9.0...v1.10.0)

---
updated-dependencies:
- dependency-name: bats
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-17 09:56:06 +02:00
dependabot[bot]
77a7b3fb3c
Bump github/super-linter from 4 to 5 (#289)
Bumps [github/super-linter](https://github.com/github/super-linter) from 4 to 5.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4...v5)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-23 09:20:59 +02:00
Pedro Amador Rodríguez
9cc0a1f55d
Seems like there is an extra space (#288) 2023-04-03 08:55:34 +02:00
Stefan Zweifel
0b5f8a5333
Update Test 2023-03-28 14:46:47 +02:00
Stefan Zweifel
3a446b74f0
Merge branch 'master' of github.com:stefanzweifel/git-auto-commit-action 2023-02-15 19:45:07 +01:00
Stefan Zweifel
8e108d701f
Fix docs about using in public forks
Update docs section about using the Action in public forks.

Add warning about current issue when the forks lives under an organisation.

Mark section about running a workflow in the head repository as outdated, as I was not able to reproduce this in test projects.

See https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1428849944 for more details.
2023-02-15 19:44:45 +01:00
dependabot[bot]
c8254de74f
Bump bats from 1.8.2 to 1.9.0 (#282)
Bumps [bats](https://github.com/bats-core/bats-core) from 1.8.2 to 1.9.0.
- [Release notes](https://github.com/bats-core/bats-core/releases)
- [Changelog](https://github.com/bats-core/bats-core/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bats-core/bats-core/compare/v1.8.2...v1.9.0)

---
updated-dependencies:
- dependency-name: bats
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-13 08:22:21 +01:00
Stefan Zweifel
6436584fbb
Fix Comment in README 2023-02-11 21:31:27 +01:00
Stefan Zweifel
6656e54255
Use actions/checkout@v3 in examples 2023-02-11 21:29:21 +01:00
Stefan Zweifel
f0b35f0a73
Mention new permission requirements in usage docs
Starting February 2nd 2023, GitHub changed the default permissions of the GITHUB_TOKEN to be read-only in all new repositories.[1]

git-auto-commits needs `write`-permissions for the `contents`-key in order to work properly.
This commits updates the usage section, to mention the need for the permission requirements. The examples have also been updated to reflect that change.

[1]: https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
2023-02-11 21:29:07 +01:00
Stefan Zweifel
ccd4d054a5
Fix Typo in Workflow comments 2023-02-11 21:14:56 +01:00
Stefan Zweifel
94d6bf9d22
Add permissions block to Workflows 2023-02-11 12:23:24 +01:00
Stefan Zweifel
f44d1cd002
Merge branch 'master' of github.com:stefanzweifel/git-auto-commit-action 2023-01-25 19:58:10 +01:00
Stefan Zweifel
92b3981e0b
Update Author Email Address 2023-01-25 19:57:43 +01:00
Stefan Zweifel
3b94e3d017
Update README.md
Closes #281
2023-01-20 15:31:53 +01:00
Stefan Zweifel
3663a6fa3e
Update README.md 2023-01-14 18:05:16 +01:00
Stefan Zweifel
fe00d25867 Add test for multi-line commit messages 2023-01-07 12:06:10 +01:00
cong
86fb2e11b2
Fix git-auto-commit.yml (#277) 2023-01-03 08:17:32 +01:00
Stefan Zweifel
aeb1802648
Add _log and _set_github_output functions (#273)
* Add _set_github_output function

* Use _set_github_output in Action

* Add _log function

* Use _log in Action and fix Test Cases

* Update wording in log messages

* Update note about removal of old output syntax

Logic is now encapuslated in a single function. I don’t mind keeping it around until spring / June 2023
2022-12-22 19:45:17 +01:00
stefanzweifel
925bbcaef3 Update CHANGELOG 2022-12-02 06:50:39 +00:00
ZeroRin
3ea6ae190b
Fix "nothing to commit" error with LF/CRLF changes #241 (#265)
Some checks failed
Lint Code Base / Lint Code Base (push) Failing after 5s
* fix crlf test

* add diff check before commit

* add dirty check flag (not sure if needed)

* Update test name and add more assertions

Update test name to make it clear that the Action no longer fails to detect CRLF changes.

* Add Comment to explain why we use git-diff again

* Add test to confirm content changes are commited

* Closes #241 

Co-authored-by: Stefan Zweifel <hello@stefanzweifel.io>
2022-12-01 20:47:06 +01:00
Teko
976f22029f
Fix github-actions[bot] email address (#264) 2022-11-15 20:12:31 +01:00
Teko
ebb5756042
Fix link and text for workflow limitation (#263) 2022-11-13 10:06:41 +01:00
stefanzweifel
3dce995a13 Update CHANGELOG 2022-11-05 10:56:08 +00:00
Stefan Zweifel
0b007fbd11
Let Action fail if git binary can't be located (#261)
Some checks failed
Lint Code Base / Lint Code Base (push) Failing after 6s
* Check if git binary exists

* Add Tests
2022-11-05 11:53:46 +01:00
dependabot[bot]
7106b2184a
Bump github/super-linter from 3 to 4 (#258)
Bumps [github/super-linter](https://github.com/github/super-linter) from 3 to 4.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v3...v4)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:05:48 +02:00
dependabot[bot]
f166130208
Bump bats from 1.7.0 to 1.8.2 (#259)
Bumps [bats](https://github.com/bats-core/bats-core) from 1.7.0 to 1.8.2.
- [Release notes](https://github.com/bats-core/bats-core/releases)
- [Changelog](https://github.com/bats-core/bats-core/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bats-core/bats-core/compare/v1.7.0...v1.8.2)

---
updated-dependencies:
- dependency-name: bats
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:04:33 +02:00
dependabot[bot]
021a6363fa
Bump actions/checkout from 2 to 3 (#257)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:03:57 +02:00
Stefan Zweifel
38864a638f
Create dependabot.yml 2022-10-26 19:02:41 +02:00
stefanzweifel
393fea59ef Update CHANGELOG 2022-10-26 16:57:18 +00:00
Stefan Zweifel
0049e3fa40
Use deprecated set-output syntax if GITHUB_OUTPUT environment is not available (#255)
Some checks failed
Lint Code Base / Lint Code Base (push) Failing after 4s
* Fallback to set-output if GITHUB_OUTPUT not available

* Add Tests to cover old syntax
2022-10-26 18:55:42 +02:00
stefanzweifel
f6f7a9c351 Update CHANGELOG 2022-10-22 09:19:59 +00:00
18 changed files with 535 additions and 172 deletions

View File

@ -5,7 +5,7 @@ body:
- type: markdown
attributes:
value: |
Before opening a bug report, please search for the behaviour in the existing issues.
Before opening a bug report, please search for the behaviour in existing issues or discussions.
---
@ -17,7 +17,7 @@ body:
description: "Which exact version of git-auto-commit are you using in your Workflow?"
placeholder: "v4.14.0"
validations:
required: true
required: true
- type: dropdown
id: machine
attributes:
@ -33,7 +33,7 @@ body:
id: bug-description
attributes:
label: Bug description
description: What exactly happened?
description: What exactly happened? Please describe your problem in detail.
validations:
required: true
- type: textarea
@ -52,7 +52,7 @@ body:
id: example-workflow
attributes:
label: Example Workflow
description: Please share your GitHub Actions workflow which causes the bug. We use this to reproduce the error. No need for backticks here.
description: Please share the YAML-code of your GitHub Actions workflow which causes the bug. We use this to reproduce the error. If the workflow is in a private repostory, please provide a minimal example. (No need for backticks here, the pasted code will be correctly formatted.)
render: yaml
validations:
required: true
@ -60,5 +60,10 @@ body:
id: logs
attributes:
label: Relevant log output
description: If applicable, provide relevant log output. No need for backticks here.
description: If applicable, provide relevant log output. Please copy and paste the output here, and make sure to remove any sensitive information. (No need for backticks here, the pasted code will be correctly formatted.)
render: shell
- type: input
id: repository-url
attributes:
label: Repository
description: If applicable, please provide the repository where the bug occurred.

View File

@ -4,5 +4,5 @@ contact_links:
url: https://github.com/stefanzweifel/git-auto-commit-action/discussions/new?category=help
about: If you can't get something to work the way you expect, open a question in our discussion forums.
- name: Feature Request
url: https://github.com/tailwindlabs/tailwindcss/discussions/new?category=ideas
url: https://github.com/stefanzweifel/git-auto-commit-action/discussions/new?category=ideas
about: 'Suggest any ideas you have using our discussion forums.'

10
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

View File

@ -12,7 +12,7 @@ categories:
- 'changelog:changed'
- title: Deprecated
labels:
- 'changelog:deprecated '
- 'changelog:deprecated'
- title: Removed
labels:
- 'changelog:removed'

View File

@ -10,17 +10,22 @@ jobs:
git-auto-commit:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission.
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use git-auto-commit-action
id: "auto-commit-action"
uses: ./
- name: "no changes detected"
if: steps.auto-commit-action.outputs.changes_detected == false
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
if: steps.auto-commit-action.outputs.changes_detected == 'true'
run: "echo \"Changes detected\""

View File

@ -9,10 +9,10 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Lint Code Base
uses: github/super-linter@v3
uses: github/super-linter@v7
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: false

View File

@ -8,7 +8,13 @@ on:
jobs:
update_release_draft:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission.
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
contents: write
steps:
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install testing dependencies
run: yarn install

View File

@ -8,9 +8,15 @@ jobs:
update:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# updated CHANGELOG back to the repository.
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: master
@ -21,7 +27,7 @@ jobs:
latest-version: ${{ github.event.release.name }}
- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: master
commit_message: Update CHANGELOG

View File

@ -7,6 +7,12 @@ on:
jobs:
actions-tagger:
runs-on: windows-latest
permissions:
# Give the default GITHUB_TOKEN write permission.
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
contents: write
steps:
- uses: Actions-R-Us/actions-tagger@latest
env:

View File

@ -5,10 +5,83 @@ 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.15.1...HEAD)
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v5.0.1...HEAD)
> TBD
## [v5.0.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v5.0.0...v5.0.1) - 2024-04-12
### Fixed
- Fail if attempting to execute git commands in a directory that is not a git-repo. ([#326](https://github.com/stefanzweifel/git-auto-commit-action/pull/326)) [@ccomendant](https://github.com/@ccomendant)
### Dependency Updates
- Bump bats from 1.10.0 to 1.11.0 ([#325](https://github.com/stefanzweifel/git-auto-commit-action/pull/325)) [@dependabot](https://github.com/@dependabot)
- Bump release-drafter/release-drafter from 5 to 6 ([#319](https://github.com/stefanzweifel/git-auto-commit-action/pull/319)) [@dependabot](https://github.com/@dependabot)
### Misc
- Clarify `commit_author` input option ([#315](https://github.com/stefanzweifel/git-auto-commit-action/pull/315)) [@npanuhin](https://github.com/@npanuhin)
- Add step id explanation for output in README.md ([#324](https://github.com/stefanzweifel/git-auto-commit-action/pull/324)) [@ChristianVermeulen](https://github.com/@ChristianVermeulen)
- Linux is not UNIX ([#321](https://github.com/stefanzweifel/git-auto-commit-action/pull/321)) [@couling](https://github.com/@couling)
## [v5.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.16.0...v5.0.0) - 2023-10-06
New major release that bumps the default runtime to Node 20. There are no other breaking changes.
### Changed
- Update node version to node20 ([#300](https://github.com/stefanzweifel/git-auto-commit-action/pull/300)) [@ryudaitakai](https://github.com/@ryudaitakai)
- Add _log and _set_github_output functions ([#273](https://github.com/stefanzweifel/git-auto-commit-action/pull/273)) [@stefanzweifel](https://github.com/@stefanzweifel)
### Fixed
- Seems like there is an extra space ([#288](https://github.com/stefanzweifel/git-auto-commit-action/pull/288)) [@pedroamador](https://github.com/@pedroamador)
- Fix git-auto-commit.yml ([#277](https://github.com/stefanzweifel/git-auto-commit-action/pull/277)) [@zcong1993](https://github.com/@zcong1993)
### Dependency Updates
- Bump actions/checkout from 3 to 4 ([#302](https://github.com/stefanzweifel/git-auto-commit-action/pull/302)) [@dependabot](https://github.com/@dependabot)
- Bump bats from 1.9.0 to 1.10.0 ([#293](https://github.com/stefanzweifel/git-auto-commit-action/pull/293)) [@dependabot](https://github.com/@dependabot)
- Bump github/super-linter from 4 to 5 ([#289](https://github.com/stefanzweifel/git-auto-commit-action/pull/289)) [@dependabot](https://github.com/@dependabot)
- Bump bats from 1.8.2 to 1.9.0 ([#282](https://github.com/stefanzweifel/git-auto-commit-action/pull/282)) [@dependabot](https://github.com/@dependabot)
## [v4.16.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.4...v4.16.0) - 2022-12-02
### Changed
- Don't commit files when only LF/CRLF changes ([#265](https://github.com/stefanzweifel/git-auto-commit-action/pull/265)) [@ZeroRin](https://github.com/@ZeroRin)
- Update default email address of github-actions[bot] ([#264](https://github.com/stefanzweifel/git-auto-commit-action/pull/264)) [@Teko012](https://github.com/@Teko012)
### Fixed
- Fix link and text for workflow limitation ([#263](https://github.com/stefanzweifel/git-auto-commit-action/pull/263)) [@Teko012](https://github.com/@Teko012)
## [v4.15.4](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.3...v4.15.4) - 2022-11-05
### Fixed
- Let Action fail if git binary can't be located ([#261](https://github.com/stefanzweifel/git-auto-commit-action/pull/261)) [@stefanzweifel](https://github.com/@stefanzweifel)
### Dependency Updates
- Bump github/super-linter from 3 to 4 ([#258](https://github.com/stefanzweifel/git-auto-commit-action/pull/258)) [@dependabot](https://github.com/@dependabot)
- Bump bats from 1.7.0 to 1.8.2 ([#259](https://github.com/stefanzweifel/git-auto-commit-action/pull/259)) [@dependabot](https://github.com/@dependabot)
- Bump actions/checkout from 2 to 3 ([#257](https://github.com/stefanzweifel/git-auto-commit-action/pull/257)) [@dependabot](https://github.com/@dependabot)
## [v4.15.3](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.2...v4.15.3) - 2022-10-26
### Changed
- Use deprecated set-output syntax if GITHUB_OUTPUT environment is not available ([#255](https://github.com/stefanzweifel/git-auto-commit-action/pull/255)) [@stefanzweifel](https://github.com/@stefanzweifel)
## [v4.15.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.1...v4.15.2) - 2022-10-22
### Changed
- Replace set-output usage with GITHUB_OUTPUT ([#252](https://github.com/stefanzweifel/git-auto-commit-action/pull/252)) [@amonshiz](https://github.com/amonshiz)
## [v4.15.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.0...v4.15.1) - 2022-10-10
### Fixed

View File

@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at hello@stefanzweifel.io. All
reported by contacting the project team at stefan@stefanzweifel.dev. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.

301
README.md
View File

@ -13,19 +13,50 @@ If you want to learn more how this Action works under the hood, check out [this
## Usage
Add the following step at the end of your job, after other steps that might add or change files.
Adding git-auto-commit to your Workflow only takes a couple lines of code.
1. Set the `contents`-permission of the default GITHUB_TOKEN to `true`. (Required to push new commits to the repository)
2. 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
- uses: stefanzweifel/git-auto-commit-action@v5
```
Note that the Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`).
If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the `contents: write` permission.
Your Workflow should look similar to this example.
```yaml
name: Format
on: push
jobs:
format-code:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
# Other steps that change files in the repository go here
# …
# Commit all changed files back to the repository
- uses: stefanzweifel/git-auto-commit-action@v5
```
> [!NOTE]
> The Action has to be used in a Job that runs on a UNIX-like system (e.g. `ubuntu-latest`).
The following is an extended example with all available options.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
@ -53,8 +84,8 @@ The following is an extended example with all available options.
# Optional commit user and author settings
commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]"
commit_user_email: my-github-actions-bot@example.org # defaults to "github-actions[bot]@users.noreply.github.com"
commit_author: Author <actions@github.com> # defaults to author of the commit that triggered the run
commit_user_email: my-github-actions-bot@example.org # defaults to "41898282+github-actions[bot]@users.noreply.github.com"
commit_author: Author <actions@github.com> # defaults to "username <username@users.noreply.github.com>", where "username" belongs to the author of the commit that triggered the run
# Optional. Tag name being created in the local repository and
# pushed to remote repository and defined branch.
@ -111,15 +142,19 @@ jobs:
php-cs-fixer:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply php-cs-fixer changes
```
@ -135,9 +170,16 @@ You can use these outputs to trigger other Actions in your Workflow run based on
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
- `commit_hash`: Returns the full hash of the commit if one was created.
**⚠️ When using outputs, the step needs to be given an id. See example below.**
### Example
```yaml
- uses: stefanzweifel/git-auto-commit-action@v5
id: auto-commit-action #mandatory for the output to show up in ${{ steps }}
with:
commit_message: Apply php-cs-fixer changes
- name: "Run if changes have been detected"
if: steps.auto-commit-action.outputs.changes_detected == 'true'
run: echo "Changes!"
@ -169,7 +211,7 @@ You must use `action/checkout@v2` or later versions to check out the repository.
In non-`push` events, such as `pull_request`, make sure to specify the `ref` to check out:
```yaml
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
```
@ -187,35 +229,117 @@ You can change this by creating a new [Personal Access Token (PAT)](https://gith
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
- uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
```
If you create a personal access token, apply the `repo` and `workflow` scopes.
If you create a personal access token (classic), apply the `repo` and `workflow` scopes.
If you create a fine-grained personal access token, apply the `Contents`-permissions.
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.
### Prevent Infinite Loop when using a Personal Access Token
If you're using a Personal Access Token (PAT) to push commits to GitHub repository, the resulting commit or push can trigger other GitHub Actions workflows. This can result in an infinite loop.
If you would like to prevent this, you can add `skip-checks:true` to the commit message. See [Skipping workflow runs](https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs) for details.
### Change to file is not detected
Does your workflow change a file but "git-auto-commit" does not detect the change? Check the `.gitignore` that applies to the respective file. You might have accidentally marked the file to be ignored by git.
Does your workflow change a file, but "git-auto-commit" does not detect the change? Check the `.gitignore` that applies to the respective file. You might have accidentally marked the file to be ignored by git.
## Advanced Uses
<details>
<summary>Use in forks from public repositories</summary>
### Multiline Commit Messages
**☝️ Important Notice**: This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\
If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch.
If your commit message should span multiple lines, you have to create a separate step to generate the string.
---
The example below can be used as a starting point to generate a multiline commit meesage. Learn more how multiline strings in GitHub Actions work in the [GitHub documentation](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings).
```yaml
# Building a multiline commit message
# Adjust to your liking
- run: echo "Commit Message 1" >> commitmessage.txt
- run: echo "Commit Message 2" >> commitmessage.txt
- run: echo "Commit Message 3" >> commitmessage.txt
# Create a multiline string to be used by the git-auto-commit Action
- name: Set commit message
id: commit_message_step
run: |
echo 'commit_message<<EOF' >> $GITHUB_OUTPUT
cat commitmessage.txt >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
# Quick and dirty step to get rid of the temporary file holding the commit message
- run: rm -rf commitmessage.txt
- uses: stefanzweifel/git-auto-commit-action@v5
id: commit
with:
commit_message: ${{ steps.commit_message_step.outputs.commit_message }}
```
### Signing Commits
If you would like to sign your commits using a GPG key, you will need to use an additional action.
You can use the [crazy-max/ghaction-import-gpg](https://github.com/crazy-max/ghaction-import-gpg) action and follow its setup instructions.
As git-auto-commit by default does not use **your** username and email when creating a commit, you have to override these values in your workflow.
```yml
- name: "Import GPG key"
id: import-gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: "Commit and push changes"
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_author: "${{ steps.import-gpg.outputs.name }} <${{ steps.import-gpg.outputs.email }}>"
commit_user_name: ${{ steps.import-gpg.outputs.name }}
commit_user_email: ${{ steps.import-gpg.outputs.email }}
```
See discussion [#334](https://github.com/stefanzweifel/git-auto-commit-action/discussions/334) for details.
### Use in 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.
### Use in forks from public repositories
> [!NOTE]
> This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\
> Ensure your contributors enable "Allow edits by maintainers" when opening a pull request. ([Learn more](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)) \
> \
> **If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch.**
> [!WARNING]
> Due to limitations of GitHub, this Action currently can't push commits to a base repository, if the fork _lives_ under an organisation. See [github/community#6634](https://github.com/orgs/community/discussions/5634) and [this comment](https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1428849944) for details.
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.)
However, there are a couple of ways to use this Actions in Workflows that should be triggered by forked repositories.
### Workflow should run in **base** repository
The workflow below runs whenever a commit is pushed to the `main`-branch or when activity on a pull request happens, by listening to the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event.
> [!CAUTION]
> The following section explains how you can use git-auto-commit in combination with the `pull_request_target` trigger.
> **Using `pull_request_target` in your workflows can lead to repository compromise as [mentioned](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) by GitHub's own security team. This means, that a bad actor could potentially leak/steal your GitHub Actions repository secrets.**
> Please be aware of this risk when using `pull_request_target` in your workflows.
>
> If your workflow runs code-fixing tools, consider running the workflow on your default branch by listening to the `push` event or use a third-party tool like [autofix.ci](https://autofix.ci/).
> We keep this documentation around, as many questions came in over the years, on how to use this action for public forks.
The workflow below runs whenever a commit is pushed to the `main`-branch or when activity on a pull request happens, by listening to the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event.
If the workflow is triggered by the `pull_request_target`-event, the workflow will run in the context of the base of the pull request, rather than in the context of the merge commit, as the `pull_request` event does.
In other words, this will allow your workflow to be run in the repository where the pull request is opened to and will push changes back to the fork.
@ -234,108 +358,47 @@ on:
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# Checkout the fork/head-repository and push changes to the fork.
# If you skip this, the base repository will be checked out and changes
# will be committed to the base repository!
repository: ${{ github.event.pull_request.head.repo.full_name }}
# Checkout the branch made in the fork. Will automatically push changes
# back to this branch.
ref: ${{ github.head_ref }}
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
```
### Workflow should run in **forked** repository
If the workflow should run in the forked repository, follow these steps:
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: [push, pull_request, pull_request_target]
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
with:
commit_message: Apply php-cs-fixer changes
```
Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the **forked** repository and will push commits to the same branch.
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 run linters and fixers (like the example above) we recommend running them when a push happens on the `main`-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/).
</details>
<details>
<summary>Push to forks from private repositories</summary>
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.
</details>
<details>
<summary>
Signing Commits & Other Git Command Line Options
</summary>
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 regularly.
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
</details>
<details>
<summary>
Using `--amend` and `--no-edit` as commit options
</summary>
### Using `--amend` and `--no-edit` as commit options
If you would like to use this Action to create a commit using [`--amend`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend) and [`--no-edit`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-edit) you need to make some adjustments.
**☝️ Important Notice:** You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase)
> [!CAUTION]
> You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase).
First, you need to extract the previous commit message by using `git log -1 --pretty=%s`.
Then you need to provide this last commit message to the Action through the `commit_message` input option.
By default, the commit author is changed to `username <username@users.noreply.github.com>`, where `username` is the name of the user who triggered the workflow (The [`github.actor`](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) context is used here). If you want to preserve the name and email of the original author, you must extract them from the last commit and provide them to the Action through the `commit_author` input option.
Finally, you have to use `push_options: '--force'` to overwrite the git history on the GitHub remote repository. (git-auto-commit will not do a `git-rebase` for you!)
The steps in your workflow might look like this:
```yaml
- uses: actions/checkout@master
- uses: actions/checkout@4
with:
# Fetch the last 2 commits instead of just 1. (Fetching just 1 commit would overwrite the whole history)
fetch-depth: 2
@ -343,13 +406,15 @@ The steps in your workflow might look like this:
# Other steps in your workflow to trigger a changed file
- name: Get last commit message
id: last-commit-message
id: last-commit
run: |
echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
echo "author=$(git log -1 --pretty=\"%an <%ae>\")" >> $GITHUB_OUTPUT
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: ${{ steps.last-commit-message.outputs.msg }}
commit_author: ${{ steps.last-commit.outputs.author }}
commit_message: ${{ steps.last-commit.outputs.message }}
commit_options: '--amend --no-edit'
push_options: '--force'
skip_fetch: true
@ -357,8 +422,6 @@ The steps in your workflow might look like this:
See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details.
</details>
## Troubleshooting
### Action does not push commit to repository
@ -371,27 +434,39 @@ please update your Workflow configuration and usage of [`actions/checkout`](http
Updating the `token` value with a Personal Access Token should fix your issues.
### git-auto-commit fails to push commit that creates or updates files in `.github/workflows/`
The default `GITHUB_TOKEN` issued by GitHub Action does not have permission to make changes to workflow files located in `.github/workflows/`.
To fix this, please create a personal access token (PAT) and pass the token to the `actions/checkout`-step in your workflow. (Similar to [how to push to protected branches](https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#push-to-protected-branches)).
If a PAT does not work for you, you could also create a new GitHub app and use it's token in your workflows. See [this comment in #87](https://github.com/stefanzweifel/git-auto-commit-action/issues/87#issuecomment-1939138661) for details.
See [#322](https://github.com/stefanzweifel/git-auto-commit-action/issues/322) for details and discussions around this topic.
### 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 make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Access Token needs to belong to an Administrator.
If your repository uses [protected branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches) you have to make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Access Token needs to belong to an Administrator.
First, 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.
If you create a personal access token (classic), apply the `repo` and `workflow` scopes.
If you create a fine-grained personal access token, apply the `Contents`-permissions.
```yaml
- uses: actions/checkout@v2
- uses: actions/checkout@v4
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.
> [!TIP]
> 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.
If you go the "force pushes" route, 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.
If you go the "force pushes" route, 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
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply php-cs-fixer changes
push_options: --force
@ -399,11 +474,11 @@ If you go the "force pushes" route, you have to enable force pushes to a protect
### 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).
This is due to limitations set up by GitHub, [commits made by this Action do not trigger new Workflow runs](#commits-made-by-this-action-do-not-trigger-new-workflow-runs).
### Pathspec 'x' did not match any files
If you're using the Action with a custom `file_pattern` and the Action throws a fatal error with the message "Pathspec 'file-pattern' did not match any files", the problem is probably that no file for the pattern exists in the repository.
If you're using the Action with a custom `file_pattern` and the Action throws a fatal error with the message "Pathspec 'file-pattern' did not match any files", the problem is probably that no file for the pattern **exists** in the repository.
`file_pattern` is used both for `git-status` and `git-add` in this Action. `git-add` will throw a fatal error, if for example, you use a file pattern like `*.js *.ts` but no `*.ts` files exist in your projects' repository.
@ -421,7 +496,7 @@ This is due to the fact, that the `*.md`-glob is expanded before sending it to `
To fix this add `disable_globbing: true` to your Workflow.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: '*.md'
disable_globbing: true
@ -449,7 +524,7 @@ yarn test
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.
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@v5` 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).)
## Credits

View File

@ -1,7 +1,7 @@
name: Git Auto Commit
description: 'Automatically commits files which have been changed during the workflow run and push changes back to remote repository.'
author: Stefan Zweifel <hello@stefanzweifel.io>
author: Stefan Zweifel <stefan@stefanzweifel.dev>
inputs:
commit_message:
@ -39,7 +39,7 @@ inputs:
commit_user_email:
description: Email address used for the commit user
required: false
default: github-actions[bot]@users.noreply.github.com
default: 41898282+github-actions[bot]@users.noreply.github.com
commit_author:
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
required: false
@ -70,6 +70,9 @@ inputs:
create_branch:
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
default: false
internal_git_binary:
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
default: git
outputs:
changes_detected:
@ -78,7 +81,7 @@ outputs:
description: Full hash of the created commit. Only present if the "changes_detected" output is "true".
runs:
using: 'node16'
using: 'node20'
main: 'index.js'
branding:

View File

@ -6,30 +6,69 @@ if "$INPUT_DISABLE_GLOBBING"; then
set -o noglob;
fi
_set_github_output() {
local name=${1}
local value=${2}
# Check if $GITHUB_OUTPUT is available
# (Feature detection will be removed in spring 2023)
if [ -z ${GITHUB_OUTPUT+x} ]; then
echo "::set-output name=$name::$value";
else
echo "$name=$value" >> $GITHUB_OUTPUT;
fi
}
_log() {
local level=${1}
local message=${2}
echo "::$level::$message";
}
_main() {
_check_if_git_is_available
_switch_to_repository
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
echo "changes_detected=true" >> $GITHUB_OUTPUT;
_set_github_output "changes_detected" "true"
_switch_to_branch
_add_files
_local_commit
# Check dirty state of repo again using git-diff.
# (git-diff detects better if CRLF of files changes and does NOT
# proceed, if only CRLF changes are detected. See #241 and #265
# for more details.)
if [ -n "$(git diff --staged)" ] || "$INPUT_SKIP_DIRTY_CHECK"; then
_local_commit
_tag_commit
_tag_commit
_push_to_github
_push_to_github
else
_set_github_output "changes_detected" "false"
echo "Working tree clean. Nothing to commit.";
fi
else
echo "changes_detected=false" >> $GITHUB_OUTPUT;
_set_github_output "changes_detected" "false"
echo "Working tree clean. Nothing to commit.";
fi
}
_check_if_git_is_available() {
if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then
_log "debug" "git binary found.";
else
_log "error" "git-auto-commit could not find git binary. Please make sure git is available."
exit 1;
fi
}
_switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
@ -38,13 +77,20 @@ _switch_to_repository() {
_git_is_dirty() {
echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}";
echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}";
_log "debug" "Apply status options ${INPUT_STATUS_OPTIONS}";
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN";
# capture stderr
gitStatusMessage="$((git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}} >/dev/null ) 2>&1)";
# shellcheck disable=SC2086
[ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ]
gitStatus="$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})";
if [ $? -ne 0 ]; then
_log "error" "git-status failed with:<$gitStatusMessage>";
exit 1;
fi
[ -n "$gitStatus" ]
}
_switch_to_branch() {
@ -52,14 +98,14 @@ _switch_to_branch() {
# Fetch remote to make sure that repo can be switched to the right branch.
if "$INPUT_SKIP_FETCH"; then
echo "::debug::git-fetch has not been executed";
_log "debug" "git-fetch will not be executed.";
else
git fetch --depth=1;
fi
# If `skip_checkout`-input is true, skip the entire checkout step.
if "$INPUT_SKIP_CHECKOUT"; then
echo "::debug::git-checkout has not been executed";
_log "debug" "git-checkout will not be executed.";
else
# Create new local branch if `create_branch`-input is true
if "$INPUT_CREATE_BRANCH"; then
@ -75,7 +121,7 @@ _switch_to_branch() {
_add_files() {
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}";
_log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN";
@ -86,7 +132,7 @@ _add_files() {
_local_commit() {
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}";
echo "::debug::Apply commit options ${INPUT_COMMIT_OPTIONS}";
_log "debug" "Apply commit options ${INPUT_COMMIT_OPTIONS}";
# shellcheck disable=SC2206
INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS );
@ -101,7 +147,7 @@ _local_commit() {
--author="$INPUT_COMMIT_AUTHOR" \
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT;
_set_github_output "commit_hash" $(git rev-parse HEAD)
}
_tag_commit() {
@ -109,7 +155,7 @@ _tag_commit() {
if [ -n "$INPUT_TAGGING_MESSAGE" ]
then
echo "::debug::Create tag $INPUT_TAGGING_MESSAGE";
_log "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.";
@ -119,7 +165,7 @@ _tag_commit() {
_push_to_github() {
echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS}";
echo "::debug::Apply push options ${INPUT_PUSH_OPTIONS}";
_log "debug" "Apply push options ${INPUT_PUSH_OPTIONS}";
# shellcheck disable=SC2206
INPUT_PUSH_OPTIONS_ARRAY=( $INPUT_PUSH_OPTIONS );
@ -129,15 +175,15 @@ _push_to_github() {
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
if [ -n "$INPUT_TAGGING_MESSAGE" ]
then
echo "::debug::git push origin --tags";
_log "debug" "git push origin --tags";
git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
else
echo "::debug::git push origin";
_log "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";
_log "debug" "Push commit to remote branch $INPUT_BRANCH";
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
fi
}

View File

@ -1,6 +1,6 @@
{
"devDependencies": {
"bats": "^1.1.0",
"bats": "^1.11.0",
"bats-assert": "ztombol/bats-assert",
"bats-support": "ztombol/bats-support"
},

View File

@ -8,6 +8,7 @@ setup() {
export FAKE_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/tests_local_repository"
export FAKE_REMOTE="${BATS_TEST_DIRNAME}/tests_remote_repository"
export FAKE_TEMP_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/tests_clone_of_remote_repository"
export FAKE_FOLDER_WITHOUT_GIT_REPO="/tmp/tests_folder_without_git_repo"
# While it is likely the GitHub hosted runners will use master as the default branch,
# locally anyone may change that. So for tests lets grab whatever is currently set
@ -37,6 +38,7 @@ setup() {
export INPUT_SKIP_CHECKOUT=false
export INPUT_DISABLE_GLOBBING=false
export INPUT_CREATE_BRANCH=false
export INPUT_INTERNAL_GIT_BINARY=git
# Set GitHub environment variables used by the GitHub Action
temp_github_output_file=$(mktemp -t github_output_test.XXXXX)
@ -57,7 +59,13 @@ teardown() {
rm -rf "${FAKE_LOCAL_REPOSITORY}"
rm -rf "${FAKE_REMOTE}"
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
rm "${GITHUB_OUTPUT}"
rm -rf "${INPUT_REPOSITORY}"
if [ -z ${GITHUB_OUTPUT+x} ]; then
echo "GITHUB_OUTPUT is not set"
else
rm "${GITHUB_OUTPUT}"
fi
}
# Create a fake remote repository which tests can push against
@ -253,7 +261,7 @@ cat_github_output() {
}
@test "It applies commit user and author settings" {
INPUT_COMMIT_USER_NAME="A Single Test"
INPUT_COMMIT_USER_NAME="Custom User Name"
INPUT_COMMIT_USER_EMAIL="single-test@github.com"
INPUT_COMMIT_AUTHOR="A Single Test <single@users.noreply.github.com>"
@ -263,7 +271,7 @@ cat_github_output() {
assert_success
assert_line "INPUT_COMMIT_USER_NAME: A Single Test"
assert_line "INPUT_COMMIT_USER_NAME: Custom User Name"
assert_line "INPUT_COMMIT_USER_EMAIL: single-test@github.com"
assert_line "INPUT_COMMIT_AUTHOR: A Single Test <single@users.noreply.github.com>"
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
@ -276,7 +284,7 @@ cat_github_output() {
assert_output --partial "A Single Test"
run git log -1 --pretty=format:'%cn'
assert_output --partial "A Single Test"
assert_output --partial "Custom User Name"
run git log -1 --pretty=format:'%ce'
assert_output --partial "single-test@github.com"
@ -411,7 +419,7 @@ cat_github_output() {
assert_success
assert_line "::debug::git-fetch has not been executed"
assert_line "::debug::git-fetch will not be executed."
}
@test "If SKIP_CHECKOUT is true git-checkout will not be called" {
@ -424,7 +432,7 @@ cat_github_output() {
assert_success
assert_line "::debug::git-checkout has not been executed"
assert_line "::debug::git-checkout will not be executed."
}
@test "It pushes generated commit and tag to remote and actually updates the commit shas" {
@ -968,7 +976,7 @@ cat_github_output() {
assert_line --partial "another-subdirectory/new-file-3.txt"
}
@test "fails to detect crlf change in files and does not detect change or commit changes" {
@test "detects if crlf in files change and does not create commit" {
# Set autocrlf to true
cd "${FAKE_LOCAL_REPOSITORY}"
git config core.autocrlf true
@ -976,24 +984,144 @@ cat_github_output() {
assert_line "true"
# Add more .txt files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to add new files to repository
run git_auto_commit
# Change control characters in files
sed 's/^M$//' "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
sed 's/$/^M/' "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to commit the 2 changes files
run git_auto_commit
assert_success
# Changes are not detected
assert_line --partial "Working tree clean. Nothing to commit."
refute_line --partial "2 files changed, 2 insertions(+), 2 deletions(-)"
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
refute_line --partial "new-file-2.txt"
refute_line --partial "new-file-3.txt"
assert_line --partial "Working tree clean. Nothing to commit."
assert_line --partial "new-file-2.txt"
assert_line --partial "new-file-3.txt"
# Changes are not detected
run cat_github_output
assert_line "changes_detected=false"
}
@test "detects if crlf in files change and creates commit if the actual content of the files change" {
# Set autocrlf to true
cd "${FAKE_LOCAL_REPOSITORY}"
git config core.autocrlf true
run git config --get-all core.autocrlf
assert_line "true"
# Add more .txt files
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to add new files to repository
run git_auto_commit
# Change control characters in files
echo -ne "crlf test2\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
echo -ne "crlf test2\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to commit the 2 changes files
run git_auto_commit
assert_success
assert_line --partial "2 files changed, 2 insertions(+), 2 deletions(-)"
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
assert_line --partial "new-file-2.txt"
assert_line --partial "new-file-3.txt"
# Changes are detected
run cat_github_output
assert_line "changes_detected=true"
}
@test "It uses old set-output syntax if GITHUB_OUTPUT environment is not available when changes are committed" {
unset GITHUB_OUTPUT
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
run git_auto_commit
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "INPUT_BRANCH value: ${FAKE_DEFAULT_BRANCH}"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
assert_line "::debug::Apply commit options "
assert_line "INPUT_TAGGING_MESSAGE: "
assert_line "No tagging message supplied. No tag will be added."
assert_line "INPUT_PUSH_OPTIONS: "
assert_line "::debug::Apply push options "
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
}
@test "It uses old set-output syntax if GITHUB_OUTPUT environment is not available when no changes have been detected" {
unset GITHUB_OUTPUT
run git_auto_commit
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "Working tree clean. Nothing to commit."
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
}
@test "It fails hard if git is not available" {
INPUT_INTERNAL_GIT_BINARY=binary-does-not-exist
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
run git_auto_commit
assert_failure;
assert_line "::error::git-auto-commit could not find git binary. Please make sure git is available."
}
@test "It creates multi-line commit messages" {
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
COMMIT_MESSAGE=$(cat <<-END
this commit message
has multiple lines
END
)
INPUT_COMMIT_MESSAGE=$COMMIT_MESSAGE
run git_auto_commit
assert_success
# Assert last commit was signed off
run git log -n 1
assert_output --partial $COMMIT_MESSAGE
}
@test "It exits with error message if entrypoint.sh is being run not in a git repository" {
INPUT_REPOSITORY="${FAKE_FOLDER_WITHOUT_GIT_REPO}"
mkdir "${INPUT_REPOSITORY}"
run git_auto_commit
assert_failure;
assert_line "::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
}

View File

@ -10,7 +10,7 @@ bats-support@ztombol/bats-support:
version "0.3.0"
resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee"
bats@^1.1.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.7.0.tgz#caae958b1d211eda6b1322ac7792515de40165a2"
integrity sha512-pt5zjJQUB4+JI8Si+z/IAWc8yhMyhdZs6IXMCKgzF768dUIyW5xyBstWtDI5uGSa80v7UQOhh+w0GA4p4+01Bg==
bats@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.11.0.tgz#40281f021f5befcc10da54ed5674aa5b181f4953"
integrity sha512-qiKdnS4ID3bJ1MaEOKuZe12R4w+t+psJF0ICj+UdkiHBBoObPMHv8xmD3w6F4a5qwUyZUHS+413lxENBNy8xcQ==