Skip to content

Commit

Permalink
Merge license checking
Browse files Browse the repository at this point in the history
  • Loading branch information
karlmutch committed Oct 23, 2018
2 parents 502f00b + c34f577 commit a8f137f
Show file tree
Hide file tree
Showing 525 changed files with 873,547 additions and 721 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ Dockerfile.tmp
clusters

*.log


#Autogenerated licen ses manifest
licenses.manifest
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ WORKDIR /project/src/github.com/SentientTechnologies/studio-go-runner
#
ENV AMQP_URL "amqp://guest:guest@${RABBITMQ_SERVICE_SERVICE_HOST}:${RABBITMQ_SERVICE_SERVICE_PORT}/%2f?connection_attempts=2&retry_delay=.5&socket_timeout=5"

CMD /bin/bash -c '(go get github.com/karlmutch/duat && go get github.com/karlmutch/enumer && dep ensure && go build -o $GOPATH/bin/build -tags NO_CUDA build.go && $GOPATH/bin/build -r -dirs internal && $GOPATH/bin/build -dirs cmd/runner) 2>&1 | tee $RUNNER_BUILD_LOG'
CMD /bin/bash -c '(go get github.com/karlmutch/duat && go get github.com/karlmutch/enumer && dep ensure && go build -o $GOPATH/bin/build -tags NO_CUDA *.go && $GOPATH/bin/build -r -dirs internal && $GOPATH/bin/build -dirs cmd/runner) 2>&1 | tee $RUNNER_BUILD_LOG'

# Done last to prevent lots of disruption when bumping versions
LABEL vendor="Sentient Technologies INC" \
Expand Down
164 changes: 159 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ ignored = ["github.com/Sirupsen/logrus"]
name = "github.com/karlmutch/duat"
branch="master"

[[override]]
name = "gopkg.in/src-d/go-git.v4"
version="v4.7.0"

# K8s API Version 1.10
[[override]]
name = "github.com/ericchiang/k8s"
Expand Down
62 changes: 62 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"github.com/karlmutch/stack" // Forked copy of https://github.com/go-stack/stack

"github.com/karlmutch/envflag" // Forked copy of https://github.com/GoBike/envflag

"gopkg.in/src-d/go-license-detector.v2/licensedb"
"gopkg.in/src-d/go-license-detector.v2/licensedb/filer"
)

var (
Expand Down Expand Up @@ -118,6 +121,20 @@ func main() {

outputs := []string{}

allLics, err := licenses(".")
if err != nil {
logger.Warn(errors.Wrap(err, "could not create a license manifest").With("stack", stack.Trace().TrimRuntime()).Error())
}
licf, errGo := os.OpenFile("licenses.manifest", os.O_WRONLY|os.O_CREATE, 0644)
if errGo != nil {
logger.Warn(errors.Wrap(errGo, "could not create a license manifest").With("stack", stack.Trace().TrimRuntime()).Error())
} else {
for dir, lics := range allLics {
licf.WriteString(fmt.Sprint(dir, ",", lics[0].lic, ",", lics[0].score, "\n"))
}
licf.Close()
}

// Invoke the generator in any of the root dirs and their desendents without
// looking for a main for TestMain as generated code can exist throughout any
// of our repos packages
Expand Down Expand Up @@ -161,6 +178,51 @@ func main() {
}
}

type License struct {
lic string
score float32
}

// licenses returns a list of directories and files that have license and confidences related to
// each. An attempt is made to rollup results so that directories with licenses that match all
// files are aggregated into a single entry for the items, any small variations for files are
// called out and left in the output. Also directories are rolled up where their children match.
//
func licenses(dir string) (lics map[string][]License, err errors.Error) {
lics = map[string][]License{}
errGo := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
if len(path) > 1 && path[0] == '.' {
return filepath.SkipDir
}
fr, errGo := filer.FromDirectory(path)
if errGo != nil {
return errors.Wrap(errGo).With("stack", stack.Trace().TrimRuntime())
}
licenses, errGo := licensedb.Detect(fr)
if errGo != nil && errGo.Error() != "no license file was found" {
return errors.Wrap(errGo).With("stack", stack.Trace().TrimRuntime())
}
if len(licenses) == 0 {
return nil
}
if _, isPresent := lics[path]; !isPresent {
lics[path] = []License{}
}
for lic, conf := range licenses {
lics[path] = append(lics[path], License{lic: lic, score: conf})
}
sort.Slice(lics[path], func(i, j int) bool { return lics[path][i].score < lics[path][j].score })
return nil
})
if errGo != nil {
return nil, errors.Wrap(errGo).With("stack", stack.Trace().TrimRuntime())
}
return lics, nil
}

// runGenerate is used to do a stock go generate within our project directories
//
func runGenerate(dirs []string, verFn string) (outputs []string, err errors.Error) {
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/dgryski/go-minhash/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a8f137f

Please sign in to comment.