[PR #2729] feat: Support filtering workflows using on.<> filters and events #2576

Open
opened 2026-03-01 22:37:11 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/nektos/act/pull/2729
Author: @john-tipper
Created: 4/11/2025
Status: 🔄 Open

Base: masterHead: #2489-filter-workflows-by-events


📝 Commits (4)

  • e948801 Support filtering workflows by on.<> filters.
  • 8a77428 Don't try to handle path filters in pull request events.
  • 750e5f3 Add missing files
  • 943bd64 Merge branch 'master' into #2489-filter-workflows-by-events

📊 Changes

17 files changed (+2905 additions, -84 deletions)

View changed files

📝 cmd/input.go (+1 -0)
📝 cmd/root.go (+28 -51)
📝 go.mod (+2 -0)
📝 go.sum (+5 -0)
📝 pkg/artifacts/server_test.go (+1 -1)
📝 pkg/model/planner.go (+57 -20)
📝 pkg/model/planner_test.go (+640 -1)
pkg/model/testdata/filter-events/pr-opened.json (+532 -0)
pkg/model/testdata/filter-events/push-foo.json (+219 -0)
pkg/model/testdata/filter-events/push-master.json (+219 -0)
pkg/model/testdata/filter-events/push-tag-v1.json (+219 -0)
pkg/model/testdata/filter-events/push-tag-v2.json (+219 -0)
📝 pkg/model/workflow.go (+370 -0)
📝 pkg/model/workflow_test.go (+383 -2)
📝 pkg/runner/reusable_workflow.go (+2 -2)
📝 pkg/runner/runner.go (+1 -0)
📝 pkg/runner/runner_test.go (+7 -7)

📄 Description

resolves #2489

This PR adds a non-breaking change to add a --apply-event-filters flag.

  • When not set, there is no change to Act's existing behaviour.
  • When set, Act will filter workflows using the on.<> filters (paths, paths_ignore, tags, tags_ignore, branches, branches_ignore).

Limitations:

  • for push events, filtering paths is done using the commits referenced in the GitHub Webhook event which I think this is where GHA gets its information.
  • for pull_request and pull_request_target events, there is no guarantee that Act will actually be running with access to the actual git repo that's in GitHub (either locally on disk or via the network). I've elected for now to not handle this case, so workflows that set path filters.

More detailed thoughts on paths and pull request events:

GitHub says it does a 3 dot diff between base and head (https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests)

"The three-dot comparison shows the difference between the latest common commit of both branches (merge base) and the most recent version of the topic branch."

We could get the 2 SHA values from githubPullRequestEvent, but we'd have to decide whether we want to:

  • read from git on disk to perform the diff, perhaps from working directory or by reference to the path of the workflow files
  • clone from repo (requires credentials)
  • use the GitHub API (requires credentials)
  • do something else
  • do nothing

I've elected to do nothing for now, happy to consider adding this in later if we can agree the way forward.

Additional changes:

I removed a section of dead code around filtering, given that it just fed the list/graph output but didn't do anything else. That printing logic has been moved further down in root.go to be able to use variables that are defined later.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/nektos/act/pull/2729 **Author:** [@john-tipper](https://github.com/john-tipper) **Created:** 4/11/2025 **Status:** 🔄 Open **Base:** `master` ← **Head:** `#2489-filter-workflows-by-events` --- ### 📝 Commits (4) - [`e948801`](https://github.com/nektos/act/commit/e94880174ff6a7d8d1dfe16d8e84ae0b51caa7c1) Support filtering workflows by on.<> filters. - [`8a77428`](https://github.com/nektos/act/commit/8a774288b933c9b81ac4a63db718b5d6a021f413) Don't try to handle path filters in pull request events. - [`750e5f3`](https://github.com/nektos/act/commit/750e5f39eb03423b8bd8cd8b4b30b9285d319925) Add missing files - [`943bd64`](https://github.com/nektos/act/commit/943bd6412920bee35fd164eb4007e1824bf9353b) Merge branch 'master' into #2489-filter-workflows-by-events ### 📊 Changes **17 files changed** (+2905 additions, -84 deletions) <details> <summary>View changed files</summary> 📝 `cmd/input.go` (+1 -0) 📝 `cmd/root.go` (+28 -51) 📝 `go.mod` (+2 -0) 📝 `go.sum` (+5 -0) 📝 `pkg/artifacts/server_test.go` (+1 -1) 📝 `pkg/model/planner.go` (+57 -20) 📝 `pkg/model/planner_test.go` (+640 -1) ➕ `pkg/model/testdata/filter-events/pr-opened.json` (+532 -0) ➕ `pkg/model/testdata/filter-events/push-foo.json` (+219 -0) ➕ `pkg/model/testdata/filter-events/push-master.json` (+219 -0) ➕ `pkg/model/testdata/filter-events/push-tag-v1.json` (+219 -0) ➕ `pkg/model/testdata/filter-events/push-tag-v2.json` (+219 -0) 📝 `pkg/model/workflow.go` (+370 -0) 📝 `pkg/model/workflow_test.go` (+383 -2) 📝 `pkg/runner/reusable_workflow.go` (+2 -2) 📝 `pkg/runner/runner.go` (+1 -0) 📝 `pkg/runner/runner_test.go` (+7 -7) </details> ### 📄 Description resolves #2489 This PR adds a non-breaking change to add a `--apply-event-filters` flag. - When not set, there is no change to Act's existing behaviour. - When set, Act will filter workflows using the on.<> filters (paths, paths_ignore, tags, tags_ignore, branches, branches_ignore). **Limitations:** - for push events, filtering paths is done using the commits referenced in the GitHub Webhook event which I think this is where GHA gets its information. - for pull_request and pull_request_target events, there is no guarantee that Act will actually be running with access to the actual git repo that's in GitHub (either locally on disk or via the network). I've elected for now to not handle this case, so workflows that set path filters. More detailed thoughts on paths and pull request events: GitHub says it does a 3 dot diff between base and head (https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests) > "The three-dot comparison shows the difference between the latest common commit of both branches (merge base) and the most recent version of the topic branch." We could get the 2 SHA values from githubPullRequestEvent, but we'd have to decide whether we want to: - read from git on disk to perform the diff, perhaps from working directory or by reference to the path of the workflow files - clone from repo (requires credentials) - use the GitHub API (requires credentials) - do something else - do nothing I've elected to do nothing for now, happy to consider adding this in later if we can agree the way forward. **Additional changes:** I removed a section of dead code around filtering, given that it just fed the list/graph output but didn't do anything else. That printing logic has been moved further down in `root.go` to be able to use variables that are defined later. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#2576
No description provided.