-
Notifications
You must be signed in to change notification settings - Fork 5
[RF-27572] Handle quotes in passed in parameters #29
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
Conversation
/reviewme @jbarber @rainforestapp/devs |
# Define error helper | ||
error () { | ||
echo "::error ::${1}" | ||
echo "error=${1}" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here "$GITHUB_OUTPUT"
does not require "${GITHUB_OUTPUT}"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess not 🤔 echo "name=value >> $GITHUB_OUTPUT
is how GitHub documents their "set output" functionality (so without braces or quotes), and ShellCheck only complains about the lack of quotes, not braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
braces are only needed if your variable name would run into something not your variable name, e.g. if you wanted to output something like "${GITHUB_OUTPUT}_DEBUG", the braces are important, otherwise it'd be looking for a variable GITHUB_OUTPUT_DEBUG (which obviously doesn't exist)
|
||
RUN_COMMAND="rerun \"${RAINFOREST_RUN_ID}\" --skip-update --token \"${RF_TOKEN}\" --junit-file results/rainforest/junit.xml --save-run-id .rainforest_run_id" | ||
else | ||
RUN_COMMAND="run --skip-update --token \"${RF_TOKEN}\" --run-group ${RF_RUN_GROUP_ID} --junit-file results/rainforest/junit.xml --save-run-id .rainforest_run_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No quotes needed for ${RF_RUN_GROUP_ID}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${RF_RUN_GROUP_ID}
is already validated to be a number
|
||
# Set branch | ||
if [ -n "${RF_BRANCH}" ] ; then | ||
RUN_COMMAND="${RUN_COMMAND} --branch \"${RF_BRANCH//\"/\\\"}\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮 , are al those \
/
necessary? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be using the following bash functionality, which is where a bunch of the forward slashes come from (see https://tldp.org/LDP/abs/html/parameter-substitution.html). It's replacing a "
with a \"
. The escaping is necessary to make that work.
${var//Pattern/Replacement}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are (see the long list of failed workflows while attempting to get this working...)
|
||
# Set description | ||
if [ -z "${RAINFOREST_RUN_ID}" ] && [ -n "${RF_DESCRIPTION}" ] ; then | ||
RUN_COMMAND="${RUN_COMMAND} --description \"${RF_DESCRIPTION//\"/\\\"}\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very familiar with writing/reading shell, and GH Actions, but as far as I could review it looks fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really does make me wonder if this should be done in not-shell and use execve() to spawn the CLI and avoid the quoting risk.
@@ -0,0 +1,134 @@ | |||
#!/bin/bash | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add set -euo pipefail
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it might cause a bunch of stuff to start failing though...
|
||
# Validate token | ||
if [ -z "${RF_TOKEN}" ] ; then | ||
error "Token not set" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedantry: this is actually testing if the variable has a zero length value, test -v
tests if a variable is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but since tokens can't be zero-length, if the variable is set to the empty string, then the token isn't actually set
rm .rainforest_run_id | ||
echo "Rerunning Run ${RAINFOREST_RUN_ID}" | ||
|
||
RUN_COMMAND="rerun \"${RAINFOREST_RUN_ID}\" --skip-update --token \"${RF_TOKEN}\" --junit-file results/rainforest/junit.xml --save-run-id .rainforest_run_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use single quotes here and save yourself some escaping? e.g.
RUN_COMMAND="rerun '${RAINFOREST_RUN_ID}' --skip-update ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that, then reverted because I needed to update all the tests and more crucially the escaping I added in the first commit, and I'd rather not figure out how to get the escaping working again 🙇🏼
action.yml
Outdated
@@ -102,142 +101,20 @@ runs: | |||
path: .rainforest_run_id | |||
restore-keys: | | |||
rainforest-run-${{ github.run_id }}-${{ inputs.cache_key }}- | |||
- name: Escape Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems mis-named, as it doesn't appear to be doing any escaping? It's just assigning values to variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toJSON
does the escaping. That said, this was from a previous attempt where I was setting outputs in this step and then using them in the next step. This step shouldn't be needed now that we're using standard environment variables.
b473b8e
to
6e775fb
Compare
6e775fb
to
2bc6d62
Compare
The proper fix definitely feels like it would be to rewrite the action to be a JavaScript action rather than a composite action, but that's much more involved. |
The first commit is the fix, the rest is to make this hopefully somewhat saner.