diff --git a/shell/devconfig.sh b/shell/devconfig.sh index e562be03..f90126ae 100755 --- a/shell/devconfig.sh +++ b/shell/devconfig.sh @@ -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 diff --git a/shell/lib/box.sh b/shell/lib/box.sh index 1190fea8..2a70cf59 100755 --- a/shell/lib/box.sh +++ b/shell/lib/box.sh @@ -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}" | diff --git a/shell/lib/yq.sh b/shell/lib/yq.sh index 9d3e61e8..c1d5afc4 100644 --- a/shell/lib/yq.sh +++ b/shell/lib/yq.sh @@ -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)" diff --git a/shell/lib/yq_test.bats b/shell/lib/yq_test.bats index deafcb5f..0835e3ff 100644 --- a/shell/lib/yq_test.bats +++ b/shell/lib/yq_test.bats @@ -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. @@ -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" +}