Skip to content

Conversation

magni-
Copy link
Contributor

@magni- magni- commented Mar 15, 2023

The first commit is the fix, the rest is to make this hopefully somewhat saner.

@marvin-rfbot
Copy link

marvin-rfbot bot commented Mar 15, 2023

@magni-
Copy link
Contributor Author

magni- commented Mar 15, 2023

/reviewme @jbarber @rainforestapp/devs

@marvin-rfbot marvin-rfbot bot added the review label Mar 15, 2023
@marvin-rfbot marvin-rfbot bot requested a review from jbarber March 15, 2023 10:08
# Define error helper
error () {
echo "::error ::${1}"
echo "error=${1}" >> "$GITHUB_OUTPUT"
Copy link
Member

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}" ?

Copy link
Contributor Author

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.

Copy link
Member

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"
Copy link
Member

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} ?

Copy link
Contributor Author

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//\"/\\\"}\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮 , are al those \ / necessary? 😅

Copy link
Member

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}

Copy link
Contributor Author

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//\"/\\\"}\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here 😅

Copy link
Member

@sebaherrera07 sebaherrera07 left a 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.

Copy link
Contributor

@jbarber jbarber left a 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add set -euo pipefail ?

Copy link
Contributor

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"
Copy link
Contributor

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.

Copy link
Contributor Author

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"
Copy link
Contributor

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 ..."

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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.

@magni- magni- force-pushed the RF-27572/pp/escape-strings branch from b473b8e to 6e775fb Compare March 17, 2023 00:13
@magni- magni- force-pushed the RF-27572/pp/escape-strings branch from 6e775fb to 2bc6d62 Compare March 17, 2023 00:17
@magni-
Copy link
Contributor Author

magni- commented Mar 17, 2023

Really does make me wonder if this should be done in not-shell

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.

@magni- magni- merged commit 96981cb into master Mar 17, 2023
@magni- magni- deleted the RF-27572/pp/escape-strings branch March 17, 2023 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants