Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion shell/devconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ source "$DIR/lib/yq.sh"
# Resolve the yq binary once, up front: each yq_wrapper call below runs
# as its own pipeline stage (a forked subshell), so without this each of
# the 3 pipelines further down would independently redo yq_resolve_bin's
# own resolution work.
# own resolution work. Without Go, this resolves nothing and yq_wrapper
# runs gojq instead.
yq_resolve_bin

# shellcheck source=./lib/box.sh
Expand Down
3 changes: 2 additions & 1 deletion shell/lib/box.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ download_box() {
# Resolve the yq binary once, in this shell, before the 3 calls
# below: each runs in its own forked subshell (pipe/process
# substitution), so without this they'd each independently redo
# yq_resolve_bin's own resolution work.
# yq_resolve_bin's own resolution work. Without Go, this resolves
# nothing and yq_wrapper runs gojq instead.
yq_resolve_bin
# Avoid reading and writing to the same file
newBox="$(yq_wrapper . "${BOXPATH}" |
Expand Down
6 changes: 5 additions & 1 deletion shell/lib/yq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ DEVBASE_YQ_BIN=""
# yq_resolve_bin resolves and caches in DEVBASE_YQ_BIN the binary
# yq_wrapper() should run: built-from-source for "local"/dev (see
# yq_build_from_source), or devbase_cli's own tagged-release resolution
# otherwise.
# otherwise. It resolves nothing when yq_wrapper will run gojq instead.
yq_resolve_bin() {
if [[ -n $DEVBASE_YQ_BIN ]]; then
return
fi

if yq_use_gojq; then
return
fi

local version
version="$(devbase_cli_version)"

Expand Down
24 changes: 24 additions & 0 deletions shell/lib/yq_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ stub_go_git() {
@test "yq_resolve_bin uses yq_build_from_source for a local/dev version" {
# shellcheck disable=SC2329 # Why: called indirectly as a stub.
devbase_cli_version() { echo "local"; }
# shellcheck disable=SC2329 # Why: called indirectly as a stub.
find_tool() { echo "/fake/go"; }
local build_count_file="$DEVBASE_CACHED_BINARY_STORAGE_PATH/count"
stub_go_git "$build_count_file"
# shellcheck disable=SC2329 # Why: called indirectly as a stub.
Expand Down Expand Up @@ -253,3 +255,25 @@ stub_gojq_env() {
assert_success
assert_output "gojq fallback .a"
}

@test "yq_resolve_bin does not build devbase when go is missing" {
stub_gojq_env local ""
yq_build_from_source() {
echo "unexpected build" >&2
return 1
}

yq_resolve_bin
# shellcheck disable=SC2031 # Why: yq_resolve_bin runs in this shell, not a subshell.
assert_equal "$DEVBASE_YQ_BIN" ""
}

@test "yq_resolve_bin still resolves a tagged version when go is missing" {
stub_gojq_env v2.40.0 ""
# shellcheck disable=SC2317,SC2329 # Why: called indirectly as a stub.
devbase_cli_binary() { echo "/fake/devbase-v2.40.0"; }

yq_resolve_bin
# shellcheck disable=SC2031 # Why: yq_resolve_bin runs in this shell, not a subshell.
assert_equal "$DEVBASE_YQ_BIN" "/fake/devbase-v2.40.0"
}
Loading