From d762687624e75bedaaa0d5bcb9d13d238bf2abf8 Mon Sep 17 00:00:00 2001 From: Mikolaj Gasior Date: Wed, 23 Oct 2024 10:18:27 +0200 Subject: [PATCH] Allow actions that are in 1 level subdirectories --- pkg/action/action.go | 2 +- pkg/action/action_step.go | 2 +- pkg/dotgithub/dot_github.go | 25 +++++++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index 34926b3..6816f00 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -125,7 +125,7 @@ func (a *Action) formatError(code string, desc string) string { } func (a *Action) validateDirName() (string, error) { - m, err := regexp.MatchString(`^[a-z0-9][a-z0-9\-]+$`, a.DirName) + m, err := regexp.MatchString(`^([a-z0-9][a-z0-9\-]+|[a-z0-9][a-z0-9\-]+/[a-z0-9][a-z0-9\-]+)$`, a.DirName) if err != nil { return "", err } diff --git a/pkg/action/action_step.go b/pkg/action/action_step.go index 85e4365..5012019 100644 --- a/pkg/action/action_step.go +++ b/pkg/action/action_step.go @@ -99,7 +99,7 @@ func (as *ActionStep) validateUses(action string, workflowJob string, name strin func (as *ActionStep) validateUsesLocalAction(actionName string, workflowJobName string, step string, uses string, d IDotGithub) ([]string, error) { var validationErrors []string - m, err := regexp.MatchString(`^\.\/\.github\/actions\/[a-z0-9\-]+$`, uses) + m, err := regexp.MatchString(`^\.\/\.github\/actions\/([a-z0-9\-]+|[a-z0-9\-]+\/[a-z0-9\-]+)$`, uses) if err != nil { return validationErrors, err } diff --git a/pkg/dotgithub/dot_github.go b/pkg/dotgithub/dot_github.go index 0682569..e5ca3d2 100644 --- a/pkg/dotgithub/dot_github.go +++ b/pkg/dotgithub/dot_github.go @@ -116,8 +116,17 @@ func (d *DotGithub) getActions() { } log.Fatal(err) } + + d.getActionsFromEntries(actionsPath, entries, "") +} + +func (d *DotGithub) getActionsFromEntries(actionsPath string, entries []os.DirEntry, parentDir string) { for _, e := range entries { entryPath := filepath.Join(actionsPath, e.Name()) + if parentDir != "" { + entryPath = filepath.Join(actionsPath, parentDir, e.Name()) + } + fileInfo, err := os.Stat(entryPath) if err != nil { log.Fatal(err) @@ -126,6 +135,14 @@ func (d *DotGithub) getActions() { continue } + if parentDir == "" { + entries2, err2 := os.ReadDir(entryPath) + if err2 != nil { + log.Fatal(err) + } + d.getActionsFromEntries(actionsPath, entries2, e.Name()) + } + actionYMLPath := filepath.Join(entryPath, "action.yml") _, err = os.Stat(actionYMLPath) ymlNotFound := os.IsNotExist(err) @@ -145,9 +162,13 @@ func (d *DotGithub) getActions() { continue } } - d.Actions[e.Name()] = &action.Action{ + actionName := e.Name() + if parentDir != "" { + actionName = parentDir + "/" + e.Name() + } + d.Actions[actionName] = &action.Action{ Path: actionYMLPath, - DirName: e.Name(), + DirName: actionName, } } }