From b408bf2f0bb6e76e73421e63128f08d42047e7c0 Mon Sep 17 00:00:00 2001 From: endo0911engineer <161911062+endo0911engineer@users.noreply.github.com> Date: Tue, 10 Jun 2025 02:44:45 +0900 Subject: [PATCH] Fix: skip paths check on tag push events in workflows (#34602) ## Summary Fix skipping of `paths` condition in workflows triggered by tag push events. ## Details - Ensure workflows triggered by tag pushes bypass the `paths` filter check. - Prevent incorrect skipping of workflows due to `paths` conditions on tag pushes. - Added and updated unit tests to verify correct behavior. --- modules/actions/workflows.go | 8 ++++++++ modules/actions/workflows_test.go | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index 31f859953e..84b3225338 100644 --- a/modules/actions/workflows.go +++ b/modules/actions/workflows.go @@ -313,6 +313,10 @@ func matchPushEvent(commit *git.Commit, pushPayload *api.PushPayload, evt *jobpa matchTimes++ } case "paths": + if refName.IsTag() { + matchTimes++ + break + } filesChanged, err := commit.GetFilesChangedSinceCommit(pushPayload.Before) if err != nil { log.Error("GetFilesChangedSinceCommit [commit_sha1: %s]: %v", commit.ID.String(), err) @@ -326,6 +330,10 @@ func matchPushEvent(commit *git.Commit, pushPayload *api.PushPayload, evt *jobpa } } case "paths-ignore": + if refName.IsTag() { + matchTimes++ + break + } filesChanged, err := commit.GetFilesChangedSinceCommit(pushPayload.Before) if err != nil { log.Error("GetFilesChangedSinceCommit [commit_sha1: %s]: %v", commit.ID.String(), err) diff --git a/modules/actions/workflows_test.go b/modules/actions/workflows_test.go index c8e1e553fe..e23431651d 100644 --- a/modules/actions/workflows_test.go +++ b/modules/actions/workflows_test.go @@ -125,6 +125,24 @@ func TestDetectMatched(t *testing.T) { yamlOn: "on: schedule", expected: true, }, + { + desc: "push to tag matches workflow with paths condition (should skip paths check)", + triggedEvent: webhook_module.HookEventPush, + payload: &api.PushPayload{ + Ref: "refs/tags/v1.0.0", + Before: "0000000", + Commits: []*api.PayloadCommit{ + { + ID: "abcdef123456", + Added: []string{"src/main.go"}, + Message: "Release v1.0.0", + }, + }, + }, + commit: nil, + yamlOn: "on:\n push:\n paths:\n - src/**", + expected: true, + }, } for _, tc := range testCases {