From fc174e240685ba61fdc7422f02ea5edea2171e6a Mon Sep 17 00:00:00 2001 From: Chris Buckley Date: Mon, 10 Jan 2022 00:10:05 +0000 Subject: [PATCH 01/30] Add skip_checkout option --- README.md | 3 +++ action.yml | 4 ++++ entrypoint.sh | 10 +++++++--- tests/git-auto-commit.bats | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 246c3b8..c584d9d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,9 @@ The following is an extended example with all possible options available for thi # Optional. Skip internal call to `git fetch` skip_fetch: true + # Optional. Skip internal call to `git checkout` + skip_checkout: true + # Optional. Prevents the shell from expanding filenames. # Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html disable_globbing: true diff --git a/action.yml b/action.yml index 540b900..03a8557 100644 --- a/action.yml +++ b/action.yml @@ -60,6 +60,10 @@ inputs: description: Skip the call to git-fetch. required: false default: false + skip_checkout: + description: Skip the call to git-checkout. + required: false + default: false disable_globbing: description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html) default: false diff --git a/entrypoint.sh b/entrypoint.sh index 406f03f..0d87608 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -55,9 +55,13 @@ _switch_to_branch() { git fetch --depth=1; fi - # Switch to branch from current Workflow run - # shellcheck disable=SC2086 - git checkout $INPUT_BRANCH; + if "$INPUT_SKIP_CHECKOUT"; then + echo "::debug::git-checkout has not been executed"; + else + # Switch to branch from current Workflow run + # shellcheck disable=SC2086 + git checkout $INPUT_BRANCH; + fi } _add_files() { diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 654fb7c..bdadd35 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -24,6 +24,7 @@ setup() { export INPUT_PUSH_OPTIONS="" export INPUT_SKIP_DIRTY_CHECK=false export INPUT_SKIP_FETCH=false + export INPUT_SKIP_CHECKOUT=false export INPUT_DISABLE_GLOBBING=false # Configure Git @@ -381,6 +382,19 @@ git_auto_commit() { assert_line "::debug::git-fetch has not been executed" } +@test "If SKIP_CHECKOUT is true git-checkout will not be called" { + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt + + INPUT_SKIP_CHECKOUT=true + + run git_auto_commit + + assert_success + + assert_line "::debug::git-checkout has not been executed" +} + @test "It pushes generated commit and tag to remote and actually updates the commit shas" { INPUT_BRANCH="" INPUT_TAGGING_MESSAGE="v2.0.0" From c463ede7c351b825b604097cfd6173a39381babb Mon Sep 17 00:00:00 2001 From: stefanzweifel Date: Mon, 10 Jan 2022 19:27:51 +0000 Subject: [PATCH 02/30] Update CHANGELOG --- CHANGELOG.md | 79 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2eb0a..d368d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,235 +1,260 @@ # Changelog + 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.12.0...HEAD) +## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...HEAD) > TBD +## [v4.13.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...v4.13.0) - 2022-01-10 + +## Added + +- Add `skip_checkout` option (#197) @cmbuckley + +## Changed + +- Add note on minimum permissions to the docs (#180) @ericcornelissen ## [v4.12.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...v4.12.0) - 2021-09-10 ### Added -- Add `commit_hash` output [#172](https://github.com/stefanzweifel/git-auto-commit-action/pull/172) +- Add `commit_hash` output [#172](https://github.com/stefanzweifel/git-auto-commit-action/pull/172) ## [v4.11.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.10.0...v4.11.0) - 2021-05-03 ### Added -- Add `status_options` and `add_options` option [#156](https://github.com/stefanzweifel/git-auto-commit-action/pull/156) +- Add `status_options` and `add_options` option [#156](https://github.com/stefanzweifel/git-auto-commit-action/pull/156) ## [v4.10.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.9.2...v4.10.0) - 2021-04-12 ### Added -- Add `disable_globbing` option [#153](https://github.com/stefanzweifel/git-auto-commit-action/issues/153), [#154](https://github.com/stefanzweifel/git-auto-commit-action/pull/154) +- Add `disable_globbing` option [#153](https://github.com/stefanzweifel/git-auto-commit-action/issues/153), [#154](https://github.com/stefanzweifel/git-auto-commit-action/pull/154) ## [v4.9.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.9.1...v4.9.2) - 2021-03-04 ### Fixes -- Push created annotated tags to remote by using `--follow-tags` and `--atomic` instead of just `--tags` [#146](https://github.com/stefanzweifel/git-auto-commit-action/pull/146) +- Push created annotated tags to remote by using `--follow-tags` and `--atomic` instead of just `--tags` [#146](https://github.com/stefanzweifel/git-auto-commit-action/pull/146) ## [v4.9.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.9.0...v4.9.1) - 2021-02-23 ### Changed -- Revert changes made in v4.9.0. A branch will no longer be automatically generated. [#144](https://github.com/stefanzweifel/git-auto-commit-action/pull/144) +- Revert changes made in v4.9.0. A branch will no longer be automatically generated. [#144](https://github.com/stefanzweifel/git-auto-commit-action/pull/144) ## [v4.9.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.8.0...v4.9.0) - 2021-02-20 ### Changed -- Automatically create branch if a branch with the given name does not exist [#140](https://github.com/stefanzweifel/git-auto-commit-action/pull/140) +- Automatically create branch if a branch with the given name does not exist [#140](https://github.com/stefanzweifel/git-auto-commit-action/pull/140) ## [v4.8.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.2...v4.8.0) - 2020-12-15 ### Added + - Add `skip_fetch` option to skip the execution of `git-fetch` [#131](https://github.com/stefanzweifel/git-auto-commit-action/pull/131) ### Changed -- Update `git fetch` to only fetch the latest commit from remote [#131](https://github.com/stefanzweifel/git-auto-commit-action/pull/131) +- Update `git fetch` to only fetch the latest commit from remote [#131](https://github.com/stefanzweifel/git-auto-commit-action/pull/131) ## [v4.7.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.1...v4.7.2) - 2020-10-24 This release basically reverts the Action to the state of `v4.6.0`. ### Changed -- Revert change to fix git-checkout with special characters in branch names [#122](https://github.com/stefanzweifel/git-auto-commit-action/pull/122) +- Revert change to fix git-checkout with special characters in branch names [#122](https://github.com/stefanzweifel/git-auto-commit-action/pull/122) ## [v4.7.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.0...v4.7.1) - 2020-10-22 ### Removed -- Remove `checkout_options` as it broke everything [#120](https://github.com/stefanzweifel/git-auto-commit-action/pull/120/) +- Remove `checkout_options` as it broke everything [#120](https://github.com/stefanzweifel/git-auto-commit-action/pull/120/) ## [v4.7.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.6.0...v4.7.0) - 2020-10-21 ### Added -- Add `checkout_options` [#115](https://github.com/stefanzweifel/git-auto-commit-action/pull/115) +- Add `checkout_options` [#115](https://github.com/stefanzweifel/git-auto-commit-action/pull/115) ## [v4.6.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.5.1...v4.6.0) - 2020-10-11 ### Changed + - Make "commit_message" optional and set default commit message to "Apply automatic changes" [#103](https://github.com/stefanzweifel/git-auto-commit-action/issues/103), [#110](https://github.com/stefanzweifel/git-auto-commit-action/pull/110) ### Fixes -- Better support for branch names with special characters in them [#108](https://github.com/stefanzweifel/git-auto-commit-action/pull/108) +- Better support for branch names with special characters in them [#108](https://github.com/stefanzweifel/git-auto-commit-action/pull/108) ## [v4.5.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.5.0...v4.5.1) - 2020-09-11 ### Removed + - Remove orphan branch feature added in #95 which broke stuff [#98](https://github.com/stefanzweifel/git-auto-commit-action/pull/98) ## [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) +- 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) +- 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) +- 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) +- 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) +- Fix bug introduced in previous version, where git user configuration has been placed inline [#62](https://github.com/stefanzweifel/git-auto-commit-action/pull/62) ## [v4.1.3](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.2...v4.1.3) - 2020-04-18 ### Changed + - Place Git user configuration inline [#59](https://github.com/stefanzweifel/git-auto-commit-action/pull/59) ## [v4.1.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.1...v4.1.2) - 2020-04-03 ### Fixes + - Fix Issue with `changes_detected`-output [#57](https://github.com/stefanzweifel/git-auto-commit-action/pull/57) ## [v4.1.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.0...v4.1.1) - 2020-03-14 ### Fixes -- Fix issue where commit has not been pushed to remote repository, when no `branch`-option has been given [#54](https://github.com/stefanzweifel/git-auto-commit-action/pull/54) +- Fix issue where commit has not been pushed to remote repository, when no `branch`-option has been given [#54](https://github.com/stefanzweifel/git-auto-commit-action/pull/54) ## [v4.1.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.0.0...v4.1.0) - 2020-03-05 ### Added + - Add `changes_detected` output [#49](https://github.com/stefanzweifel/git-auto-commit-action/pull/49), [#46](https://github.com/stefanzweifel/git-auto-commit-action/issues/46) - Add `tagging_message` input option to create and push tags [#50](https://github.com/stefanzweifel/git-auto-commit-action/pull/50), [#47](https://github.com/stefanzweifel/git-auto-commit-action/issues/47) - ## [v4.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v3.0.0...v4.0.0) - 2020-02-24 ### Changed + - Switch Action to use `node12`-environment instead of `docker`. [#45](https://github.com/stefanzweifel/git-auto-commit-action/pull/45) ## [v3.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.5.0...v3.0.0) - 2020-02-06 ### Added + - Add `commit_user_name`, `commit_user_email` and `commit_author` input options for full customzation on how the commit is being created [#39](https://github.com/stefanzweifel/git-auto-commit-action/pull/39) ### Changed + - Make the `branch` input option optional [#41](https://github.com/stefanzweifel/git-auto-commit-action/pull/41) ### Removed -- Remove the need of a GITHUB_TOKEN. Users now have to use `actions/checkout@v2` or higher [#36](https://github.com/stefanzweifel/git-auto-commit-action/pull/36) +- Remove the need of a GITHUB_TOKEN. Users now have to use `actions/checkout@v2` or higher [#36](https://github.com/stefanzweifel/git-auto-commit-action/pull/36) ## [v2.5.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.4.0...v2.5.0) - 2019-12-18 ### Added + - Add new `repository`-argument [#22](https://github.com/stefanzweifel/git-auto-commit-action/pull/22) ### Changed -- Extract logic of the Action into methods and into a separate file [#24](https://github.com/stefanzweifel/git-auto-commit-action/pull/24) +- Extract logic of the Action into methods and into a separate file [#24](https://github.com/stefanzweifel/git-auto-commit-action/pull/24) ## [v2.4.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.3.0...v2.4.0) - 2019-11-30 ### Added + - Commit untracked files [#19](https://github.com/stefanzweifel/git-auto-commit-action/pull/19) (fixes [#16](https://github.com/stefanzweifel/git-auto-commit-action/issues/16)) - Add support for Git-LFS [#21](https://github.com/stefanzweifel/git-auto-commit-action/pull/21) (fixes [#20](https://github.com/stefanzweifel/git-auto-commit-action/issues/20)) - ## [v2.3.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.2.0...v2.3.0) - 2019-11-04 ### Added -- Add a new `commit_option`-argument. Allows users to define additional commit options for the `git-commit` command. [#14](https://github.com/stefanzweifel/git-auto-commit-action/pull/15) +- Add a new `commit_option`-argument. Allows users to define additional commit options for the `git-commit` command. [#14](https://github.com/stefanzweifel/git-auto-commit-action/pull/15) ## [v2.2.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.1.0...v2.2.0) - 2019-10-26 ### Added -- Add new `file_pattern`-argument. Allows users to define which files should be added in the commit. [#13](https://github.com/stefanzweifel/git-auto-commit-action/pull/13) +- Add new `file_pattern`-argument. Allows users to define which files should be added in the commit. [#13](https://github.com/stefanzweifel/git-auto-commit-action/pull/13) ## [v2.1.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.0.0...v2.1.0) - 2019-09-20 ### Added + - Add `branch`-argument to determine, to which branch changes should be pushed. See README for usage details. ### Fixed + - Fixes Issue where changes couldn't be pushed to GitHub due to wrong ref-name. ### Removed -- Remove `commit_author_email` and `commit_author_name` arguments. The `$GITHUB_ACTOR` is now used as the Git Author +- Remove `commit_author_email` and `commit_author_name` arguments. The `$GITHUB_ACTOR` is now used as the Git Author ## [v2.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v1.0.0...v2.0.0) - 2019-08-31 ### Changed -- Make Action Compatible with latest beta of GitHub Actions [#3](https://github.com/stefanzweifel/git-auto-commit-action/pull/3) +- Make Action Compatible with latest beta of GitHub Actions [#3](https://github.com/stefanzweifel/git-auto-commit-action/pull/3) ## v1.0.0 - 2019-06-10 ### Added - Add Core Logic for Action - From b244c3829309c04c2210a52681c50f25b183b2d5 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Mon, 10 Jan 2022 20:28:24 +0100 Subject: [PATCH 03/30] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d368d8b..002a4a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add `skip_checkout` option (#197) @cmbuckley -## Changed +## Changed - Add note on minimum permissions to the docs (#180) @ericcornelissen From af4930911628533bc669ef1ac181e4ff1ab96ece Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Tue, 11 Jan 2022 10:21:56 -0600 Subject: [PATCH 04/30] Properly disambiguate between branch or file checkout --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0d87608..a89bea4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -60,7 +60,7 @@ _switch_to_branch() { else # Switch to branch from current Workflow run # shellcheck disable=SC2086 - git checkout $INPUT_BRANCH; + git checkout $INPUT_BRANCH --; fi } From e3cb9ba079224bed2a8cd6aab37bffc62e4b0c7b Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 12 Jan 2022 21:05:06 +0100 Subject: [PATCH 05/30] Add Test Case --- tests/git-auto-commit.bats | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index bdadd35..2250496 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -507,3 +507,29 @@ git_auto_commit() { run git status assert_output --partial 'nothing to commit, working tree clean' } + +@test "It does not throw an error if branch is checked out with same name as a file or folder in the repo" { + + # Add File called dev and commit/push + echo "Create dev file"; + cd "${FAKE_LOCAL_REPOSITORY}"; + echo this is a file named dev > dev + git add dev + git commit -m 'add file named dev' + git update-ref refs/remotes/origin/master master + git update-ref refs/remotes/origin/dev master + + # --- + + INPUT_BRANCH=dev + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{4,5,6}.txt + + run git_auto_commit + + assert_success + + assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" + assert_line "::set-output name=changes_detected::true" + assert_line "::debug::Push commit to remote branch dev" +} From 8f6736864a0865fb29f1b3147a41f59cfa7ca670 Mon Sep 17 00:00:00 2001 From: stefanzweifel Date: Thu, 13 Jan 2022 18:17:02 +0000 Subject: [PATCH 06/30] Update CHANGELOG --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 002a4a9..7b94189 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,16 @@ 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.13.0...HEAD) +## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...HEAD) > TBD +## [v4.13.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...v4.13.1) - 2022-01-13 + +## Fixed + +- Properly disambiguate between branch or file checkout (#199) @kenodegard + ## [v4.13.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...v4.13.0) - 2022-01-10 ## Added From 22695fb19ef63e0c278f7e50beddd9a8d91a9abb Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Mon, 24 Jan 2022 15:55:20 +0100 Subject: [PATCH 07/30] README.md: Updates hyperlink to GH docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c584d9d..991a9b2 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ You have to do this to avoid that the `checkout`-Action clones your repository i ### Commits made by this Action do not trigger new Workflow runs The resulting commit **will not trigger** another GitHub Actions Workflow run. -This is due to [limitations set by GitHub](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). +This is due to [limitations set by GitHub](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#triggering-a-workflow-from-a-workflow). > 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. From 248fbacc3ea5152797eaa9fa53f6a76a7fe3ba1e Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Mon, 24 Jan 2022 16:51:53 +0100 Subject: [PATCH 08/30] Add note about scopes for PAT --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 991a9b2..f18675b 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,8 @@ storing the token as a secret in your repository and then passing the new token token: ${{ secrets.PAT }} ``` +If you create a personal access token, apply the `repo` and `workflow` scopes. + 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. ## Advanced Uses From dee58f4213fa2ce05f8b11b983fca79b01ab0b80 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 22 Feb 2022 20:02:04 +0100 Subject: [PATCH 09/30] Remove nbsp from entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a89bea4..3b0c85e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,7 +47,7 @@ _git_is_dirty() { _switch_to_branch() { echo "INPUT_BRANCH value: $INPUT_BRANCH"; - # Fetch remote to make sure that repo can be switched to the right 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"; From ebe77391c67c5fa6314697c01af103e3722b917c Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 27 Feb 2022 07:52:17 +0100 Subject: [PATCH 10/30] Add `create_branch` option to force create a new branch (#203) * Add create_branch option * Checkout new branch if create_branch input is true * Add tests * Update README --- README.md | 28 ++-- action.yml | 5 +- entrypoint.sh | 14 +- tests/git-auto-commit.bats | 257 +++++++++++++++++++++++++++++++++++++ 4 files changed, 287 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f18675b..e70737e 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,16 @@ The following is an extended example with all possible options available for thi ```yaml - uses: stefanzweifel/git-auto-commit-action@v4 with: - # Optional, but recommended + # Optional. Commit message for the created commit. # Defaults to "Apply automatic changes" commit_message: Automated Change - # Optional branch name where commit should be pushed to. - # Defaults to the current branch. + # Optional. Local and remote branch name where commit is going to be pushed + # to. Defaults to the current branch. + # You might need to set `create_branch: true` if the branch does not exist. branch: feature-123 - # Optional. Used by `git-commit`. + # Optional. Options used by `git-commit`. # See https://git-scm.com/docs/git-commit#_options commit_options: '--no-verify --signoff' @@ -47,8 +48,8 @@ The following is an extended example with all possible options available for thi # - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec file_pattern: src/*.js tests/*.js *.php - # Optional local file path to the repository - # Defaults to the root of the repository + # Optional. Local file path to the repository. + # Defaults to the root of the repository. repository: . # Optional commit user and author settings @@ -56,19 +57,19 @@ The following is an extended example with all possible options available for thi commit_user_email: my-github-actions-bot@example.org # defaults to "actions@github.com" commit_author: Author # defaults to author of the commit that triggered the run - # Optional tag message - # Action will create and push a new tag to the remote repository and the defined branch + # Optional. Tag name being created in the local repository and + # pushed to remtoe repository and defined branch. tagging_message: 'v1.0.0' - # Optional. Used by `git-status` - # See https://git-scm.com/docs/git-status#_options + # Optional. Option used by `git-status` to determine if the repository is + # dirty. See https://git-scm.com/docs/git-status#_options status_options: '--untracked-files=no' - # Optional. Used by `git-add` + # Optional. Options used by `git-add`. # See https://git-scm.com/docs/git-add#_options add_options: '-u' - # Optional. Used by `git-push` + # Optional. Options used by `git-push`. # See https://git-scm.com/docs/git-push#_options push_options: '--force' @@ -84,6 +85,9 @@ The following is an extended example with all possible options available for thi # Optional. Prevents the shell from expanding filenames. # Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html disable_globbing: true + + # Optional. Create given branch name in local and remote repository. + create_branch: true ``` Please note that the Action depends on `bash`. If you're using the Action in a job in combination with a custom Docker container, make sure that `bash` is installed. diff --git a/action.yml b/action.yml index 03a8557..0c30824 100644 --- a/action.yml +++ b/action.yml @@ -25,7 +25,7 @@ inputs: required: false default: '' file_pattern: - description: File pattern used for `git add`. For example `src/\*.js` + description: File pattern used for `git add`. For example `src/*.js` required: false default: '.' repository: @@ -67,6 +67,9 @@ inputs: disable_globbing: description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html) default: false + 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 outputs: changes_detected: diff --git a/entrypoint.sh b/entrypoint.sh index 3b0c85e..dee54a9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -48,19 +48,25 @@ _switch_to_branch() { echo "INPUT_BRANCH value: $INPUT_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"; 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"; else - # Switch to branch from current Workflow run - # shellcheck disable=SC2086 - git checkout $INPUT_BRANCH --; + # Create new local branch if `create_branch`-input is true + if "$INPUT_CREATE_BRANCH"; then + # shellcheck disable=SC2086 + git checkout -B $INPUT_BRANCH --; + else + # Switch to branch from current Workflow run + # shellcheck disable=SC2086 + git checkout $INPUT_BRANCH --; + fi fi } diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 2250496..da25586 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -26,6 +26,7 @@ setup() { export INPUT_SKIP_FETCH=false export INPUT_SKIP_CHECKOUT=false export INPUT_DISABLE_GLOBBING=false + export INPUT_CREATE_BRANCH=false # Configure Git if [[ -z $(git config user.name) ]]; then @@ -533,3 +534,259 @@ git_auto_commit() { assert_line "::set-output name=changes_detected::true" assert_line "::debug::Push commit to remote branch dev" } + +@test "script fails to push commit to new branch that does not exist yet" { + INPUT_BRANCH="not-existend-branch" + INPUT_CREATE_BRANCH=false + + run git branch + refute_line --partial "not-existend-branch" + + run git branch -r + refute_line --partial "origin/not-existend-branch" + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt + + run git_auto_commit + + assert_failure + + assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" + assert_line "::set-output name=changes_detected::true" + assert_line "INPUT_BRANCH value: not-existend-branch" + assert_line "fatal: invalid reference: not-existend-branch" + + run git branch + refute_line --partial "not-existend-branch" + + run git branch -r + refute_line --partial "origin/not-existend-branch" +} + +@test "It creates new local branch and pushes the new branch to remote" { + INPUT_BRANCH="not-existend-branch" + INPUT_CREATE_BRANCH=true + + run git branch + refute_line --partial "not-existend-branch" + + run git branch -r + refute_line --partial "origin/not-existend-branch" + + 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 "::set-output name=changes_detected::true" + assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$" + assert_line "INPUT_BRANCH value: not-existend-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 not-existend-branch" + + run git branch + assert_line --partial "not-existend-branch" + + run git branch -r + assert_line --partial "origin/not-existend-branch" +} + +@test "it does not create new local branch if local branch already exists" { + + git checkout -b not-existend-remote-branch + git checkout master + + INPUT_BRANCH="not-existend-remote-branch" + INPUT_CREATE_BRANCH=true + + run git branch + assert_line --partial "not-existend-remote-branch" + + run git branch -r + refute_line --partial "origin/not-existend-remote-branch" + + 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 "::set-output name=changes_detected::true" + assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$" + assert_line "INPUT_BRANCH value: not-existend-remote-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 not-existend-remote-branch" + + run git branch + assert_line --partial "not-existend-remote-branch" + + run git branch -r + assert_line --partial "origin/not-existend-remote-branch" +} + +@test "it creates new local branch and pushes branch to remote even if the remote branch already exists" { + + # Create `existing-remote-branch` on remote with changes the local repository does not yet have + cd $FAKE_TEMP_LOCAL_REPOSITORY; + git checkout -b "existing-remote-branch" + touch new-branch-file.txt + git add new-branch-file.txt + git commit -m "Add additional file"; + git push origin existing-remote-branch; + + run git branch; + assert_line --partial "existing-remote-branch" + + # --------- + # Switch to our regular local repository and run `git-auto-commit` + cd $FAKE_LOCAL_REPOSITORY; + + INPUT_BRANCH="existing-remote-branch" + INPUT_CREATE_BRANCH=true + + run git branch + refute_line --partial "existing-remote-branch" + + run git fetch --all; + run git pull origin existing-remote-branch; + run git branch -r; + assert_line --partial "origin/existing-remote-branch" + + 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 "::set-output name=changes_detected::true" + assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$" + assert_line "INPUT_BRANCH value: existing-remote-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 existing-remote-branch" + + run git branch + assert_line --partial "existing-remote-branch" + + run git branch -r + assert_line --partial "origin/existing-remote-branch" + + # Assert that branch "existing-remote-branch" was updated on remote + current_sha="$(git rev-parse --verify --short existing-remote-branch)" + remote_sha="$(git rev-parse --verify --short origin/existing-remote-branch)" + + assert_equal $current_sha $remote_sha; +} + +@test "script fails if new local branch is checked out and push fails as remote has newer commits than local" { + # Create `existing-remote-branch` on remote with changes the local repository does not yet have + cd $FAKE_TEMP_LOCAL_REPOSITORY; + git checkout -b "existing-remote-branch" + touch new-branch-file.txt + git add new-branch-file.txt + git commit -m "Add additional file"; + git push origin existing-remote-branch; + + run git branch; + assert_line --partial "existing-remote-branch" + + # --------- + # Switch to our regular local repository and run `git-auto-commit` + cd $FAKE_LOCAL_REPOSITORY; + + INPUT_BRANCH="existing-remote-branch" + INPUT_CREATE_BRANCH=true + + run git branch + refute_line --partial "existing-remote-branch" + + run git fetch --all; + run git branch -r; + assert_line --partial "origin/existing-remote-branch" + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt + + run git_auto_commit + + assert_failure + + assert_line "hint: Updates were rejected because the tip of your current branch is behind" + + # Assert that branch exists locally and on remote + run git branch + assert_line --partial "existing-remote-branch" + + run git branch -r + assert_line --partial "origin/existing-remote-branch" + + # Assert that branch "existing-remote-branch" was not updated on remote + current_sha="$(git rev-parse --verify --short existing-remote-branch)" + remote_sha="$(git rev-parse --verify --short origin/existing-remote-branch)" + + refute [assert_equal $current_sha $remote_sha]; +} + +@test "It pushes commit to remote if branch already exists and local repo is behind its remote counterpart" { + # Create `new-branch` on remote with changes the local repository does not yet have + cd $FAKE_TEMP_LOCAL_REPOSITORY; + + git checkout -b "new-branch" + touch new-branch-file.txt + git add new-branch-file.txt + + git commit --quiet -m "Add additional file"; + git push origin new-branch; + + run git branch -r + assert_line --partial "origin/new-branch" + + # --------- + # Switch to our regular local repository and run `git-auto-commit` + cd $FAKE_LOCAL_REPOSITORY; + + INPUT_BRANCH="new-branch" + + # Assert that local remote does not know have "new-branch" locally nor does + # know about the remote branch. + run git branch + refute_line --partial "new-branch" + + run git branch -r + refute_line --partial "origin/new-branch" + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt + + run git_auto_commit + + assert_success + + assert_line "INPUT_BRANCH value: new-branch" + assert_line --partial "::debug::Push commit to remote branch new-branch" + + # Assert that branch "new-branch" was updated on remote + current_sha="$(git rev-parse --verify --short new-branch)" + remote_sha="$(git rev-parse --verify --short origin/new-branch)" + + assert_equal $current_sha $remote_sha; +} From 19c7b84a3c3a6c94aa7aa94141d1217c79b1ccd6 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 27 Feb 2022 11:18:39 +0100 Subject: [PATCH 11/30] Update README --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e70737e..b04c72c 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ The following is an extended example with all possible options available for thi disable_globbing: true # Optional. Create given branch name in local and remote repository. + # (Not released yet, available when @master is used) create_branch: true ``` @@ -106,7 +107,7 @@ on: pull_request: push: branches: - - "main" + - main jobs: php-cs-fixer: @@ -154,9 +155,9 @@ The goal of this Action is to be "the Action for committing files for the 80% us The following is a list of edge cases the Action knowingly does not support: -**No `git pull` when the repository is out of the date with remote.** The will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs. +**No `git pull` when the repository is out of the date with remote.** The Action will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs. -**No support for running the Action in build matrices**. For example, if your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a `git pull` for you, you have to do that yourself. +**No support for running the Action in build matrices**. If your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a `git pull` for you, you have to do that yourself. **No support for `git rebase` or `git merge`**. There are many strategies on how to integrate remote upstream changes to a local repository. `git-auto-commit` does not want to be responsible for doing that. @@ -164,8 +165,8 @@ If this Action doesn't work for your workflow, check out [EndBug/add-and-commit] ### Checkout the correct branch -You must use `action/checkout@v2` or later versions to checkout the repository. -In non-`push` events, such as `pull_request`, make sure to specify the `ref` to checkout: +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 @@ -173,7 +174,7 @@ In non-`push` events, such as `pull_request`, make sure to specify the `ref` to ref: ${{ github.head_ref }} ``` -You have to do this to avoid that the `checkout`-Action clones your repository in a detached state. +Do this to avoid checking out the repository in a detached state. ### Commits made by this Action do not trigger new Workflow runs @@ -362,7 +363,7 @@ This is due to limitations set up by GitHub, [commits of this Action do not trig ## Running the tests -The package has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`. +The Action has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`. ```shell npm install From c4b132ec2c77a21fcab564bd3c92610cee84b894 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 27 Feb 2022 12:10:20 +0100 Subject: [PATCH 12/30] Update file_pattern related test --- tests/git-auto-commit.bats | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index da25586..ea53cad 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -186,7 +186,10 @@ git_auto_commit() { } @test "It applies INPUT_FILE_PATTERN when creating commit" { - INPUT_FILE_PATTERN="*.txt *.html" + INPUT_FILE_PATTERN="src/*.js *.txt *.html" + + mkdir src; + touch src/new-file-{1,2}.js; touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.html @@ -195,7 +198,7 @@ git_auto_commit() { assert_success - assert_line "INPUT_FILE_PATTERN: *.txt *.html" + assert_line "INPUT_FILE_PATTERN: src/*.js *.txt *.html" assert_line "::debug::Push commit to remote branch master" # Assert that PHP files have not been added. From 2719df73cd9f53ea26cbca737ba758532fda3ab8 Mon Sep 17 00:00:00 2001 From: stefanzweifel Date: Fri, 18 Mar 2022 19:29:58 +0000 Subject: [PATCH 13/30] Update CHANGELOG --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b94189..33d5458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,20 @@ 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.13.1...HEAD) +## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.0...HEAD) > TBD +## [v4.14.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...v4.14.0) - 2022-03-18 + +## Added + +- Add `create_branch` option to force create a new branch (#203) @stefanzweifel + +## Fixed + +- README.md: Updates hyperlink to GH docs (#200) @funkyfuture + ## [v4.13.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...v4.13.1) - 2022-01-13 ## Fixed From d0487b9fa3a792b5e90562c27541eedecc2548b4 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 19 Mar 2022 07:46:33 +0100 Subject: [PATCH 14/30] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index b04c72c..d6a99d4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ > The GitHub Action for committing files for the 80% use case. -Public workflows that use this action. @@ -87,7 +86,6 @@ The following is an extended example with all possible options available for thi disable_globbing: true # Optional. Create given branch name in local and remote repository. - # (Not released yet, available when @master is used) create_branch: true ``` From 30fd9f94bcc75ff514e7bd26fd3c6f5b3ab70aa9 Mon Sep 17 00:00:00 2001 From: Geoff Date: Wed, 23 Mar 2022 00:14:36 -0700 Subject: [PATCH 15/30] Update README.md (#206) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6a99d4..140d2b7 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ Do this to avoid checking out the repository in a detached state. ### Commits made by this Action do not trigger new Workflow runs The resulting commit **will not trigger** another GitHub Actions Workflow run. -This is due to [limitations set by GitHub](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#triggering-a-workflow-from-a-workflow). +This is due to [limitations set by GitHub](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow). > 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. From 73f17337ef94eb9524dd420ff11a97846ff3acb0 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Tue, 12 Apr 2022 20:30:34 +0200 Subject: [PATCH 16/30] Use github-actions[bot] user as commit user (#213) Fixes #212 --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 0c30824..09bce42 100644 --- a/action.yml +++ b/action.yml @@ -35,11 +35,11 @@ inputs: commit_user_name: description: Name used for the commit user required: false - default: GitHub Actions + default: github-actions[bot] commit_user_email: description: Email address used for the commit user required: false - default: actions@github.com + default: 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 From 49620cd3ed21ee620a48530e81dba0d139c9cb80 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 12 Apr 2022 20:33:36 +0200 Subject: [PATCH 17/30] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 140d2b7..b7a1e8c 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ The following is an extended example with all possible options available for thi repository: . # Optional commit user and author settings - commit_user_name: My GitHub Actions Bot # defaults to "GitHub Actions" - commit_user_email: my-github-actions-bot@example.org # defaults to "actions@github.com" + 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 # defaults to author of the commit that triggered the run # Optional. Tag name being created in the local repository and From 488db3d5039c2879d03cb74567b8215a01208a9e Mon Sep 17 00:00:00 2001 From: stefanzweifel Date: Tue, 12 Apr 2022 18:43:36 +0000 Subject: [PATCH 18/30] Update CHANGELOG --- CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d5458..5a5464a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,21 @@ 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.14.0...HEAD) +## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.1...HEAD) > TBD +## [v4.14.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.0...v4.14.1) - 2022-04-12 + +## Changed + +- Change Commit User Name from "GitHub Actions" to "github-actions[bot]" (#213) @jooola +- Change Commit User Email from "actions@github.com" to "github-actions[bot]@users.noreply.github.com" (#213) @jooola + +## Fixed + +- Update doc link to GITHUB_TOKEN not triggering new workflow runs (#206) @gapple + ## [v4.14.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...v4.14.0) - 2022-03-18 ## Added From 79ae6eea9571e6564ff5bc076266872207a5bdac Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 15 Apr 2022 20:06:11 +0200 Subject: [PATCH 19/30] Update README concerning pull_request_target trigger Closes #211 --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b7a1e8c..8ec3340 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Add the following step at the end of your job, after other steps that might add Note that the Action has to be used in a Job that runs on a UNIX system (eg. `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. -The following is an extended example with all possible options available for this Action. +The following is an extended example with all available options. ```yaml - uses: stefanzweifel/git-auto-commit-action@v4 @@ -153,7 +153,7 @@ The goal of this Action is to be "the Action for committing files for the 80% us The following is a list of edge cases the Action knowingly does not support: -**No `git pull` when the repository is out of the date with remote.** The Action will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs. +**No `git pull` when the repository is out of date with remote.** The Action will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs. **No support for running the Action in build matrices**. If your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a `git pull` for you, you have to do that yourself. @@ -204,9 +204,45 @@ If you use this Action in combination with a linter/fixer, it's easier if you ru --- -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.) +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. -If you want that a Workflow using this Action runs on Pull Requests opened by forks, 2 things have to be changed: +### 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. + +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. + +Check out the discussion in [#211](https://github.com/stefanzweifel/git-auto-commit-action/issues/211) for more information on this. + +```yaml +name: Format PHP + +on: + push: + branches: + - main + pull_request_target: + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + + - name: Run php-cs-fixer + uses: docker://oskarstark/php-cs-fixer-ga + + - uses: stefanzweifel/git-auto-commit-action@v4 +``` + +### 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. \ @@ -239,7 +275,7 @@ jobs: 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 the forked repository and will push commits to the same branch. +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. Here's how the Pull Request will look like: From 789f58e41a0d5e3af8438b58272ab02db9438f80 Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Mon, 6 Jun 2022 07:36:31 +0200 Subject: [PATCH 20/30] Add missing links in the CHANGELOG (#223) * Update CHANGELOG Add missing references to Pull Requests. * Link to PRs and Authors in upcoming release notes Co-authored-by: Stefan Zweifel --- .github/release-drafter.yml | 2 +- CHANGELOG.md | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 455bbd6..69cfc0b 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,7 +1,7 @@ ame-template: 'v$RESOLVED_VERSION' tag-template: 'v$RESOLVED_VERSION' +change-template: '- $TITLE ([#$NUMBER](https://github.com/stefanzweifel/git-auto-commit-action/pull/$NUMBER)) [@$AUTHOR](https://github.com/@$AUTHOR)' template: | - # What's Changed $CHANGES categories: - title: Added diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5464a..45ee049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,38 +13,38 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Changed -- Change Commit User Name from "GitHub Actions" to "github-actions[bot]" (#213) @jooola -- Change Commit User Email from "actions@github.com" to "github-actions[bot]@users.noreply.github.com" (#213) @jooola +- Change Commit User Name from "GitHub Actions" to "github-actions[bot]" ([#213](https://github.com/stefanzweifel/git-auto-commit-action/pull/213)) @jooola +- Change Commit User Email from "actions@github.com" to "github-actions[bot]@users.noreply.github.com" ([#213](https://github.com/stefanzweifel/git-auto-commit-action/pull/213)) @jooola ## Fixed -- Update doc link to GITHUB_TOKEN not triggering new workflow runs (#206) @gapple +- Update doc link to GITHUB_TOKEN not triggering new workflow runs ([#206](https://github.com/stefanzweifel/git-auto-commit-action/pull/206)) @gapple ## [v4.14.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...v4.14.0) - 2022-03-18 ## Added -- Add `create_branch` option to force create a new branch (#203) @stefanzweifel +- Add `create_branch` option to force create a new branch ([#203](https://github.com/stefanzweifel/git-auto-commit-action/pull/203)) @stefanzweifel ## Fixed -- README.md: Updates hyperlink to GH docs (#200) @funkyfuture +- README.md: Updates hyperlink to GH docs ([#200](https://github.com/stefanzweifel/git-auto-commit-action/pull/200)) @funkyfuture ## [v4.13.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...v4.13.1) - 2022-01-13 ## Fixed -- Properly disambiguate between branch or file checkout (#199) @kenodegard +- Properly disambiguate between branch or file checkout ([#199](https://github.com/stefanzweifel/git-auto-commit-action/pull/199)) @kenodegard ## [v4.13.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...v4.13.0) - 2022-01-10 ## Added -- Add `skip_checkout` option (#197) @cmbuckley +- Add `skip_checkout` option ([#197](https://github.com/stefanzweifel/git-auto-commit-action/pull/197)) @cmbuckley ## Changed -- Add note on minimum permissions to the docs (#180) @ericcornelissen +- Add note on minimum permissions to the docs ([#180](https://github.com/stefanzweifel/git-auto-commit-action/pull/180)) @ericcornelissen ## [v4.12.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...v4.12.0) - 2021-09-10 From f990bd0ed13ca1e41d474ae0bff84ea053b3bd65 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Mon, 27 Jun 2022 20:56:36 +0200 Subject: [PATCH 21/30] Add Note about .gitignore --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8ec3340..9f69ffc 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,10 @@ If you create a personal access token, apply the `repo` and `workflow` scopes. 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. +### 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. + ## Advanced Uses
From 571d6b78ed2213bc3630491d4cfffb7fe3f152bb Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 28 Jun 2022 20:08:10 +0200 Subject: [PATCH 22/30] Add test to verify issue #227 This test confirms the problem mentioned in #227. If `file_pattern` contains a pattern of, for example 2 file extensions, and only files for one extensions are dirty but not for the otherone, `git-add` will throw a fatal error. It does not throw an error if the files for the pattern already exist but are not dirty. --- tests/git-auto-commit.bats | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index ea53cad..47687ce 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -793,3 +793,33 @@ git_auto_commit() { assert_equal $current_sha $remote_sha; } + +@test "throws fatal error if file pattern includes files that do not exist" { + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo + + INPUT_FILE_PATTERN="*.foo *.bar" + + run git_auto_commit + + assert_failure + assert_line --partial "fatal: pathspec '*.bar' did not match any files" +} + +@test "does not throw fataal error if files for file pattern exist but only one is dirty" { + # Add some .foo and .bar files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.bar + + INPUT_FILE_PATTERN="*.foo *.bar" + + run git_auto_commit + + # Add more .foo files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{4,5,6}.foo + + INPUT_FILE_PATTERN="*.foo *.bar" + + run git_auto_commit + + assert_success +} From f0d72a04e7eb2216f50ae6c9089b42165b342737 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 29 Jun 2022 20:24:50 +0200 Subject: [PATCH 23/30] Add note about pathspec error --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 9f69ffc..8bf22dd 100644 --- a/README.md +++ b/README.md @@ -399,6 +399,14 @@ If you go the "force pushes" route, you have to enable force pushes to a protect 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). +### 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. + +`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. + +See [Issue #227](https://github.com/stefanzweifel/git-auto-commit-action/issues/227) for details. + ## Running the tests The Action has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`. From f33e764001cd92cef6fcdd2d494661df3d143a75 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 11 Jul 2022 15:25:38 +0200 Subject: [PATCH 24/30] fix typo in readme (#230) remote was misspelled --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8bf22dd..7c5dcc9 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The following is an extended example with all available options. commit_author: Author # defaults to author of the commit that triggered the run # Optional. Tag name being created in the local repository and - # pushed to remtoe repository and defined branch. + # pushed to remote repository and defined branch. tagging_message: 'v1.0.0' # Optional. Option used by `git-status` to determine if the repository is From f5b5fefa06a5c27d8b29ab2f0f31c0ce1a5b9d59 Mon Sep 17 00:00:00 2001 From: Derrick Lee Date: Wed, 27 Jul 2022 14:23:35 +0800 Subject: [PATCH 25/30] docs: fix typos and grammer errors in readme.md (#235) --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7c5dcc9..dad822f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add the following step at the end of your job, after other steps that might add - uses: stefanzweifel/git-auto-commit-action@v4 ``` -Note that the Action has to be used in a Job that runs on a UNIX system (eg. `ubuntu-latest`). +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. The following is an extended example with all available options. @@ -149,7 +149,7 @@ You can use these outputs to trigger other Actions in your Workflow run based on ## Limitations & Gotchas -The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore you might run into issues if your Workflow falls into the not supported 20% portion. +The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore, you might run into issues if your Workflow falls into the not supported 20% portion. The following is a list of edge cases the Action knowingly does not support: @@ -279,7 +279,7 @@ jobs: 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 the **forked** repository and will push commits to the same branch. +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: @@ -307,7 +307,7 @@ See [this announcement from GitHub](https://github.blog/2020-08-03-github-action 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. +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)) @@ -371,7 +371,7 @@ 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 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 Acess Token needs to belong to an Administrator. +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. 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. @@ -383,7 +383,7 @@ store the token as a secret in your repository and pass the new token to the [`a ``` 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. +**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. 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. @@ -403,7 +403,7 @@ This is due to limitations set up by GitHub, [commits of this Action do not trig 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. +`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. See [Issue #227](https://github.com/stefanzweifel/git-auto-commit-action/issues/227) for details. @@ -427,7 +427,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@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).) ## Credits From 32807d4f18f1f004ed74e14e047fecfe5204874b Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 30 Jul 2022 20:14:29 +0200 Subject: [PATCH 26/30] Upgrade Bats --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1d4ab40..efbe05d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11,6 +11,6 @@ bats-support@ztombol/bats-support: resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee" bats@^1.1.0: - version "1.2.1" - resolved "https://registry.yarnpkg.com/bats/-/bats-1.2.1.tgz#c15aecc3eb331aedf28678880fab2be0b73eba43" - integrity sha512-2fcPDRQa/Kvh6j1IcCqsHpT5b9ObMzRzw6abC7Bg298PX8Qdh9VRkvO2WJUEhdyfjq2rLBCOAWdcv0tS4+xTUA== + version "1.7.0" + resolved "https://registry.yarnpkg.com/bats/-/bats-1.7.0.tgz#caae958b1d211eda6b1322ac7792515de40165a2" + integrity sha512-pt5zjJQUB4+JI8Si+z/IAWc8yhMyhdZs6IXMCKgzF768dUIyW5xyBstWtDI5uGSa80v7UQOhh+w0GA4p4+01Bg== From 926240570901a8a0cbb6fb2ec40f26e35d5644fe Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 30 Jul 2022 20:14:41 +0200 Subject: [PATCH 27/30] Fix Typo in Test --- tests/git-auto-commit.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 47687ce..21c3eea 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -805,7 +805,7 @@ git_auto_commit() { assert_line --partial "fatal: pathspec '*.bar' did not match any files" } -@test "does not throw fataal error if files for file pattern exist but only one is dirty" { +@test "does not throw fatal error if files for file pattern exist but only one is dirty" { # Add some .foo and .bar files touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.bar From dce7e85096193516db2ae686bd562faf5bc7f4ea Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 30 Jul 2022 20:21:57 +0200 Subject: [PATCH 28/30] Add Tests to Cover #233 --- tests/git-auto-commit.bats | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 21c3eea..449d9d8 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -823,3 +823,19 @@ git_auto_commit() { assert_success } + +@test "detects and commits changed files based on pattern in root and subfolders" { + # Add some .neon files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.neon + mkdir foo; + touch "${FAKE_LOCAL_REPOSITORY}"/foo/new-file-2.neon + + INPUT_FILE_PATTERN="**/*.neon *.neon" + + run git_auto_commit + + assert_success + + assert_line --partial "new-file-1.neon" + assert_line --partial "foo/new-file-2.neon" +} From 4e7c0d67cd27ac96adcf4d3e06db1070c1a3c4f0 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 6 Sep 2022 21:04:34 +0200 Subject: [PATCH 29/30] Assert throws error when force adding ignored files See https://github.com/stefanzweifel/git-auto-commit-action/issues/204#issuecomment-1236880360 --- tests/git-auto-commit.bats | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 449d9d8..775d24a 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -839,3 +839,36 @@ git_auto_commit() { assert_line --partial "new-file-1.neon" assert_line --partial "foo/new-file-2.neon" } + +@test "throws error if tries to force add ignored files which do not have any changes" { + # Create 2 files which will later will be added to .gitignore + touch "${FAKE_LOCAL_REPOSITORY}"/ignored-file.txt + touch "${FAKE_LOCAL_REPOSITORY}"/another-ignored-file.txt + + # Commit the 2 new files + run git_auto_commit + + # Add our txt files to gitignore + echo "ignored-file.txt" >> "${FAKE_LOCAL_REPOSITORY}"/.gitignore + echo "another-ignored-file.txt" >> "${FAKE_LOCAL_REPOSITORY}"/.gitignore + + # Commit & push .gitignore changes + run git_auto_commit + + # Sanity check that txt files are ignored + run cat "${FAKE_LOCAL_REPOSITORY}"/.gitignore + assert_output --partial "ignored-file.txt" + assert_output --partial "another-ignored-file.txt"; + + # Configure git-auto-commit + INPUT_SKIP_DIRTY_CHECK=true + INPUT_ADD_OPTIONS="-f" + INPUT_FILE_PATTERN="ignored-file.txt another-ignored-file.txt" + + # Run git-auto-commit with special configuration + run git_auto_commit + + assert_output --partial "nothing to commit, working tree clean"; + + assert_failure; +} From 4d00f10668b767d99f539489062c0e3dd052c645 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 15:18:36 +0200 Subject: [PATCH 30/30] Expand `file_pattern`-input to an array (#205) * Expand file_pattern input * Expand file pattern array in git-status * Add Failing Test * Expand INPUT_FILE_PATTERN * Fix Shellcheck Issues * Add test to cover file expansion works when globbing is disabled * Add explanation to README --- README.md | 20 +++++++++++++ entrypoint.sh | 8 ++++-- tests/git-auto-commit.bats | 57 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dad822f..1f77647 100644 --- a/README.md +++ b/README.md @@ -407,6 +407,26 @@ If you're using the Action with a custom `file_pattern` and the Action throws a See [Issue #227](https://github.com/stefanzweifel/git-auto-commit-action/issues/227) for details. +### Custom `file_pattern`, changed files but seeing "Working tree clean. Nothing to commit." in the logs + +If you're using a custom `file_pattern` and the Action does not detect the changes made in your worfklow, you're probably running into a globbing issue. + +Let's imagine you use `file_pattern: '*.md'` to detect and commit changes to all Markdown files in your repository. +If your Workflow now only updates `.md`-files in a subdirectory, but you have an untouched `.md`-file in the root of the repository, the git-auto-commit Action will display "Working tree clean. Nothing to commit." in the Workflow log. + +This is due to the fact, that the `*.md`-glob is expanded before sending it to `git-status`. `git-status` will receive the filename of your untouched `.md`-file in the root of the repository and won't detect any changes; and therefore the Action does nothing. + +To fix this add `disable_globbing: true` to your Workflow. + +```yaml +- uses: stefanzweifel/git-auto-commit-action@v4 + with: + file_pattern: '*.md' + disable_globbing: true +``` + +See [Issue #239](https://github.com/stefanzweifel/git-auto-commit-action/issues/239) for details. + ## Running the tests The Action has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`. diff --git a/entrypoint.sh b/entrypoint.sh index dee54a9..e34e72e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -40,8 +40,11 @@ _git_is_dirty() { echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}"; echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}"; + echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; + read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; + # shellcheck disable=SC2086 - [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- $INPUT_FILE_PATTERN)" ] + [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ] } _switch_to_branch() { @@ -75,9 +78,10 @@ _add_files() { echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; + read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; # shellcheck disable=SC2086 - git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN}; + git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN:+"${INPUT_FILE_PATTERN_EXPANDED[@]}"}; } _local_commit() { diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 775d24a..819b1e8 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -164,7 +164,6 @@ git_auto_commit() { } @test "It applies INPUT_ADD_OPTIONS when adding files" { - INPUT_FILE_PATTERN="" INPUT_STATUS_OPTIONS="--untracked-files=no" INPUT_ADD_OPTIONS="-u" @@ -177,7 +176,6 @@ git_auto_commit() { assert_line "INPUT_STATUS_OPTIONS: --untracked-files=no" assert_line "INPUT_ADD_OPTIONS: -u" - assert_line "INPUT_FILE_PATTERN: " assert_line "::debug::Push commit to remote branch master" # Assert that PHP files have not been added. @@ -872,3 +870,58 @@ git_auto_commit() { assert_failure; } + +@test "expands file patterns correctly and commits all changed files" { + # Add more .txt files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.txt + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar + + INPUT_FILE_PATTERN="*.txt *.bar" + + run git_auto_commit + + assert_success + + assert_line --partial "new-file-1.txt" + assert_line --partial "subdirectory/new-file-2.txt" + assert_line --partial "new-file-3.bar" +} + +@test "expands file patterns correctly and commits all changed files when globbing is disabled" { + # Add more .txt files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.txt + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar + + INPUT_FILE_PATTERN="*.txt *.bar" + INPUT_DISABLE_GLOBBING=true + + run git_auto_commit + + assert_success + + assert_line --partial "new-file-1.txt" + assert_line --partial "subdirectory/new-file-2.txt" + assert_line --partial "new-file-3.bar" +} + +@test "expands file patterns correctly and commits all changed files if dirty files are only in subdirectory" { + # Add more .txt files + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt + mkdir "${FAKE_LOCAL_REPOSITORY}"/another-subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/another-subdirectory/new-file-3.txt + + INPUT_FILE_PATTERN="*.txt" + INPUT_DISABLE_GLOBBING=true + + run git_auto_commit + + assert_success + + assert_line --partial "subdirectory/new-file-2.txt" + assert_line --partial "another-subdirectory/new-file-3.txt" +}