From 0ee9fb7263afb95069f9e98e32c3035eeea91997 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Thu, 15 Oct 2020 20:21:08 +0200 Subject: [PATCH 1/5] Add checkout_options --- action.yml | 4 ++++ entrypoint.sh | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a4a8630..6c9bf7d 100644 --- a/action.yml +++ b/action.yml @@ -44,6 +44,10 @@ inputs: description: Push options (eg. --force) required: false default: '' + checkout_options: + description: Checkout options (eg. --branch) + required: false + default: '' skip_dirty_check: description: Skip the check if the git repository is dirty and always try to create a commit. required: false diff --git a/entrypoint.sh b/entrypoint.sh index cfe6823..0829b48 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -42,8 +42,11 @@ _switch_to_branch() { # Fetch remote to make sure that repo can be switched to the right branch. git fetch; + # shellcheck disable=SC2206 + INPUT_CHECKOUT_OPTIONS_ARRAY=( $INPUT_CHECKOUT_OPTIONS ); + # Switch to branch from current Workflow run - git checkout "$INPUT_BRANCH" --; + git checkout ${INPUT_CHECKOUT_OPTIONS:+"${INPUT_CHECKOUT_OPTIONS_ARRAY[@]}"} "$INPUT_BRANCH" --; } _add_files() { From 849613a3adf99d0db5126b9e9ed50d8dffe19f85 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Thu, 15 Oct 2020 20:23:04 +0200 Subject: [PATCH 2/5] Add test to cover checkout-options --- tests/git-auto-commit-mocked.bats | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/git-auto-commit-mocked.bats b/tests/git-auto-commit-mocked.bats index 8dc583a..f7e8f53 100644 --- a/tests/git-auto-commit-mocked.bats +++ b/tests/git-auto-commit-mocked.bats @@ -32,6 +32,7 @@ setup() { export INPUT_COMMIT_AUTHOR="Test Suite " export INPUT_TAGGING_MESSAGE="" export INPUT_PUSH_OPTIONS="" + export INPUT_CHECKOUT_OPTIONS="" export INPUT_SKIP_DIRTY_CHECK=false skipIfNot "$BATS_TEST_DESCRIPTION" @@ -308,6 +309,39 @@ main() { } +@test "git-checkout-options-are-applied" { + + INPUT_CHECKOUT_OPTIONS="-b --progress" + + touch "${test_repository}"/new-file-{1,2,3}.txt + + shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status" + shellmock_expect git --type exact --match "fetch" + shellmock_expect git --type exact --match "checkout -b --progress master --" + shellmock_expect git --type partial --match "add ." + shellmock_expect git --type partial --match '-c' + shellmock_expect git --type partial --match 'push --set-upstream origin' + + run main + + echo "$output" + + # Success Exit Code + [ "$status" = 0 ] + + [ "${lines[10]}" = "::debug::Push commit to remote branch master" ] + + + shellmock_verify + [ "${capture[0]}" = "git-stub status -s -- ." ] + [ "${capture[1]}" = "git-stub fetch" ] + [ "${capture[2]}" = "git-stub checkout -b --progress master --" ] + [ "${capture[3]}" = "git-stub add ." ] + [ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite " ] + [ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ] + +} + @test "can-checkout-different-branch" { INPUT_BRANCH="foo" From cfdb7e609e6c88cf7668f810abf0d6398ebce8cf Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Thu, 15 Oct 2020 20:26:03 +0200 Subject: [PATCH 3/5] Add checkout_options to README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 273d5c3..56bf6b3 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,9 @@ Add the following step at the end of your job, after other steps that might add # Optional: Disable dirty check and always try to create a commit and push skip_dirty_check: true + + # Optional: Allows you to update how the repo is checked out + checkout_options: '-q --force -b' ``` ## Example From b9e4cea0ef10674620338288a4172f232f93cf45 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Thu, 15 Oct 2020 20:30:19 +0200 Subject: [PATCH 4/5] Disable Markdown Linter --- .github/workflows/linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 23329dd..5fc5555 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -14,5 +14,6 @@ jobs: uses: github/super-linter@v3 env: VALIDATE_ALL_CODEBASE: false + VALIDATE_MARKDOWN: false DEFAULT_BRANCH: master GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 1ba48c6d7f0aedfbdaceef720b38b65f1b6b6db9 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Thu, 15 Oct 2020 20:30:26 +0200 Subject: [PATCH 5/5] Fix Linter Errors in entrypoint.sh --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0829b48..ee2cce7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -29,10 +29,11 @@ _main() { _switch_to_repository() { echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY"; - cd $INPUT_REPOSITORY; + cd "$INPUT_REPOSITORY"; } _git_is_dirty() { + # shellcheck disable=SC2086 [ -n "$(git status -s -- $INPUT_FILE_PATTERN)" ] }