Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Types: Skip .test.yml files when linting/applying #4772

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions cmd/cli/app/ruletype/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func shouldSkipFile(f string) bool {
ext := filepath.Ext(f)
switch ext {
case ".yaml", ".yml", ".json":
if cli.IsTestFile(f) {
// Skip test files.
return true
}
return false
default:
fmt.Fprintf(os.Stderr, "Skipping file %s: not a yaml or json file\n", f)
Expand Down
3 changes: 2 additions & 1 deletion cmd/dev/app/rule_type/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/mindersec/minder/internal/engine/eval/rego"
"github.com/mindersec/minder/internal/util/cli"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ func lintCmdRun(cmd *cobra.Command, _ []string) error {
return nil
}

if filepath.Ext(path) != ".yaml" && filepath.Ext(path) != ".yml" {
if !cli.IsYAMLFileAndNotATest(path) {
return nil
}

Expand Down
11 changes: 11 additions & 0 deletions internal/util/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,14 @@ func GetRelevantCLIConfigPath(v *viper.Viper) string {
GetDefaultCLIConfigPath(),
))
}

// IsYAMLFileAndNotATest checks if a file is a YAML file and not a test file
func IsYAMLFileAndNotATest(path string) bool {
return (filepath.Ext(path) == ".yaml" || filepath.Ext(path) == ".yml") &&
!IsTestFile(path)
}

// IsTestFile checks if a file is a test file. Test files are YAML files ending with .test.yaml or .test.yml
func IsTestFile(path string) bool {
return strings.HasSuffix(path, ".test.yaml") || strings.HasSuffix(path, ".test.yml")
}