Skip to content

Commit 7e0299b

Browse files
authored
Only delete scheduled workflows when needed (#29091) (#29235)
Backport #29091 Fix #29040 `handleSchedules` should be called only if `DetectWorkflows` should detect schedule workflows
1 parent 933cc4d commit 7e0299b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

services/actions/notifier_helper.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ func notify(ctx context.Context, input *notifyInput) error {
149149

150150
var detectedWorkflows []*actions_module.DetectedWorkflow
151151
actionsConfig := input.Repo.MustGetUnit(ctx, unit_model.TypeActions).ActionsConfig()
152+
shouldDetectSchedules := input.Event == webhook_module.HookEventPush && git.RefName(input.Ref).BranchName() == input.Repo.DefaultBranch
152153
workflows, schedules, err := actions_module.DetectWorkflows(gitRepo, commit,
153154
input.Event,
154155
input.Payload,
155-
input.Event == webhook_module.HookEventPush && git.RefName(input.Ref).BranchName() == input.Repo.DefaultBranch,
156+
shouldDetectSchedules,
156157
)
157158
if err != nil {
158159
return fmt.Errorf("DetectWorkflows: %w", err)
@@ -199,8 +200,10 @@ func notify(ctx context.Context, input *notifyInput) error {
199200
}
200201
}
201202

202-
if err := handleSchedules(ctx, schedules, commit, input, ref); err != nil {
203-
return err
203+
if shouldDetectSchedules {
204+
if err := handleSchedules(ctx, schedules, commit, input, ref); err != nil {
205+
return err
206+
}
204207
}
205208

206209
return handleWorkflows(ctx, detectedWorkflows, commit, input, ref)

0 commit comments

Comments
 (0)