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.

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

2 Likes

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?

1 Like

@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
1 Like

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.

1 Like

@stevegore did you ever determine what the problem was with the paths-ignore for the README.md?

I ask because the following stanza still results in the workflow running even though the only change was to the README.md.

on:
push:
paths-ignore:
-'README.md'  
branches:
- master
- develop

Actually, nevermind - it works.

@brightran @stevegore @rbellamy @franciscolourenco Below is the workflow trigger I am using:-

on:

  push:

    paths-ignore:

      - '.github/project.yaml'

      - 'README.md'

      - LICENSE

    branches:

      - maste

   

paths-ignore works for me and the workflow doesn’t gets triggered if I do any changes on the ‘README.md’ and ‘LICENSE’ file. However, it doesn’t work for the path ‘.github/project.yaml’. I want that the workflow should not get triggerred if the changes are made only on the ‘project.yaml’ file which is present at location ‘.github/project.yaml’. however, it gets triggered currently and ‘paths-ignore’ doesn’t seems to be working for me in case of ‘.github/project.yaml’

It seems backwards that this would be an OR condition.

on:
  push:
    paths-ignore:
      - ".github/**"
      - "*.md"
    branches:
      - master

I don’t want the workflow to trigger on any branch but master, and even then I don’t want it to trigger on master when changes are on the paths mentioned.

Instead it sounds like it will always run on master, and also on any branch where a change to files except those in paths-ignore happens.