githubgithub-actions

Run jobs conditionally in GitHub Actions


I'm trying to control a list of services to deploy on GitHub Actions with checkboxes in workflow_dispatch:

  workflow_dispatch:
   inputs:
      graphics:
        type: boolean
        required: false
        default: false
      tags:
        description: 'trigger manually'
        
  push:
    branches:
      - "release"

jobs:  
  graphics:
    if: ${{ github.event.inputs.graphics == true || github.event.inputs.graphics == false }}
    name: call graphicstransform deploy
    uses: ./.github/workflows/deploygraphics.yml
    secrets: inherit
    with:
      external: 'true'

I'm checking for either true or false with github.event.inputs.graphics but the graphics job is never executed.

Why not? How can I run jobs conditionally in workflow_dispatch with checkbox booleans?


Solution

  • You have a typo in your inputs definition; According to the validation schema; One MUST specify whether input is required or not, and if it is not required, one MUST provide a default value.

        inputs:
          graphics:
            type: boolean
            required: true
          tags:
            type: string
            default: my_tag
            required: false
            description: "trigger manually"
    

    You also may access the input directly as shown in the example

    if: ${{ inputs.graphics == true }}
    

    Or like this

    if: ${{ github.event.inputs.graphics == "true" }}