How to trigger on a release only if tag name matches pattern

I need to trigger an action only when we release we release a minor version change. Our tag format follows release/v1.2.0.0 where we have a major, minor, fix, nightly version. I want this action to trigger in the following circumstances:

release/v1.2.0.0

release/v1.3.0.0

release/v1.4.0.0

But not when the fix version is not zero, eg (should not trigger):

release/v1.2.1.0

release/v1.3.2.0

release/v1.4.3.0

I’m using this trigger:

on:
release:
types: [published]
tags:
-'release\/v[0-9]\*\.[0-9]\*\.0\.[0-9]\*'

But it still triggers whenever any tag is released/published. Is there a way to properly do this?

@dan-0 ,

The tags filter is not supported on release event, currently only supported on push event and pull_request event.

And the regular expression (release/v[0-9]*.[0-9]*.0.[0-9]*) you are using seems is not the right one, according to your request.

As a workaround, maybe you can reference the following configurations to configure your workflow:

on:
  release:
    types: [published]

jobs:
  check_tag:
    runs-on: ubuntu-latest
    outputs:
      run_other_jobs: ${{ steps.check-tag.outputs.run_jobs }}
    steps:
      - name: check tag ${{ github.ref }}
        id: check-tag
        run: |
          if [[${{ github.ref }} =~ refs\/tags\/release\/v[0-9]+\.[0-9]+\.0\.[0-9]+ ]]; then
            echo "::set-output name=run_jobs::true"
          else
            echo "::set-output name=run_jobs::false"
          fi

  job1:
    needs: [check_tag]
    if: needs.check_tag.outputs.run_other_jobs == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Run job1
        run: echo "Run job1"

  job2:
    needs: [check_tag]
    if: needs.check_tag.outputs.run_other_jobs == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Run job2
        run: echo "Run job2"

  . . .

  jobN:
    needs: [check_tag]
    if: needs.check_tag.outputs.run_other_jobs == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Run jobN
        run: echo "Run jobN"

Description:

  1. Add job " check_tag" to check whether the tag ref ( github.ref ) matchs the regular expression “refs/tags/release/v[0-9]+.[0-9]+.0.[0-9]+”. If matchs the regular expression, set the value of the step-level output " run_jobs" to be " true", otherwise set the value to be " false".

  2. Set a job-level output " run_other_jobs", and pass the value of " run_jobs" to " run_other_jobs".

3)  job1job2 , …,  jobN are the actual jobs you need to run for the release event. Set each job of them  needs  the job " check_tag". And add the if statement ( if: needs.check_tag.outputs.run_other_jobs == ‘true’ ) on each job to check the value of the job-level output ( run_other_jobs ).

  1. After the job " check_tag" run completed, the if statement ( if: needs.check_tag.outputs.run_other_jobs == ‘true’ ) will determine whether to execute  job1job2 , …,  jobN , or skip them.

Note:

This workaround is not actually prevent the workflow from being triggered, it just skip jobs in the workflow when the tag does not match the regular expression. This is the only way I can think of.