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

Using on.push, tags-ignore and paths-ignore together

I'm struggle to get the behaviour I want with GitHub Actions.

 

What I'm after is:

  • When a developer pushes a commit to GitHub, the "push" workflow occurs.
  • When a release is made, the "release" workflow occurs, but not the "push" workflow.
  • Changes to certain files (i.e. setup.py) do not trigger the "push" workflow

 

This is the YAML I believe should work for the push workflow:

on:
  push:
    tags-ignore:
      - '*.*'             # We don't want this to run on release
    paths-ignore:         # Don't trigger on files that are updated by the CI
      - pyproject.toml
      - setup.py
      - README.rst

I have the following for the release workflow:

on:
  release:
    types: [published]

However, given the above configuration, NO workflows are triggered when I push a commit.

 

If I remove the tags-ignore element, then workflows trigger, but when I do a release, the "push" workflow still triggers as well (I believe because it results in a tag push).

 

I haven't yet been at all able to make the paths-ignore syntax work.

 

Some assistance would be greatly appreciated.

4 Replies
GitHub Partner
Message 2 of 5

Re: Using on.push, tags-ignore and paths-ignore together

Hi @stevegore ,

 

There are several notes need you pay attention to:

  • If only define only tags filter (tags/ tags-ignore) or only branches filter (branches/ branches-ignore) for on.push, the workflow won't run for events affecting the undefined Git ref.
  • If neither define tags filter nor branches filter for on.push, the workflow will run for both push commits to branches and push to tags.
  • Whether the paths filter (paths/ paths-ignore) is defined does not affect the above two points.

If you want your "push" workflow can run for specific branches and specific tags, you need to add both branches filter and tags filter.

For example:

1) With the following filters, the workflow will run when push commits to the master branch, or when push to the tags that do not match the pattern in tags-ignore.

example01.PNG

2) With the following filters, the workflow will run when push commits to any branch, or when push to the tags that do not match the pattern in tags-ignore.

example02.PNG

Copilot Lvl 3
Message 3 of 5

Re: Using on.push, tags-ignore and paths-ignore together

Thanks for replying.

 

I managed to get something close to what I'm after using:

on:
  push:
    branches:
      - '**'
    tags-ignore:
      - '*.*'

However, paths-ignore is still not working for me. Changes to the ignored paths are still triggering actions. This is the YAML, including the paths-ignore:

 

on:
  push:
    branches:
      - '**'
    tags-ignore:
      - '*.*'
    paths-ignore:
      - README.rst

Changes to README.rst are still triggering a build. Should I raise an issue?

GitHub Partner
Message 4 of 5

Re: Using on.push, tags-ignore and paths-ignore together

@stevegore Can you confirm whether the ignored file README.rst is located at the root directory of the repository?

If it is in a sub-folder of the root directory, not the root directory, the syntax you used to reference the ignored file is correct. You should provide the complete relative path of the ignored file.

For example:

root
 └ docs
    └ README.rst
paths-ignore:
  - docs/README.rst
Copilot Lvl 2
Message 5 of 5

Re: Using on.push, tags-ignore and paths-ignore together

I'm finding the implicit rules quite hard to understand, perhaps because the way they are worded, or because the language used is not the one I can find in the git docs, or perhaps I just don't know enough about git internals –  even though I would consider myself an experienced git user.

 

Take the following statement:

> If only define only tags filter (tags/ tags-ignore) or only branches filter (branches/ branches-ignore) for on.push, the workflow won't run for events affecting the undefined Git ref.

 

1. Does "events affecting the undefined Git ref" refer to events which don't have a ref associated? Is there a thing as a undefined git ref?
2. Isn't it the case that "the workflow won't run for events affecting the undefined Git ref", even if both tags filter and braches filter are defined at the same time? After all, if there is no branch ref, and no tag ref, why would the workflow be triggered?

 

Clarification on both this points would be greatly appreciated. Thank you in advance.