I have a command:
yq eval-all "[.info.version] | .[0] == .[1]" api.yaml api_master.yaml <(git show master:api.yaml)
and it works fine, returns false or true.
I call this command in bash script on this way:
touch api_master.yaml
t=$(yq eval-all "[.info.version] | .[0] == .[1]" api.yaml api_master.yaml <(git show master:api.yaml))
echo $t
Then, I call this script in CI pipeline, and get an error:
yq: error: argument files: can't open '[.info.version] | .[0] == .[1]': [Errno 2] No such file or directory: '[.info.version] | .[0] == .[1]'
How this command should be called in bash script so it is executed correctly in CI pipeline
CodePudding user response:
With file contents based on your other question in mind, you could rewrite this mikefarah/yq-based solution to one using kislyuk/yq as
yq -n '[inputs.info.version] | .[0] == .[1]' api.yaml api_master.yaml
It outputs, just as before, a boolean value based on the comparison of the versions in the two files provided. It does not consider any third input (although with <(git show master:api.yaml)
you provide one), but neither is the mikefarah/yq solution you already had.
Therefore, to check if the versions from all provided inputs are indeed identical, use unique
and check the length
of the resulting array.
Using mikefarah/yq:
yq ea '[.info.version] | unique | length < 2' api.yaml api_master.yaml <(git show master:api.yaml)
Using kislyuk/yq:
yq -n '[inputs.info.version] | unique | length < 2' api.yaml api_master.yaml <(git show master:api.yaml)