From fc174e240685ba61fdc7422f02ea5edea2171e6a Mon Sep 17 00:00:00 2001 From: Chris Buckley Date: Mon, 10 Jan 2022 00:10:05 +0000 Subject: [PATCH] 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 246c3b8d..c584d9d9 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 540b9005..03a8557d 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 406f03f4..0d876086 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 654fb7c6..bdadd356 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"