"run:" not handling conditionals properly

Hi, I’m having some trouble (well, big trouble) trying to set some outputs from a bash multiline script in a workflow and some help will be hugely appreciated.

This is the problematic step in my job:

      # Set up variables
      - name: Set up variables
        id: vars
        shell: bash
        run: |
            if ["${{ github.event_name }}" == "push"]; then
              echo "::set-output name=DRIVE_FOLDER::${{ env.DRIVE_DEV_FOLDER }}"
            elif ["${{ github.event_name }}" == "pull_request"]; then
              echo "::set-output name=DRIVE_FOLDER::${{ env.DRIVE_TEST_FOLDER }}"
            fi

And this is the log I am getting (sensitive info redacted):

Run if ["push" == "push"]; then
  if ["push" == "push"]; then
    echo "::set-output name=DRIVE_FOLDER::***"
  elif ["push" == "pull_request"]; then
    echo "::set-output name=DRIVE_FOLDER::***"
  fi
  shell: /bin/bash -e {0}
  env:
    UNITY_LICENSE: ***
    DRIVE_DEV_FOLDER: ***
    DRIVE_TEST_FOLDER: ***
/home/runner/work/_temp/f53e2665-c70c-404f-ad37-35543db96cc5.sh: line 1: [push: command not found
/home/runner/work/_temp/f53e2665-c70c-404f-ad37-35543db96cc5.sh: line 3: [push: command not found

Thank you very much in advance, please feel free to ask for anything else that could help you understand the issue.

  1. You need to have spaces between square brackets and the expression. The opening bracket is actually a command (namely, an alias of the test command).
  2. String comparison for equality in the test command is just a single “equals” sign.

So you need to do it like this:

if [ "${{ github.event_name }}" = "push" ]; then
    echo "::set-output name=DRIVE_FOLDER::***"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
    echo "::set-output name=DRIVE_FOLDER::***"
fi
2 Likes

Thank you kind sir, you brilliantly solved my problem.

You’re very welcome, but it’s “ma’am” in my case. :slightly_smiling_face: