Skip to content

Commit

Permalink
Add the ability to jq template to use modules for custom functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentGoderre committed Oct 2, 2023
1 parent 6334a4f commit 2980a77
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripts/jq-template.awk
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ END {
append_jq(agg_jq)
agg_jq = ""

jq_expr = "if env.version then .[env.version] else . end | (\n" jq_expr "\n)"
# Test that the shared jq module exists before loading it
# This prevents breaking existing build that don't use the shared module
test = "jq -n 'include \"jq-template\"; \"ok\"' 2>&1 > /dev/null"

if (system (test) != 0) {
jq_expr = "if env.version then .[env.version] else . end | (\n" jq_expr "\n)"
} else {
jq_expr = "include \"jq-template\"; if env.version then .[env.version] else . end | (\n" jq_expr "\n)"
}

jq_expr = jq_expr_defs jq_expr

if (ENVIRON["DEBUG"]) {
Expand Down

0 comments on commit 2980a77

Please sign in to comment.