1
0
mirror of synced 2026-01-01 09:04:46 -05:00
Files
docs/data/reusables/actions/workflows/section-triggering-a-workflow-paths.md
Ariel Deitcher 66b4330881 differentiate between skipped workflows and skipped jobs (#27394)
* differentiate between skipped workflows and skipped jobs

* Optimize images

* bad link

* Recreated screenshot

* Optimize images

* Apply suggestions from code review

Co-authored-by: Martin Lopes <martin389@github.com>

* Apply suggestions from code review

Co-authored-by: Martin Lopes <martin389@github.com>

* Apply suggestions from code review

Co-authored-by: Josh Gross <joshmgross@github.com>

* Apply suggestions from code review

* add links and clarify language again

* fix links

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Martin Lopes <martin389@github.com>
Co-authored-by: Josh Gross <joshmgross@github.com>
Co-authored-by: hubwriter <hubwriter@github.com>
2022-05-13 16:23:09 +00:00

79 lines
4.9 KiB
Markdown

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`, 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. For more information, see the "[Filter pattern cheat sheet](/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet)."
#### 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`).
```yaml
on:
push:
paths:
- '**.js'
```
{% note %}
**Note:** If a workflow is skipped due to [path filtering](/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore), [branch filtering](/actions/using-workflows/workflow-syntax-for-github-actions#onpull_requestpull_request_targetbranchesbranches-ignore) or a [commit message](/actions/managing-workflow-runs/skipping-workflow-runs), then checks associated with that workflow will remain in a "Pending" state. A pull request that requires those checks to be successful will be blocked from merging. For more information, see "[Handling skipped but required checks](/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks)."
{% endnote %}
#### 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.
```yaml
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.
```yaml
on:
push:
paths:
- 'sub-project/**'
- '!sub-project/docs/**'
```
#### Git diff comparisons
{% note %}
**Note:** If you push more than 1,000 commits, or if {% data variables.product.prodname_dotcom %} does not generate the diff due to a timeout, the workflow will always run.
{% endnote %}
The filter determines if a workflow should run by evaluating the changed files and running them against the `paths-ignore` or `paths` list. If there are no files changed, the workflow will not run.
{% data variables.product.prodname_dotcom %} generates the list of changed files using two-dot diffs for pushes and three-dot diffs for pull requests:
- **Pull requests:** Three-dot diffs are a comparison between the most recent version of the topic branch and the commit where the topic branch was last synced with the base branch.
- **Pushes to existing branches:** A two-dot diff compares the head and base SHAs directly with each other.
- **Pushes to new branches:** A two-dot diff against the parent of the ancestor of the deepest commit pushed.
Diffs are limited to 300 files. If there are files changed that aren't matched in the first 300 files returned by the filter, the workflow will not run. You may need to create more specific filters so that the workflow will run automatically.
For more information, see "[About comparing branches in pull requests](/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests)."