Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
phw
Copilot Lvl 3
Message 1 of 3

Combine path and tags conditionals

Solved! Go to Solution.

How is the logic when combining conditonals for push to restrict paths and tags or branches?

 

In my specific case I want to limit a workflow to only a specific list of paths, but I want to ensure it always runs on a tag. Interestingly if I only do something like this:

on:
  push:
    paths:
    - 'src/**'

 

The behavior is:

 

- If a commit contains change paths in src/** the workflow runs, if it does not contain any changes in src/** it does not run. This is as expected

- If I tag a commit that does not contain changes to src/** the workflow also runs on pushing this tag. This is kind of unexpected, but actually exactly what I want.

 

Is my observation correct? Can I rely on the workflow being run on every tag push?

 

And what happens if I define both paths and tags, e.g:

on:
  push:
    paths:
    - 'src/**'

    tags:

    - 'release-*'

The expecation would be that this runs on any push that changes src/** and also on an tag release-* independent of the paths in the changed commit. Is this correct? If not, how could I achieve this behavior?

2 Replies
Solution
GitHub Partner
Message 2 of 3

Re: Combine path and tags conditionals

Thank you for posting this question in Github Community forum.

Based on your requirement: The expecation would be that this runs on any push that changes src/** and also on an tag release-* independent of the paths in the changed commit.

You can add branches filter with paths and tags together:

on:
  push:
    paths:
      - 'src/**'
    branches:
      - master
    tags:
      - 'release-*'

Please note that:

1. Path filters are not evaluated for pushes to tags. You can found this sentence here.

This could explain that when you use path filter only, when you tag a commit that does not contain changes to src/** the workflow also runs on pushing this tag.

on:

  push:

    paths:

    - 'src/**'

2. If you only define only tagsor only branches, the workflow won't run for events affecting the undefined Git ref. You can found this sentence here.

When you just add paths and tags filter to on push event, tags filter will stop the workflow to be triggered by pushing to branches. So I suggest you to add branches filter.

 

phw
Copilot Lvl 3
Message 3 of 3

Re: Combine path and tags conditionals

Thanks a lot, this fuly answers my questions. I missed that part that path filters are ignored for tag pushes, but it makes sense and really helps in my case.