action工作流忽略dsl语言修改时push事件的触发执行

This commit is contained in:
xxq250 2025-01-21 08:37:48 +08:00
parent ec4fa231c7
commit 96faecd429
1 changed files with 45 additions and 0 deletions

View File

@ -5,6 +5,8 @@ package actions
import (
"bytes"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/gitdiff"
"context"
"fmt"
"strings"
@ -158,6 +160,17 @@ func notify(ctx context.Context, input *notifyInput) error {
return fmt.Errorf("gitRepo.GetCommit: %w", err)
}
maxLines := setting.Git.MaxGitDiffLines
diff, err := gitdiff.GetDiff(gitRepo,
&gitdiff.DiffOptions{
AfterCommitID: commit.ID.String(),
SkipTo: "",
MaxLines: maxLines,
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
MaxFiles: -1, // GetDiff() will return all files
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(""),
})
var detectedWorkflows []*actions_module.DetectedWorkflow
actionsConfig := input.Repo.MustGetUnit(ctx, unit_model.TypeActions).ActionsConfig()
shouldDetectSchedules := input.Event == webhook_module.HookEventPush && git.RefName(input.Ref).BranchName() == input.Repo.DefaultBranch
@ -178,11 +191,17 @@ func notify(ctx context.Context, input *notifyInput) error {
len(schedules),
)
breakLoop:
for _, wf := range workflows {
if actionsConfig.IsWorkflowDisabled(wf.EntryName) {
log.Trace("repo %s has disable workflows %s", input.Repo.RepoPath(), wf.EntryName)
continue
}
for _, file := range diff.Files {
if (strings.Contains(file.Name, ".gitea/workflows/") || strings.Contains(file.Name, ".github/workflows/")) && (strings.HasSuffix(file.Name, ".yml") || strings.HasSuffix(file.Name, ".yaml")) {
goto breakLoop
}
}
if wf.TriggerEvent.Name != actions_module.GithubEventPullRequestTarget {
detectedWorkflows = append(detectedWorkflows, wf)
@ -505,3 +524,29 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
}
func ListWorkflowsByWorkflow(commit *git.Commit, workflow string) (git.Entries, error) {
tree, err := commit.SubTree(".gitea/workflows")
if _, ok := err.(git.ErrNotExist); ok {
tree, err = commit.SubTree(".github/workflows")
}
if _, ok := err.(git.ErrNotExist); ok {
return nil, nil
}
if err != nil {
return nil, err
}
entries, err := tree.ListEntriesRecursiveFast()
if err != nil {
return nil, err
}
ret := make(git.Entries, 0, len(entries))
for _, entry := range entries {
if workflow == entry.Name() && (strings.HasSuffix(entry.Name(), ".yml") || strings.HasSuffix(entry.Name(), ".yaml")) {
ret = append(ret, entry)
}
}
return ret, nil
}