Let Action fail if git binary can't be located (#261)

* Check if git binary exists

* Add Tests
This commit is contained in:
Stefan Zweifel 2022-11-05 11:53:46 +01:00 committed by GitHub
parent 7106b2184a
commit 0b007fbd11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -70,6 +70,9 @@ inputs:
create_branch: create_branch:
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet. description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
default: false default: false
internal_git_binary:
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
default: git
outputs: outputs:
changes_detected: changes_detected:

View File

@ -7,6 +7,8 @@ if "$INPUT_DISABLE_GLOBBING"; then
fi fi
_main() { _main() {
_check_if_git_is_available
_switch_to_repository _switch_to_repository
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
@ -42,6 +44,14 @@ _main() {
fi fi
} }
_check_if_git_is_available() {
if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then
echo "::debug::git binary found.";
else
echo "::error ::git-auto-commit could not find git binary. Please make sure git is available."
exit 1;
fi
}
_switch_to_repository() { _switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY"; echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";

View File

@ -37,6 +37,7 @@ setup() {
export INPUT_SKIP_CHECKOUT=false export INPUT_SKIP_CHECKOUT=false
export INPUT_DISABLE_GLOBBING=false export INPUT_DISABLE_GLOBBING=false
export INPUT_CREATE_BRANCH=false export INPUT_CREATE_BRANCH=false
export INPUT_INTERNAL_GIT_BINARY=git
# Set GitHub environment variables used by the GitHub Action # Set GitHub environment variables used by the GitHub Action
temp_github_output_file=$(mktemp -t github_output_test.XXXXX) temp_github_output_file=$(mktemp -t github_output_test.XXXXX)
@ -1041,3 +1042,14 @@ cat_github_output() {
assert_line "::set-output name=changes_detected::false" assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$" refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
} }
@test "It fails hard if git is not available" {
INPUT_INTERNAL_GIT_BINARY=binary-does-not-exist
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
run git_auto_commit
assert_failure;
assert_line "::error ::git-auto-commit could not find git binary. Please make sure git is available."
}