Skip to content

Commit

Permalink
Allow actions that are in 1 level subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
mikogs committed Oct 23, 2024
1 parent 104aa47 commit d762687
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/action_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
25 changes: 23 additions & 2 deletions pkg/dotgithub/dot_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
}
}
}
Expand Down

0 comments on commit d762687

Please sign in to comment.