actions / runner

The Runner for GitHub Actions :rocket:
https://github.com/features/actions
MIT License
4.88k stars 956 forks source link

Reusable workflows do not respect conditional steps based on inputs. #2658

Closed jason-edstrom closed 11 months ago

jason-edstrom commented 1 year ago

Describe the bug Reusable workflow does not respect conditional inputs. The current behavior is that they run all steps listed in the reusable workflow. This is related to #1602.

To Reproduce Steps to reproduce the behavior:

  1. Create a reusable workflow that uses inputs in its conditional steps.
  2. Run
  3. See error

Expected behavior That I can conditionally run steps in a reusable workflow.

Runner Version and Platform

Version of your runner? 2.304.0

OS of the machine running the runner? OSX/Windows/Linux/... macOS arm64

What's not working?

My conditionals attached to steps in a reusable workflow should be respected. They are not and both steps will trigger.

image

Job Log Output

If applicable, include the relevant part of the job / step log output here. All sensitive information should already be masked out, but please double-check before pasting here.

Runner and Worker's Diagnostic Logs

If applicable, add relevant diagnostic log information. Logs are located in the runner's _diag folder. The runner logs are prefixed with Runner_ and the worker logs are prefixed with Worker_. Each job run correlates to a worker log. All sensitive information should already be masked out, but please double-check before pasting here.

Runner_20230612-205711-utc.log Worker_20230613-180512-utc.log

ChristopherHX commented 1 year ago

if: ${{inputs.platform}} == 'android'

Not even the vscode actions linter complain about this not implemented syntax.

It is effectively the same as writing true, because the result of the if is a non empty string and not a boolean.

The runner and the Actions Service only supports something like

if: inputs.platform == 'android'

I would really expect an error message on the runner and service telling the workflow author there is a syntax error in the if expression

jason-edstrom commented 1 year ago

Thanks for the reply, @ChristopherHX. I changed the conditionals' syntax to match your code snippet, which is still failing. The first conditional in the pair will always run (whether it should or not), and the second conditional fails shortly after entering the step. Out of curiosity, I tried to "hide" the conditionals in a composite step, but it still failed. The error message is not existent. It only presents me with the following:

Error: Process completed with exit code 1.

image

name: Prepare CodePush
description: prepare codepush folder structure
inputs:
  app_name:
    description: "App to bundle/build"
    required: true
  platform:
    description: "Platform to prepare for"
    required: true

runs:
  using: 'composite'
  steps:
    - name: Prepare Codepush Folder (iOS)
      if: inputs.platform == 'ios'
      shell: bash
      run: |
        mkdir ${{ github.workspace }}/apps/rn-apps/${{ inputs.app_name }}/codepush &>/dev/null
        mkdir -p ${{ github.workspace }}/apps/rn-apps/${{ inputs.app_name }}/build/ios &>/dev/null
    - name: Prepare Codepush Folder (Android)
      if: inputs.platform == 'android'
      shell: bash
      run: |
        mkdir ${{ github.workspace }}/apps/rn-apps/${{ inputs.app_name }}/codepush &>/dev/null
        mkdir -p ${{ github.workspace }}/apps/rn-apps/${{ inputs.app_name }}/build/android/sourcemaps &>/dev/null
        mkdir -p ${{ github.workspace }}/apps/rn-apps/${{ inputs.app_name }}/build/android/assets &>/dev/null
        mkdir -p ${{ github.workspace }}/apps/rn-apps/${{ inputs.app_name }}/build/android/res &>/dev/null
jason-edstrom commented 1 year ago

Update: It looks like I spoke too soon (or looked at the wrong build 🤦‍♂️ ).

I have both scenarios working with the syntax you laid out.

I would really expect an error message on the runner and service telling the workflow author there is a syntax error in the if expression

The error messaging does need to be better. I have a few tests that I have run:

ChristopherHX commented 1 year ago

The error message is not existent. It only presents me with the following:

Error: Process completed with exit code 1.

Isn't this the result of adding&>/dev/null to each line. Maybe remove the & to allow stderr to be shown in logs.

jason-edstrom commented 1 year ago

I'll double-check. My bad if this turns out to be a red herring. 😅

jason-edstrom commented 1 year ago

I changed the conditionals to one of the formats I mentioned: if: ${{inputs.platform}} == android. I also removed the /dev/null. to bring back the failure state. It does look like the /dev/null was eating some logging.

mkdir: ./actions-runner-osx-arm64-2.304.0/_work/retail-mobile-apps-sandbox/retail-mobile-apps-sandbox/apps/rn-apps/mercury/codepush: File exists
Error: Process completed with exit code 1.

I ran this to see if mkdir with the directory existing causes a failure state:

mkdir ./apps/rn-apps/mercury/codepush; mkdir ./apps/rn-apps/mercury/codepush-2/

It doesn't seem to block the successful execution of the second mkdir command. Does that seem accurate?