Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ The following is an extended example with all available options.

# Optional. Skip internal call to `git checkout`
skip_checkout: true

# Optional. Skip internal call to `git push`
skip_push: true

# Optional. Prevents the shell from expanding filenames.
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
Expand Down Expand Up @@ -213,7 +216,7 @@ 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 check out the repository.
You must use `actions/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
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ inputs:
description: Skip the call to git-checkout.
required: false
default: false
skip_push:
description: Skip the call to git-push.
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
Expand Down
4 changes: 4 additions & 0 deletions dist/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ _tag_commit() {
}

_push_to_github() {
if "$INPUT_SKIP_PUSH"; then
_log "debug" "git-push will not be executed.";
return
fi

echo "INPUT_BRANCH value: $INPUT_BRANCH";

Expand Down
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ _tag_commit() {
}

_push_to_github() {
if "$INPUT_SKIP_PUSH"; then
_log "debug" "git-push will not be executed.";
return
fi

echo "INPUT_BRANCH value: $INPUT_BRANCH";

Expand Down
21 changes: 20 additions & 1 deletion tests/git-auto-commit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ setup() {
export INPUT_SKIP_DIRTY_CHECK=false
export INPUT_SKIP_FETCH=false
export INPUT_SKIP_CHECKOUT=false
export INPUT_SKIP_PUSH=false
export INPUT_DISABLE_GLOBBING=false
export INPUT_CREATE_BRANCH=false
export INPUT_INTERNAL_GIT_BINARY=git
Expand Down Expand Up @@ -352,6 +353,24 @@ cat_github_output() {
assert_equal $current_sha $remote_sha
}

@test "If SKIP_PUSH is true git-push will not be called" {
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt

INPUT_SKIP_PUSH=true

run git_auto_commit

assert_success

assert_line "::debug::git-push will not be executed."

# Assert that the sha values are not equal on local and remote
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"

refute [assert_equal $current_sha $remote_sha]
}

@test "It can checkout a different branch" {
# Create foo-branch and then immediately switch back to ${FAKE_DEFAULT_BRANCH}
git checkout -b foo
Expand Down Expand Up @@ -1501,4 +1520,4 @@ END
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"

assert_equal $current_sha $remote_sha
}
}
Loading