Skip to content

Commit

Permalink
Merge pull request #30 from rainforestapp/revert-29-RF-27572/pp/escap…
Browse files Browse the repository at this point in the history
…e-strings

Revert "[RF-27572] Handle quotes in passed in parameters"
  • Loading branch information
magni- authored Mar 17, 2023
2 parents 96981cb + 68efe36 commit c21865a
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 174 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ jobs:
shell: bash
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/[email protected]
with:
scandir: './steps'
- name: Install faketime
run: |
sudo apt-get update
Expand Down Expand Up @@ -96,21 +92,6 @@ jobs:
with:
actual: ${{ steps.test_branch.outputs.command }}
expected: run --skip-update --token "test_token" --run-group 42 --junit-file results/rainforest/junit.xml --save-run-id .rainforest_run_id --branch "feature-branch" --description "foo bar" --release "1.0"
- name: Quoted parameters command
id: test_quoted_parameters
uses: ./
with:
token: test_token
run_group_id: 42
description: something"exit 1
branch: some name"exit 2
release: some sha"exit 3
dry_run: true
- name: Quoted parameters test
uses: ./.github/actions/test
with:
actual: ${{ steps.test_quoted_parameters.outputs.command }}
expected: run --skip-update --token "test_token" --run-group 42 --junit-file results/rainforest/junit.xml --save-run-id .rainforest_run_id --branch "some name\"exit 2" --description "something\"exit 1" --release "some sha\"exit 3"
- name: Missing token command
id: test_missing_token
uses: ./
Expand Down
153 changes: 135 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ runs:
steps:
- name: Set Action Version
shell: bash
run: echo "RF_ACTION_VERSION=3.2.1" >> $GITHUB_ENV
run: |
echo "version=3.2.2" >> $GITHUB_ENV
- name: Check for reruns
uses: pat-s/always-upload-cache@v3
if: (! inputs.dry_run)
Expand All @@ -101,26 +102,142 @@ runs:
path: .rainforest_run_id
restore-keys: |
rainforest-run-${{ github.run_id }}-${{ inputs.cache_key }}-
- name: Validate Parameters
shell: bash
id: validate
env:
RF_DESCRIPTION: ${{ inputs.description }}
RF_RUN_GROUP_ID: ${{ inputs.run_group_id }}
RF_ENVIRONMENT_ID: ${{ inputs.environment_id }}
RF_CUSTOM_URL: ${{ inputs.custom_url }}
RF_CONFLICT: ${{ inputs.conflict }}
RF_EXECUTION_METHOD: ${{ inputs.execution_method }}
RF_CROWD: ${{ inputs.crowd }}
RF_RELEASE: ${{ inputs.release }}
RF_AUTOMATION_MAX_RETRIES: ${{ inputs.automation_max_retries }}
RF_BRANCH: ${{ inputs.branch }}
RF_TOKEN: ${{ inputs.token }}
RF_BACKGROUND: ${{ inputs.background }}
RF_DRY_RUN: ${{ inputs.dry_run }}
RF_CACHE_KEY: ${{ inputs.cache_key }}
run: steps/validate.sh
run: |
# Show Action Version
echo "Using Rainforest GitHub Action v${{ env.version }}"
# Ensure results directory is there
mkdir -p results/rainforest
echo "::add-mask::${{ inputs.token }}"
# Define error helper
error () {
echo "::error ::${1}"
echo "error=${1}" >> $GITHUB_OUTPUT
exit 1
}
# Validate token
if [ -z "${{ inputs.token }}" ] ; then
error "Token not set"
fi
# Validate run_group_id
if ! echo "${{ inputs.run_group_id }}" | grep -Eq '^[0-9]+$' ; then
error "run_group_id not a positive integer (${{ inputs.run_group_id }})"
fi
# Check for rerun
if [ -s .rainforest_run_id ] ; then
RAINFOREST_RUN_ID=$(cat .rainforest_run_id)
rm .rainforest_run_id
echo "Rerunning Run ${RAINFOREST_RUN_ID}"
RUN_COMMAND="rerun \"${RAINFOREST_RUN_ID}\" --skip-update --token \"${{ inputs.token }}\" --junit-file results/rainforest/junit.xml --save-run-id .rainforest_run_id"
else
RUN_COMMAND="run --skip-update --token \"${{ inputs.token }}\" --run-group ${{ inputs.run_group_id }} --junit-file results/rainforest/junit.xml --save-run-id .rainforest_run_id"
fi
# Validate conflict
if [ -n "${{ inputs.conflict }}" ] ; then
case "${{ inputs.conflict }}" in
cancel) ;&
cancel-all)
RUN_COMMAND="${RUN_COMMAND} --conflict ${{ inputs.conflict }}"
;;
*)
error "${{ inputs.conflict }} not in (cancel cancel-all)"
;;
esac
fi
# Set custom_url, or validate and set environment_id
if [ -z "${RAINFOREST_RUN_ID}" ] && [ -n "${{ inputs.custom_url }}" ] ; then
RUN_COMMAND="${RUN_COMMAND} --custom-url \"${{ inputs.custom_url }}\""
if [ -n "${{ inputs.environment_id }}" ] ; then
echo "::warning title=Environment ID Ignored::You've set values for the mutually exclusive custom_url and environment_id parameters. Unset one of these to fix this warning."
fi
elif [ -z "${RAINFOREST_RUN_ID}" ] && [ -n "${{ inputs.environment_id }}" ] ; then
if echo "${{ inputs.environment_id }}" | grep -Eq '^[0-9]+$' ; then
RUN_COMMAND="${RUN_COMMAND} --environment-id ${{ inputs.environment_id }}"
else
error "environment_id not a positive integer (${{ inputs.environment_id }})"
fi
fi
# Validate execution_method / crowd
if [ -z "${RAINFOREST_RUN_ID}" ] ; then
if [ -n "${{ inputs.execution_method }}" ] ; then
case "${{ inputs.execution_method }}" in
automation) ;&
crowd) ;&
automation_and_crowd) ;&
on_premise)
RUN_COMMAND="${RUN_COMMAND} --execution-method ${{ inputs.execution_method }}"
;;
*)
error "${{ inputs.execution_method }} not in (automation crowd automation_and_crowd on_premise)"
;;
esac
fi
if [ -n "${{ inputs.crowd }}" ] ; then
if [ -n "${{ inputs.execution_method }}" ] ; then
error "Error: execution_method and crowd are mutually exclusive"
fi
case "${{ inputs.crowd }}" in
default) ;&
automation) ;&
automation_and_crowd) ;&
on_premise_crowd)
RUN_COMMAND="${RUN_COMMAND} --crowd ${{ inputs.crowd }}"
;;
*)
error "${{ inputs.crowd }} not in (default automation automation_and_crowd on_premise_crowd)"
;;
esac
fi
fi
# Validate automation_max_retries
if [ -n "${{ inputs.automation_max_retries }}" ] ; then
if echo "${{ inputs.automation_max_retries }}" | grep -Eq '^[0-9]+$' ; then
RUN_COMMAND="${RUN_COMMAND} --automation-max-retries ${{ inputs.automation_max_retries }}"
else
error "automation_max_retries not a positive integer (${{ inputs.automation_max_retries }})"
fi
fi
# Set branch
if [ -n "${{ inputs.branch }}" ] ; then
RUN_COMMAND="${RUN_COMMAND} --branch \"${{ inputs.branch }}\""
fi
# Set description
if [ -z "${RAINFOREST_RUN_ID}" ] && [ -n "${{ inputs.description }}" ] ; then
RUN_COMMAND="${RUN_COMMAND} --description \"${{ inputs.description }}\""
elif [ -z "${RAINFOREST_RUN_ID}" ] ; then
RUN_COMMAND="${RUN_COMMAND} --description \"${GITHUB_REPOSITORY} - ${GITHUB_REF_NAME} ${GITHUB_JOB} $(date -u +'%FT%TZ')\""
fi
# Set release
if [ -n "${{ inputs.release }}" ] ; then
RUN_COMMAND="${RUN_COMMAND} --release \"${{ inputs.release }}\""
elif [ -z "${RAINFOREST_RUN_ID}" ] ; then
RUN_COMMAND="${RUN_COMMAND} --release \"${GITHUB_SHA}\""
fi
# Set background
if [ -n "${{ inputs.background }}" ] ; then
RUN_COMMAND="${RUN_COMMAND} --background"
fi
echo "command=${RUN_COMMAND}" >> $GITHUB_OUTPUT
- name: Run Rainforest
uses: docker://gcr.io/rf-public-images/rainforest-cli:latest
Expand Down
137 changes: 0 additions & 137 deletions steps/validate.sh

This file was deleted.

0 comments on commit c21865a

Please sign in to comment.