Skip to content

Commit

Permalink
fix(box): abort early if the box repo can't be cloned correctly (#714)
Browse files Browse the repository at this point in the history
* fix(box): put yq flag in the correct location
* fix(box): delete the created tmpdir, not the system tmpdir
  • Loading branch information
malept authored Dec 12, 2023
1 parent ca8201d commit e1acd31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions shell/lib/box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ download_box() {
# Why: OK with assigning without checking exit code.
# shellcheck disable=SC2155
local tempDir="$(mktemp -d)"
trap 'rm -rf "${TMPDIR}"' EXIT
trap 'rm -rf "${tempDir}"' EXIT

git clone -q "${boxGitRepo}" "${tempDir}" --depth 1

if [[ ! -f "${tempDir}/box.yaml" ]]; then
echo "Cloning failed, cannot find box.yaml" >&2
return 1
fi

# Stub for the below yq command if it doesn't exist
mkdir -p "$(dirname "$BOXPATH")"
if [[ ! -e $BOXPATH ]]; then
Expand All @@ -42,7 +47,7 @@ download_box() {
local newBox=$(yq . "${BOXPATH}" |
jq --slurpfile boxconf \
<(yq -r . "${tempDir}/box.yaml") '. * {config: $boxconf[0] }' |
yq . --yaml-output)
yq --yaml-output .)
echo "${newBox}" >"${BOXPATH}"
}

Expand Down
8 changes: 8 additions & 0 deletions shell/lib/box_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ teardown() {
run get_box_yaml
assert_output "$(cat "$BOXPATH")"
}

@test "get_box_yaml should fail if cloning the box repo fails" {
BOX_REPOSITORY_URL="https://github.com/getoutreach/notaboxrepo" \
BOXPATH=/foo/bar/nonexistent \
run get_box_yaml
assert_failure
assert_line "Cloning failed, cannot find box.yaml"
}

0 comments on commit e1acd31

Please sign in to comment.