Skip to content

Commit

Permalink
wip: git-change-exec: add spdx check
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Ostarek <[email protected]>
  • Loading branch information
christoph-zededa committed Sep 5, 2024
1 parent acf5c35 commit 5d107ee
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tools/git-change-exec/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
)
Expand All @@ -17,6 +18,10 @@ type action interface {

func id(i any) string {
ty := reflect.TypeOf(i)

if ty.Name() == "" {
ty = reflect.TypeOf(i).Elem()
}
return ty.Name()
}

Expand All @@ -35,6 +40,9 @@ var actions = []action{
pillarTestAction{},
gitChangeExecTest{},
getDepsTestAction{},
&spdxCheck{
checkFiles: []string{},
},
}

type pillarTestAction struct{}
Expand Down Expand Up @@ -66,3 +74,36 @@ func (g gitChangeExecTest) match(path string) bool {
func (g gitChangeExecTest) do() error {
return execCmdWithDefaults("go", "test", "-C", "tools/git-change-exec", "-v").Run()
}

type spdxCheck struct {
checkFiles []string
}

func (s *spdxCheck) match(path string) bool {
exts := []string{
".sh",
".c", ".h",
".go",
".py",
".rs",
".yaml", ".yml",
".proto",
}

for _, ext := range exts {
if filepath.Ext(path) == ext {
return true
}
}

return false
}
func (s *spdxCheck) do() error {
cmd := exec.Command("tools/spdx-check.sh", s.checkFiles...)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

return cmd.Run()
}

0 comments on commit 5d107ee

Please sign in to comment.