-
Notifications
You must be signed in to change notification settings - Fork 6k
fix(brew-bump.sh): add checks and handle errors #4236
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This is a library which contains functions used inside ci/steps | ||
# | ||
# We separated it into it's own file so that we could easily unit test | ||
# these functions and helpers | ||
|
||
# Checks whether and environment variable is set. | ||
# Source: https://stackoverflow.com/a/62210688/3015595 | ||
is_env_var_set() { | ||
local name="${1:-}" | ||
if test -n "${!name:-}"; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Checks whether a directory exists. | ||
directory_exists() { | ||
local dir="${1:-}" | ||
if [[ -d "${dir:-}" ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Checks whether a file exists. | ||
file_exists() { | ||
local file="${1:-}" | ||
if test -f "${file:-}"; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Checks whether a file is executable. | ||
is_executable() { | ||
local file="${1:-}" | ||
if [ -f "${file}" ] && [ -r "${file}" ] && [ -x "${file}" ]; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bats | ||
|
||
SCRIPT_NAME="steps-lib.sh" | ||
SCRIPT="$BATS_TEST_DIRNAME/../../ci/steps/$SCRIPT_NAME" | ||
|
||
source "$SCRIPT" | ||
|
||
@test "is_env_var_set should return 1 if env var is not set" { | ||
run is_env_var_set "ASDF_TEST_SET" | ||
[ "$status" = 1 ] | ||
} | ||
|
||
@test "is_env_var_set should return 0 if env var is set" { | ||
ASDF_TEST_SET="test" run is_env_var_set "ASDF_TEST_SET" | ||
[ "$status" = 0 ] | ||
} | ||
|
||
@test "directory_exists should 1 if directory doesn't exist" { | ||
run directory_exists "/tmp/asdfasdfasdf" | ||
[ "$status" = 1 ] | ||
} | ||
|
||
@test "directory_exists should 0 if directory exists" { | ||
run directory_exists "$(pwd)" | ||
[ "$status" = 0 ] | ||
} | ||
|
||
@test "file_exists should 1 if file doesn't exist" { | ||
run file_exists "hello-asfd.sh" | ||
[ "$status" = 1 ] | ||
} | ||
|
||
@test "file_exists should 0 if file exists" { | ||
run file_exists "$SCRIPT" | ||
[ "$status" = 0 ] | ||
} | ||
|
||
@test "is_executable should 1 if file isn't executable" { | ||
run is_executable "hello-asfd.sh" | ||
[ "$status" = 1 ] | ||
} | ||
|
||
@test "is_executable should 0 if file is executable" { | ||
run is_executable "$SCRIPT" | ||
[ "$status" = 0 ] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.