Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -70,6 +70,9 @@ inputs:
create_branch:
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
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:
changes_detected:
Expand Down
10 changes: 10 additions & 0 deletions entrypoint.sh
Expand Up @@ -7,6 +7,8 @@ if "$INPUT_DISABLE_GLOBBING"; then
fi

_main() {
_check_if_git_is_available

_switch_to_repository

if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
Expand Down Expand Up @@ -42,6 +44,14 @@ _main() {
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() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
Expand Down
12 changes: 12 additions & 0 deletions tests/git-auto-commit.bats
Expand Up @@ -37,6 +37,7 @@ setup() {
export INPUT_SKIP_CHECKOUT=false
export INPUT_DISABLE_GLOBBING=false
export INPUT_CREATE_BRANCH=false
export INPUT_INTERNAL_GIT_BINARY=git

# Set GitHub environment variables used by the GitHub Action
temp_github_output_file=$(mktemp -t github_output_test.XXXXX)
Expand Down Expand Up @@ -1041,3 +1042,14 @@ cat_github_output() {
assert_line "::set-output name=changes_detected::false"
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."
}