From 7c07d308166ea7de4e11c752e4d6857113103890 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 27 Feb 2022 12:11:25 +0100 Subject: [PATCH 01/11] Expand file_pattern input --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index dee54a95..5d2206a2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -75,9 +75,10 @@ _add_files() { echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; + INPUT_FILE_PATTERN_ARRAY=( ${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_ARRAY[@]}"}; } _local_commit() { From 12eef67c61b8c90e026edb4521b6331337b9d8e7 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 27 Feb 2022 14:41:55 +0100 Subject: [PATCH 02/11] Expand file pattern array in git-status --- entrypoint.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5d2206a2..3f745f6e 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}"; + INPUT_FILE_PATTERN_ARRAY=( ${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:+${INPUT_FILE_PATTERN_ARRAY[@]}})" ] } _switch_to_branch() { From 9c3e9f4a131ff34ff92f5235ccb3229d1196f14d Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 14 Sep 2022 19:05:25 +0200 Subject: [PATCH 03/11] Add Failing Test --- tests/git-auto-commit.bats | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 775d24a3..12231631 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -872,3 +872,21 @@ git_auto_commit() { assert_failure; } + +@test "expands file patterns correctly and commits all changed files" { + # Add more .foo files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.foo + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.foo + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar + + INPUT_FILE_PATTERN="*.foo *.bar" + + run git_auto_commit + + assert_success + + assert_line --partial "new-file-1.foo" + assert_line --partial "subdirectory/new-file-2.foo" + assert_line --partial "new-file-3.bar" +} From eaeb5b57de451c7747db10fedb5d089eba841762 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 14 Sep 2022 19:20:40 +0200 Subject: [PATCH 04/11] Update Tests --- tests/git-auto-commit.bats | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 12231631..f000971a 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -874,19 +874,34 @@ git_auto_commit() { } @test "expands file patterns correctly and commits all changed files" { - # Add more .foo files - touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.foo + # Add more .md files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.md mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ - touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.foo + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.md touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar - INPUT_FILE_PATTERN="*.foo *.bar" + INPUT_FILE_PATTERN="*.md *.bar" run git_auto_commit assert_success - assert_line --partial "new-file-1.foo" - assert_line --partial "subdirectory/new-file-2.foo" + assert_line --partial "new-file-1.md" + assert_line --partial "subdirectory/new-file-2.md" + # refute_line --partial "subdirectory/new-file-2.md" 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 .md files + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.md + + INPUT_FILE_PATTERN="*.md" + + run git_auto_commit + + assert_success + + assert_line --partial "subdirectory/new-file-2.md" +} From c6f9f21a5253cf2a7edd83ec449fd1eae9ae7251 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 14 Sep 2022 19:29:02 +0200 Subject: [PATCH 05/11] Fix Tests --- tests/git-auto-commit.bats | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index f000971a..a340606b 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. @@ -888,7 +886,6 @@ git_auto_commit() { assert_line --partial "new-file-1.md" assert_line --partial "subdirectory/new-file-2.md" - # refute_line --partial "subdirectory/new-file-2.md" assert_line --partial "new-file-3.bar" } From 0a1365cfd304aa6d3acec36edaef9de2de501069 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 14 Sep 2022 19:40:39 +0200 Subject: [PATCH 06/11] Expand INPUT_FILE_PATTERN --- entrypoint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3f745f6e..4a4921a3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,10 +41,10 @@ _git_is_dirty() { echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; - INPUT_FILE_PATTERN_ARRAY=( ${INPUT_FILE_PATTERN} ) + read -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; # shellcheck disable=SC2086 - [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN:+${INPUT_FILE_PATTERN_ARRAY[@]}})" ] + [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ] } _switch_to_branch() { @@ -78,10 +78,10 @@ _add_files() { echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; - INPUT_FILE_PATTERN_ARRAY=( ${INPUT_FILE_PATTERN} ) + read -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; # shellcheck disable=SC2086 - git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN:+"${INPUT_FILE_PATTERN_ARRAY[@]}"}; + git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN:+"${INPUT_FILE_PATTERN_EXPANDED[@]}"}; } _local_commit() { From aa66e830693a9d80415c25c5fe64388a4bb5b8e0 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 14 Sep 2022 20:18:23 +0200 Subject: [PATCH 07/11] Fix Shellcheck Issues --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4a4921a3..e34e72ea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,7 +41,7 @@ _git_is_dirty() { echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; - read -a INPUT_FILE_PATTERN_EXPANDED <<< "$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_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ] @@ -78,7 +78,7 @@ _add_files() { echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; - read -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; + read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; # shellcheck disable=SC2086 git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN:+"${INPUT_FILE_PATTERN_EXPANDED[@]}"}; From b0538f9930ea4bb1b5f2b41ff7da3ea8b6a4a846 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 11:39:35 +0200 Subject: [PATCH 08/11] Add test to cover file expansion works when globbing is disabled --- tests/git-auto-commit.bats | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index a340606b..5fee78a9 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -889,6 +889,25 @@ git_auto_commit() { assert_line --partial "new-file-3.bar" } +@test "expands file patterns correctly and commits all changed files when globbing is disabled" { + # Add more .md files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.md + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.md + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar + + INPUT_FILE_PATTERN="*.md *.bar" + INPUT_DISABLE_GLOBBING=true + + run git_auto_commit + + assert_success + + assert_line --partial "new-file-1.md" + assert_line --partial "subdirectory/new-file-2.md" + 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 .md files mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ From 4969f9f2d3717545f4ccae76b99b8746e0b7e43f Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 14:44:20 +0200 Subject: [PATCH 09/11] Fix Test --- tests/git-auto-commit.bats | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 5fee78a9..2960f3c6 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -909,15 +909,19 @@ git_auto_commit() { } @test "expands file patterns correctly and commits all changed files if dirty files are only in subdirectory" { - # Add more .md files + # Add more .txt files mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ - touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.md + 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="*.md" + INPUT_FILE_PATTERN="*.txt" + INPUT_DISABLE_GLOBBING=true run git_auto_commit assert_success - assert_line --partial "subdirectory/new-file-2.md" + assert_line --partial "subdirectory/new-file-2.txt" + assert_line --partial "another-subdirectory/new-file-3.txt" } From 6fa9a8d91fbf2b9e072ce53ce8e04e58926be9a4 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 14:45:51 +0200 Subject: [PATCH 10/11] Use txt files in tests --- tests/git-auto-commit.bats | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 2960f3c6..819b1e88 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -872,39 +872,39 @@ git_auto_commit() { } @test "expands file patterns correctly and commits all changed files" { - # Add more .md files - touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.md + # 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.md + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar - INPUT_FILE_PATTERN="*.md *.bar" + INPUT_FILE_PATTERN="*.txt *.bar" run git_auto_commit assert_success - assert_line --partial "new-file-1.md" - assert_line --partial "subdirectory/new-file-2.md" + 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 .md files - touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.md + # 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.md + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar - INPUT_FILE_PATTERN="*.md *.bar" + INPUT_FILE_PATTERN="*.txt *.bar" INPUT_DISABLE_GLOBBING=true run git_auto_commit assert_success - assert_line --partial "new-file-1.md" - assert_line --partial "subdirectory/new-file-2.md" + assert_line --partial "new-file-1.txt" + assert_line --partial "subdirectory/new-file-2.txt" assert_line --partial "new-file-3.bar" } From f3801e5bab9ce3b390aafacf0224ef602b347410 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 15:10:22 +0200 Subject: [PATCH 11/11] Add explanation to README --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index dad822fd..1f776475 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`.