What is the correct character escaping for workflow command values e.g. echo ::error::XXXX #26736
-
I’m using the “echo” approach to add annotations to give errors for test failures. I’m including the error message from the test which could contain arbitrary characters, and I couldn’t see from https://help.github.com/en/actions/reference/workflow-commands-for-github-actions what kind of escaping I need to perform on the command value? From hacking around it looks like colons are OK but there’s something special going on with % characters (e.g. %0A produces a newline), maybe I should be doing URL encoding? But it doesn’t seem like other URL chars are encoded, so I’m not sure. Would be great if someone could definitively confirm what encoding is needed for safely representing string as workflow command values |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments
-
Hello – we’re trying to reproduce this on our end: Are you able to share a copy of your workflow file? If the repository is public, could you link that to us as well? For more context, could you let us know what the expected behaviour of the workflow run is versus what is being outputted now? Thank you! |
Beta Was this translation helpful? Give feedback.
-
Hi this isn’t a bug report so there’s nothing to repo really - I’m asking a question about how your API works so that I can make sure when I output a message using echo “::error::XXXXX" syntax the XXXXX shows up as I expect. Clearly there is some special handling for % escape sequences otherwise |
Beta Was this translation helpful? Give feedback.
-
Hi there, any input on this? Really need a definitive answer from GitHub on how this works, thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi, sorry for the delay. The actions/toolkit/blob/cee7d92d1d02e3107c9b1387b9690b89096b67be/packages/core/src/command.ts#L92-L105
|
Beta Was this translation helpful? Give feedback.
-
Hi team - can you please give an example of how this might work in a workflow yml? I haven’t been able to figure it out from the docs
from here I see I need to do something like
but this gives the literal value in the called wf:-
if I remove the echo, the workflow file can’t be run at all:-
gives
putting the command inside the deference of the env var gives:
this also fails:-
|
Beta Was this translation helpful? Give feedback.
-
If you’re trying to pre-process the input value, you can do that in a separate job that creates an output with the escaped data. However I’d rather do any escaping that may be necessary in the called workflow, to make it more robust. |
Beta Was this translation helpful? Give feedback.
-
hi @airtower-luna - could you please give an example ? the syntax seems weird in the examples in the doc. happy to move into the called workflow to do this, but what does that look like? TIA :slight_smile: |
Beta Was this translation helpful? Give feedback.
-
Something like this, I used
airtower-luna/hello-github-actions/blob/485336f405d869bee8051f0bbfdeabedd9e4ae7f/.github/workflows/reusable-echo.yaml
on: jobs: This file has been truncated. show original |
Beta Was this translation helpful? Give feedback.
-
@airtower-luna what would the correct workflow call loo like using the built in function? tia! |
Beta Was this translation helpful? Give feedback.
-
@airtower-luna - i tried your example and the echo was empty
Create call-sanitiser.yml · dave99galloway/github-actions-issues@a58876breproduction of github actions issues. Contribute to dave99galloway/github-actions-issues development by creating an account on GitHub. where are the step outputs supposed to be set? TIA! |
Beta Was this translation helpful? Give feedback.
-
Hi Support! do you have an example of this being used somewhere? |
Beta Was this translation helpful? Give feedback.
-
The
Create call-sanitiser.yml · dave99galloway/github-actions-issues@a58876breproduction of github actions issues. Contribute to dave99galloway/github-actions-issues development by creating an account on GitHub. The reason is here, where the parameter for the reusable workflow is set.
Create call-sanitiser.yml
|
Beta Was this translation helpful? Give feedback.
Hi, sorry for the delay.
The
github.comactions/toolkit
has a way to sanitize an input into a string – could you give these commands a try?actions/toolkit/blob/cee7d92d1d02e3107c9b1387b9690b89096b67be/packages/core/src/command.ts#L92-L105