How can I have a condition based input variable definition in a composite workflow

196 Views Asked by At

I have a job that calls a composite action as below:

  CHANGE_ORDER:

    needs:
      - SETVARS
    runs-on: 'windows-latest'
    steps:

      - name: Process CO Change Order
        uses: mmctech/betech/processCO@mm365

        env:
          SNOWTOKEN: ${{ secrets.SNOW_TOKEN }}

        with:
          environment: 'dev'
          action: “close”
          SNpass: ${{ env.SNOWTOKEN }}

Cat betech/processCO/action.yml

---
name: executeCO

inputs:

  environment:
    required: true
    default: "create"
    type: string

  action:
    required: true
    default: "create"
    type: string

  SNpass:
    required: true

runs:
  using: "composite"
  steps:
    - name: Create CO

      run: |
        if: ${{ inputs.action == ‘create’ }}

        set-location "${{ github.workspace }}\betech\Scripts"         
        $SNpass="${{ inputs.SNpass }}"
        Write-host ./CreateCO.ps1 -myenv "${{ inputs. environment }}" -SNpass $SNpass
      shell: powershell

    - name: Close CO
      run: |

        if: ${{ inputs.action == ‘close’ }}

        set-location "${{ github.workspace }}\betech\Scripts"         
        $SNpass="${{ inputs.SNpass }}"
        Write-host ./CloseCO.ps1 -myenv "${{ inputs. environment }}" -SNpass $SNpass
      shell: powershell

My requirement is that if the action passed is ‘close’ in which case the composite action’s environment variable should not be required i.e required: false else it should be true.

How can I have a condition based input variable definition in a composite workflow.

0

There are 0 best solutions below