Page MenuHomePhabricator

[builds-builder] use yq instead of tomljson/jq/jsontoml
Open, Needs TriagePublic

Description

The bug that prevented us from using it seems to be fixed already, see https://gitlab.wikimedia.org/repos/cloud/toolforge/builds-builder/-/merge_requests/87/diffs?file=db43dcb9346f5921b39f1f2f7e267a0c8ae5fb8f#note_199462

That would reduce the tools we need to inject buildpacks and handle toml files

Event Timeline

It seems to work, but still trying to find the equivalent to jq '.processes |= map(.command = [.command] + (.args | .[-1] += " \"$@\"") + ["--"] | .args = [])', not there though:

dcaro@acme$ yq -p toml -o toml '
  .processes |= map(
    .command = ["bash"] + (.args[0:-1] + [(.args[-1] + " $@")])
    | .args = []
  )
'  /tmp/metadata.toml 
[[buildpacks]]
id = "heroku/dotnet"
version = "1.0.3"
api = "0.10"
homepage = "https://github.com/heroku/buildpacks-dotnet"
[[buildpacks]]
id = "heroku/procfile"
version = "4.2.1"
api = "0.10"
homepage = "https://github.com/heroku/buildpacks-procfile"
[[processes]]
type = "web"
command = ["bash", "type", "web", "command", "bash", "args", ["-c", "./autoreport.sh"], "direct", true, "buildpack-id", "./autoreport.sh $@"]
direct = true
buildpack-id = "heroku/procfile"
[[processes]]
type = "another"
command = ["bash", "type", "another", "command", "anotherbash", "args", ["-c", "./another.sh"], "direct", true, "buildpack-id", "./another.sh $@"]  <-- it's adding the whole element, not just args
direct = true
buildpack-id = "heroku/procfile"

Oop, I think this should do the trick (nope, not the same yet):

dcaro@acme$ yq -p toml -o toml '
  .processes |= map(
    .command = ["bash"] + .args + [" \"$@\"", "--"]
    | .args = []
  )
'  /tmp/metadata.toml 
[[buildpacks]]
id = "heroku/dotnet"
version = "1.0.3"
api = "0.10"
homepage = "https://github.com/heroku/buildpacks-dotnet"
[[buildpacks]]
id = "heroku/procfile"
version = "4.2.1"
api = "0.10"
homepage = "https://github.com/heroku/buildpacks-procfile"
[[processes]]
type = "web"
command = ["bash", "-c", "./autoreport.sh", " \"$@\"", "--"]
direct = true
buildpack-id = "heroku/procfile"
[[processes]]
type = "another"
command = ["bash", "-c", "./another.sh", " \"$@\"", "--"]
direct = true
buildpack-id = "heroku/procfile"

this :)

dcaro@acme$ yq -p toml -o toml '
  .processes |= map(
    .command = ["bash"] + [.args[-1] + " \"$@\"", "--"]
    | .args = []
  )
'  /tmp/metadata.toml 
[buildpacks]]
id = "heroku/dotnet"
version = "1.0.3"
api = "0.10"
homepage = "https://github.com/heroku/buildpacks-dotnet"
[[buildpacks]]
id = "heroku/procfile"
version = "4.2.1"
api = "0.10"
homepage = "https://github.com/heroku/buildpacks-procfile"
[[processes]]
type = "web"
command = ["bash", "./autoreport.sh \"$@\"", "--"]
direct = true
buildpack-id = "heroku/procfile"
[[processes]]
type = "another"
command = ["bash", "./another.sh \"$@\"", "--"]
direct = true
buildpack-id = "heroku/procfile"