github

How to set `run-name` conditionally in a github workflow


Is it possible to conditionally set run-name in a github workflow? My workflow can either be triggered from the current repo (ci-systems) with the use of workflow_dispatch, or through the use of workflow_call from another repo's workflow_dispatch.

I would love to do something like the following to have the run-name set as My Regression tests: Version_A + ci-systems: my_branch for example.

name: my tests
run-name: >-
  if [[ ${{ github.event.repository.name }} == "ci-systems" ]]; then
    My Regression tests: ${{ inputs.my_version }} + ci-systems: ${{ github.head_ref || github.ref_name }}
  else
    My Regression tests: ${{ inputs.my_version }}


on:
  workflow_call:
    inputs:
      my_version:
        type: string
        default: Version_O
  workflow_dispatch:
    inputs:
      my_version:
        type: string
        default: Version_X

Solution

  • Solution is found to be:

    run-name: >-
      ${{ github.event.repository.name == 'ci-systems'
        && format('My Regression tests: drv:{0} + ci-systems:{1}',
                  inputs.my_version,
                  github.head_ref || github.ref_name)
        || format('My Regression tests: {0}', inputs.my_version) }}