Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Double quote escape for variable substitution does not seem to work in github action? #649

Closed
steven-xufan opened this issue Jan 8, 2021 · 4 comments

Comments

@steven-xufan
Copy link

steven-xufan commented Jan 8, 2021

I was following the Tips and Tricks page to do variable substitution yq e ".a.b = \"$myvalue\"" file.yaml and it works locally in the command line. However I am having some issue to get it work with Github Action.

Example
I created a simple yaml and workflow file here.
I am just trying to replace a value in yml file with:

cmd: >
  yq eval --inplace ".bar.tag = \"${ABC}\"" test.yml

For completeness, test.yml looks like this:

foo: a
bar:
  tag: xxx
c: c

And it fails with the following. The log can also accessed here.

/usr/bin/docker run --name cc49561edb686f734b47adbd13252d2f99bd4f_5e9d18 --label cc4956 --workdir /github/workspace --rm -e ABC -e INPUT_CMD -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/public-test/public-test":"/github/workspace" cc4956:1edb686f734b47adbd13252d2f99bd4f  "yq eval --inplace \".bar.tag = \\"${ABC}\\"\" test.yml
"
/entrypoint.sh: eval: line 1: syntax error: unterminated quoted string
yq eval --inplace ".bar.tag = \${ABC}\" test.yml

The only way I could get this to work is the following. (example commit and workflow log)

yq eval --inplace '.bar.tag = "'${ABC}'"' test.yml

I looked through the code at yq/github-action and it is just passing in the argument.

Am I doing anything wrong? Or is the github action not able to escape \" properly?

@mikefarah
Copy link
Owner

Perhaps because the github action itself is defined in yaml - it's not escaping properly :/

But yeah, looks right to me.

Next release I'm going to add new env/strenv operators that will mean less escaping confusion (see #642).

@mikefarah
Copy link
Owner

Try the new env/strenv operators https://mikefarah.gitbook.io/yq/env-variable-operators

@steven-xufan
Copy link
Author

that works great. thank you!

@StephanX
Copy link

Took me a moment to decipher the documentation, but managed to decipher the env(value) like so:

yq --null-input '.some.value = "abc123"' > file.yaml
my_bash_value="xyz789" 
myYQvalue="${my_bash_value}" yq '.some.value = env(myYQvalue)' file.yaml
some:
  value: xyz789

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants