Skip to content

Commit 0b007fb

Browse files
Let Action fail if git binary can't be located (#261)
* Check if git binary exists * Add Tests
1 parent 7106b21 commit 0b007fb

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ inputs:
7070
create_branch:
7171
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
7272
default: false
73+
internal_git_binary:
74+
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
75+
default: git
7376

7477
outputs:
7578
changes_detected:

entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ if "$INPUT_DISABLE_GLOBBING"; then
77
fi
88

99
_main() {
10+
_check_if_git_is_available
11+
1012
_switch_to_repository
1113

1214
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
@@ -42,6 +44,14 @@ _main() {
4244
fi
4345
}
4446

47+
_check_if_git_is_available() {
48+
if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then
49+
echo "::debug::git binary found.";
50+
else
51+
echo "::error ::git-auto-commit could not find git binary. Please make sure git is available."
52+
exit 1;
53+
fi
54+
}
4555

4656
_switch_to_repository() {
4757
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";

tests/git-auto-commit.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ setup() {
3737
export INPUT_SKIP_CHECKOUT=false
3838
export INPUT_DISABLE_GLOBBING=false
3939
export INPUT_CREATE_BRANCH=false
40+
export INPUT_INTERNAL_GIT_BINARY=git
4041

4142
# Set GitHub environment variables used by the GitHub Action
4243
temp_github_output_file=$(mktemp -t github_output_test.XXXXX)
@@ -1041,3 +1042,14 @@ cat_github_output() {
10411042
assert_line "::set-output name=changes_detected::false"
10421043
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
10431044
}
1045+
1046+
@test "It fails hard if git is not available" {
1047+
INPUT_INTERNAL_GIT_BINARY=binary-does-not-exist
1048+
1049+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
1050+
1051+
run git_auto_commit
1052+
1053+
assert_failure;
1054+
assert_line "::error ::git-auto-commit could not find git binary. Please make sure git is available."
1055+
}

0 commit comments

Comments
 (0)