Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions scanner/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ import (
"gopkg.in/yaml.v3"
)

// Parser path patterns are stateless and safe for concurrent use, so they are
// compiled once at package init rather than per-parser-construction (which used
// to recompile all five on every repo scan).
var (
githubActionsMetadataPattern = regexp.MustCompile(`(^|/)action\.ya?ml$`)
githubWorkflowPattern = regexp.MustCompile(`^\.github/workflows/[^/]+\.ya?ml$`)
azurePipelinesPattern = regexp.MustCompile(`\.?azure-pipelines(-.+)?\.ya?ml$`)
gitlabCiPattern = regexp.MustCompile(`\.?gitlab-ci(-.+)?\.ya?ml$`)
tektonPattern = regexp.MustCompile(`^\.tekton/[^/]+\.ya?ml$`)
)

type GithubActionsMetadataParser struct {
pattern *regexp.Regexp
}

func NewGithubActionsMetadataParser() *GithubActionsMetadataParser {
return &GithubActionsMetadataParser{
pattern: regexp.MustCompile(`(^|/)action\.ya?ml$`),
pattern: githubActionsMetadataPattern,
}
}

Expand Down Expand Up @@ -63,7 +74,7 @@ type GithubActionWorkflowParser struct {

func NewGithubActionWorkflowParser() *GithubActionWorkflowParser {
return &GithubActionWorkflowParser{
pattern: regexp.MustCompile(`^\.github/workflows/[^/]+\.ya?ml$`),
pattern: githubWorkflowPattern,
}
}

Expand Down Expand Up @@ -108,7 +119,7 @@ type AzurePipelinesParser struct {

func NewAzurePipelinesParser() *AzurePipelinesParser {
return &AzurePipelinesParser{
pattern: regexp.MustCompile(`\.?azure-pipelines(-.+)?\.ya?ml$`),
pattern: azurePipelinesPattern,
}
}

Expand Down Expand Up @@ -154,7 +165,7 @@ type GitlabCiParser struct {

func NewGitlabCiParser() *GitlabCiParser {
return &GitlabCiParser{
pattern: regexp.MustCompile(`\.?gitlab-ci(-.+)?\.ya?ml$`),
pattern: gitlabCiPattern,
}
}

Expand Down Expand Up @@ -228,7 +239,7 @@ type PipelineAsCodeTektonParser struct {

func NewPipelineAsCodeTektonParser() *PipelineAsCodeTektonParser {
return &PipelineAsCodeTektonParser{
pattern: regexp.MustCompile(`^\.tekton/[^/]+\.ya?ml$`),
pattern: tektonPattern,
}
}

Expand Down