Skip to content

Commit 905c3cd

Browse files
Merge pull request #66 from step-security/auto-cherry-pick
chore: Cherry-picked changes from upstream
2 parents ca6d6c4 + f09b382 commit 905c3cd

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ The following is an extended example with all available options.
112112

113113
# Optional. Skip internal call to `git checkout`
114114
skip_checkout: true
115+
116+
# Optional. Skip internal call to `git push`
117+
skip_push: true
115118

116119
# Optional. Prevents the shell from expanding filenames.
117120
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
@@ -213,7 +216,7 @@ If this Action doesn't work for your workflow, check out [EndBug/add-and-commit]
213216

214217
### Checkout the correct branch
215218

216-
You must use `action/checkout@v2` or later versions to check out the repository.
219+
You must use `actions/checkout@v2` or later versions to check out the repository.
217220
In non-`push` events, such as `pull_request`, make sure to specify the `ref` to check out:
218221

219222
```yaml

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ inputs:
6868
description: Skip the call to git-checkout.
6969
required: false
7070
default: false
71+
skip_push:
72+
description: Skip the call to git-push.
73+
required: false
74+
default: false
7175
disable_globbing:
7276
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
7377
default: false

dist/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ _tag_commit() {
191191
}
192192
193193
_push_to_github() {
194+
if "$INPUT_SKIP_PUSH"; then
195+
_log "debug" "git-push will not be executed.";
196+
return
197+
fi
194198
195199
echo "INPUT_BRANCH value: $INPUT_BRANCH";
196200

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ _tag_commit() {
191191
}
192192
193193
_push_to_github() {
194+
if "$INPUT_SKIP_PUSH"; then
195+
_log "debug" "git-push will not be executed.";
196+
return
197+
fi
194198
195199
echo "INPUT_BRANCH value: $INPUT_BRANCH";
196200

tests/git-auto-commit.bats

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ setup() {
3838
export INPUT_SKIP_DIRTY_CHECK=false
3939
export INPUT_SKIP_FETCH=false
4040
export INPUT_SKIP_CHECKOUT=false
41+
export INPUT_SKIP_PUSH=false
4142
export INPUT_DISABLE_GLOBBING=false
4243
export INPUT_CREATE_BRANCH=false
4344
export INPUT_INTERNAL_GIT_BINARY=git
@@ -352,6 +353,24 @@ cat_github_output() {
352353
assert_equal $current_sha $remote_sha
353354
}
354355

356+
@test "If SKIP_PUSH is true git-push will not be called" {
357+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
358+
359+
INPUT_SKIP_PUSH=true
360+
361+
run git_auto_commit
362+
363+
assert_success
364+
365+
assert_line "::debug::git-push will not be executed."
366+
367+
# Assert that the sha values are not equal on local and remote
368+
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
369+
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
370+
371+
refute [assert_equal $current_sha $remote_sha]
372+
}
373+
355374
@test "It can checkout a different branch" {
356375
# Create foo-branch and then immediately switch back to ${FAKE_DEFAULT_BRANCH}
357376
git checkout -b foo
@@ -1501,4 +1520,4 @@ END
15011520
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
15021521

15031522
assert_equal $current_sha $remote_sha
1504-
}
1523+
}

0 commit comments

Comments
 (0)