in Technology by
How to use filters to target specific paths for pull request or push events?

1 Answer

0 votes
by

When using the push and pull_request events, you can configure a workflow to run based on what file paths are changed. Path filters are not evaluated for pushes of tags.

Use the paths filter when you want to include file path patterns or when you want to both include and exclude file path patterns. Use the paths-ignore filter when you only want to exclude file path patterns. You cannot use both the paths and paths-ignore filters for the same event in a workflow.

If you define both branches/branches-ignore and paths/paths-ignore, the workflow will only run when both filters are satisfied.

The paths and paths-ignore keywords accept glob patterns that use the * and ** wildcard characters to match more than one path name.

Example: Including paths

If at least one path matches a pattern in the paths filter, the workflow runs. For example, the following workflow would run anytime you push a JavaScript file (.js).

on:
  push:
    paths:
      - '**.js'


Example: Excluding paths

When all the path names match patterns in paths-ignore, the workflow will not run. If any path names do not match patterns in paths-ignore, even if some path names match the patterns, the workflow will run.

A workflow with the following path filter will only run on push events that include at least one file outside the docs directory at the root of the repository.

on:
  push:
    paths-ignore:
      - 'docs/**'

Example: Including and excluding paths

You can not use paths and paths-ignore to filter the same event in a single workflow. If you want to both include and exclude path patterns for a single event, use the paths filter along with the ! character to indicate which paths should be excluded.

If you define a path with the ! character, you must also define at least one path without the ! character. If you only want to exclude paths, use paths-ignore instead.

The order that you define patterns matters:

  • A matching negative pattern (prefixed with !) after a positive match will exclude the path.
  • A matching positive pattern after a negative match will include the path again.

This example runs anytime the push event includes a file in the sub-project directory or its subdirectories, unless the file is in the sub-project/docs directory. For example, a push that changed sub-project/index.js or sub-project/src/index.js will trigger a workflow run, but a push changing only sub-project/docs/readme.md will not.

on:
  push:
    paths:
      - 'sub-project/**'
      - '!sub-project/docs/**'

Related questions

0 votes
    How to use filters to target specific branches or tags for push events in GitHub Actions?...
asked Jun 19, 2023 in Technology by JackTerrance
0 votes
    I have created a branch named dev. I have done a pull request to send dev code to master, when I do ... to resolve these conflicts. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    How to use filters to target specific branches for pull request events in Github Actions?...
asked Jun 19, 2023 in Technology by JackTerrance
0 votes
    Ansible can work as a push automated deployment system and as well as a pull automated deployment system? (i)True (ii)False...
asked Jan 25, 2023 in Technology by JackTerrance
0 votes
    Merge the Pull request in GitHub for the updates made to starfeature branch. Which channel would receive notification ... . Stakeholders C. Starprojectteam D. None of the options...
asked Dec 23, 2022 in Technology by JackTerrance
0 votes
    Merge the Pull request in GitHub for the updates made to starfeature branch. Which channel would receive notification ... . Stakeholders C. Starprojectteam D. None of the options...
asked Dec 16, 2022 in Education by JackTerrance
0 votes
    Create a new Pull request. Review the changes between master and starfeature branch, and confirm by clicking Create ... . Stakeholders C. Starprojectteam D. None of the options...
asked Dec 23, 2022 in Technology by JackTerrance
0 votes
    @RequestMapping annotation is used to map a HTTP request method (GET or POST) to a specific class or method in the ... which will handle the respective request. A. True B. False...
asked Nov 8, 2022 in Education by JackTerrance
0 votes
0 votes
    What is the use of GitHub Actions?...
asked Apr 1, 2023 in Technology by JackTerrance
0 votes
    My git workspace is dirty, there are some local modifications. When I use the command git pull origin master it ... Ansible git module? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    How to use Push command in Git?...
asked Aug 24, 2021 in Technology by JackTerrance
0 votes
    (d) Which tool is used for drawing freehand shapes or paths? (i) Rectangle Tool (ii) Pencil Tool (iii) Line Tool (iv) Ovey Tool Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    How to automatically trigger GitHub Actions workflows?...
asked Jun 19, 2023 in Technology by JackTerrance
0 votes
    How you can help to reduce the risk of script injection?...
asked Apr 1, 2023 in Technology by JackTerrance
...