0

I have the following workflow in my GitHub actions:

name: Tests e2e iOS App

on:
  workflow_dispatch:
    inputs:
      skip:
        type: boolean
        required: true
        default: false

jobs:
  build-simu-ios-zip:
    name: Build iOS simulator zip
    uses: ./.github/workflows/reusable-e2e-buildsimuioszip.yml
    secrets: inherit
    with:
      environment: ${{ inputs.environment }}

I would like to run the job build-simu-ios-zip conditionnaly, I add the following:

jobs:
  build-simu-ios-zip:
    name: Build iOS simulator zip
+   if: ${{ inputs.skip == 'false' }}
    uses: ./.github/workflows/reusable-e2e-buildsimuioszip.yml
    secrets: inherit
    with:
      environment: ${{ inputs.environment }}

But the job automatically get skipped.

I also tried to pass an input to the reusable workflow and make it conditionnaly it from there, but it also skip.

How can I make a conditionnal reusable workflow in GitHub action?

Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204

1 Answers1

1

I made some tests here and using if: ${{ inputs.skip == 'false' }} with single quotes ' doesn't work as you are comparing a boolean type with a string.

However, I found 2 options that worked:

  • if: ${{ inputs.skip == false }} (no quote)

  • if: ${{ ! inputs.skip }} (as it's a boolean input, but with !)

Note: I used this workflow for tests.

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71
  • It work, but I had to use `if: ${{ always() }}` on the following job otherwise both jobs are skipped. – Dimitri Kopriwa Dec 02 '22 at 10:00
  • Are the other jobs depending on this one with the condition, or from the input as well? – GuiFalourd Dec 02 '22 at 11:06
  • They conditionaly depend on this condition. If we enable demo, the other step will adapt, if we don't it will adapt. – Dimitri Kopriwa Dec 02 '22 at 11:11
  • Depending on the condition implemented in the `if` expression, it may indeed be necessary to use the `always()` to evaluate it each time, otherwise it might be skipped. – GuiFalourd Dec 02 '22 at 14:32
  • actually, we do not want `always()` we want when `inputs.skip` is `true`, to run it always, otherwise, it has to fail if the `build-simu-ios-zip` job fail. Do you have a clue ? – Dimitri Kopriwa Dec 03 '22 at 12:12
  • Did you try using the `build-simu-ios-zip` job status in the next job if expression? – GuiFalourd Dec 03 '22 at 13:01
  • It's a bit more complicated than that, I did some attempt without `${{ always() }}` without success. with `${{ inputs.skip == true || (inputs.skip == false && contains(join(needs.skip.result, ','), 'success')) }}`, without success – Dimitri Kopriwa Dec 03 '22 at 13:38