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

Correct CI check for examples and add a unit test #4045

Merged
merged 2 commits into from
Nov 21, 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
6 changes: 4 additions & 2 deletions build/scripts/example-version-checker/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const examplesDir = "examples"

var excludedPatterns = [...]string{"*.md", "*.yaml", "OWNERS", ".gitignore"}
var excludedPatterns = [...]string{"*.md", "*.yaml", "*.yml", "OWNERS", ".gitignore"}

func dirIsExample(dirName string) bool {
makefileName := fmt.Sprintf("%s/Makefile", dirName)
Expand Down Expand Up @@ -80,8 +80,10 @@ func filenameIsIrrelevant(filename string, exampleNames []string) bool {
return true
}

_, splitname := filepath.Split(filename)

for _, excludedName := range excludedPatterns {
matches, err := filepath.Match(excludedName, filename)
matches, err := filepath.Match(excludedName, splitname)
if err != nil {
log.Fatalf("Unknown error: %s", err)
}
Expand Down
31 changes: 31 additions & 0 deletions build/scripts/example-version-checker/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"log"
"testing"
)

func TestFilenameIsIrrelevant(t *testing.T) {
exampleNames := []string{"inner", "first"}

irrelevantMap := map[string]bool{
// in deny-list
"README.md": true,
"cloudbuild.yaml": true,
// in deny-list and inside an example
"examples/inner/outer/EXAMPLE.md": true,
"examples/first/second/third/test.yml": true,
// not in deny list, but outside examples
"outside/test.txt": true,
"1/2/3/4/5.go": true,
// in examples and relevant
"examples/inner/main.go": false,
}

for filename, expected := range irrelevantMap {
observed := filenameIsIrrelevant(filename, exampleNames)
if observed != expected {
log.Fatalf("%s was expected to be: %t", filename, expected)
}
}
}
Loading