How to show when I am running a tagged build?

How can I do something like this:

jobs:
  tests:
    name: ${{ matrix.name }} {{ if startsWith(github.ref, 'refs/tags/') "Tagged" else "" }}

i.e., when if startsWith(github.ref, 'refs/tags/') is true, my build name should be ${{ matrix.name }} Tagged, but when if startsWith(github.ref, 'refs/tags/') is false, my build name should be only ${{ matrix.name }}.

I know I could do something like:

jobs:
  tests:
    name: ${{ matrix.name }} startsWith(github.ref, 'refs/tags/')

Which would make my build names like ${{ matrix.name }} true and ${{ matrix.name }} false, but this is too verbose and does not auto explain what true and false means.

@evandrocoan ,

You can try to add a job to check if the github.ref is a tag , and set a job-level output to mark the check result, then pass this output to the name of the tests job.
A simple demo:

jobs:
  check_tag:
    name: Check tag
    outputs:
      tagged: ${{ steps.check_tagged.outputs.is_tagged }}
    runs-on: ubuntu-latest
    steps:
      - name: Check the ref
        id: check_tagged
        run: |
          if [[${{ github.ref }} == refs/tags/*]]; then
            echo "::set-output name=is_tagged::Tagged"
          else
            echo "::set-output name=is_tagged:: "
          fi
  tests:
needs: [check_tag]
    name: ${{ matrix.name }} ${{ needs.check_tag.outputs.tagged }}
    . . .

Description:

1) Add the check_tag job to check if the github.ref is a tag : if the ref is a tag, set the value of the step-level output to be " Tagged"; if the ref is not a tag, set the value of the step-level output to be a whitespace , of course you also can set it to be others (such as " Not Tagged") instead of  whitespace. Use the property " steps.<step id>.outputs.<output name>" of the steps context to pass the value of the step-level output to the job-level output.

2) Set the  tests job needs  check_tag job, then you can use the property " needs.<job id>.outputs.<output name>" of the needs context to access the value of the job-level output from the  check_tag job.

1 Like