fortanu82
fortanu82

Reputation: 471

GitHub Action | Trigger pipeline for root folder except one sub folder

I wanted to trigger the pipeline when any file is changed in the directory or subdirectories of folder /ProjectA/ except /ProjectA/sub-dir-a.

I added the below event to achieve the results, however, it throws an error saying Path and Path-ignore cannot be added in the same event.

    on:
  push:
    branches: [ master ]
    paths: "ProjectA/**"
    paths-ignore: " ProjectA/sub-dir-a /**"

Error Received enter image description here

Further, If I change an event to include "paths" only, it triggers the pipeline even when any files are changed in the subfolder too.

I was looking for an option to exclude sub directory.

Upvotes: 7

Views: 4666

Answers (2)

Marcin Kłopotek
Marcin Kłopotek

Reputation: 5931

As you can see you cannot mix the paths with paths-ignore but if you look at the filter pattern cheat sheet and later at the pattern to match file paths section you can see you can also negate patterns:

Using an exclamation mark (!) in front of a pattern negates it. When a file matches a pattern and also matches a negative pattern defined later in the file, the file will not be included.

Having that in mind you can try with:

on:
  push:
    branches:
      - master
    paths: 
      - "ProjectA/**"
      - "!ProjectA/sub-dir-a/**"

EDIT

The example from the documentation covers exactly your case.

Upvotes: 13

Rohit Salecha
Rohit Salecha

Reputation: 1033

This is how I managed to do for a Github Action while building a Docker CI/CD pipeline. I wanted to avoid docker builds for README files (not a sub-folder as asked in the OP) so this is what I did

on:
  push:
    branches:
      - main
    paths:
      - "java/**"
      - "!**/README.md"
  pull_request:
    branches:
        - main

This worked like a charm.

Upvotes: 0

Related Questions