Replies: 3 comments 2 replies
-
Actually it seems the core issue here is that the sh command does not seem to behave like it does in a terminal. Here it does the right thing: which gojq
gojq not found
If "task tool:print " returned a "gojq not found" instead of an error than it might be easier to overcome this catch 22 ? |
Beta Was this translation helpful? Give feedback.
-
Before I address your question, I want to make a general suggestion for when you want to find the path to an executable. It is recommended to use That aside, if you want Task not to error when setting a variable dynamically, you can use the vars:
JQ_BIN_NAME: "gojq"
JQ_BIN_WHICH:
sh: 'command -v {{.JQ_BIN_NAME}} | true' In this scenario, the value of A couple of options for you:
vars:
PACKAGE:
sh: cat library/package.json
VERSION: '{{(fromJson .PACKAGE).version}}' This might not be practical in scenarios where you need to do something more complex that just accessing a JSON field.
version: '3'
vars:
BIN: "{{.ROOT_DIR}}/bin"
tasks:
foo:
deps: [install:gojq]
cmds:
- '{{.BIN}}/gojq --help'
install:gojq:
vars:
GOJQ_VERSION: v0.12.14
env:
GOBIN: "{{.BIN}}"
status:
- go version -m {{.BIN}}/gojq | grep github.com/itchyny/gojq | grep {{.GOJQ_VERSION}}
cmds:
- go install github.com/itchyny/gojq/cmd/gojq@{{.GOJQ_VERSION}} This pattern has a few advantages:
|
Beta Was this translation helpful? Give feedback.
-
Hey @pd93 The other common pattern missing is sniffing the inane to decide what to do per OS and ARCH ? |
Beta Was this translation helpful? Give feedback.
-
https://github.com/gedw99/datastar
https://github.com/gedw99/datastar/blob/main/Taskfile_tool.yml works for managing compile time dependencies. For example this var:
But I have a dependency here https://github.com/gedw99/datastar/blob/main/Taskfile.yml#L16, which causes all the code to not evaluate, because it needs the binary jq ( aka {{.JQ_BIN_NAME}} ) to be physically installed.
SO I have a catch 22. I can't run "task tool:print" in order to install the binary, because the binary in not installed and breaks any code that relies on the the binary being installed.
is there a workaround that anyone can suggest ?
The Makefile can do this sort of thing without blowing up: https://github.com/gedw99/datastar/blob/main/tools.mk
Beta Was this translation helpful? Give feedback.
All reactions