mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
Fix parallel execution.
This commit is contained in:
parent
3ee3c748e9
commit
b2358d9b62
31
README.md
31
README.md
@ -8,13 +8,30 @@ The program only requires one argument to run, the name of the repo:
|
||||
|
||||
```shell
|
||||
$ scorecards --repo=github.com/kubernetes/kubernetes
|
||||
Security-MD 10 true
|
||||
Contributors 10 true
|
||||
Signed-Tags 7 false
|
||||
Signed-Releases 0 false
|
||||
Code-Review 10 true
|
||||
CI-Tests 10 true
|
||||
Frozen-Deps 10 true
|
||||
2020/10/09 10:25:12 Starting [Code-Review]
|
||||
2020/10/09 10:25:12 Starting [Contributors]
|
||||
2020/10/09 10:25:12 Starting [Frozen-Deps]
|
||||
2020/10/09 10:25:12 Starting [Signed-Releases]
|
||||
2020/10/09 10:25:12 Starting [Security-MD]
|
||||
2020/10/09 10:25:12 Starting [Signed-Tags]
|
||||
2020/10/09 10:25:12 Starting [CI-Tests]
|
||||
2020/10/09 10:25:12 Finished [Security-MD]
|
||||
2020/10/09 10:25:14 Finished [Contributors]
|
||||
2020/10/09 10:25:16 Finished [Signed-Tags]
|
||||
2020/10/09 10:25:16 Finished [Signed-Releases]
|
||||
2020/10/09 10:25:25 Finished [Code-Review]
|
||||
2020/10/09 10:25:28 Finished [CI-Tests]
|
||||
2020/10/09 10:25:38 Finished [Frozen-Deps]
|
||||
|
||||
RESULTS
|
||||
-------
|
||||
CI-Tests true 10
|
||||
Code-Review true 10
|
||||
Contributors true 10
|
||||
Frozen-Deps true 10
|
||||
Security-MD true 10
|
||||
Signed-Releases false 0
|
||||
Signed-Tags false 7
|
||||
```
|
||||
|
||||
You'll probably also need to set an Oauth token to avoid rate limits.
|
||||
|
37
main.go
37
main.go
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@ -18,6 +19,11 @@ import (
|
||||
var repo = flag.String("repo", "", "url to the repo")
|
||||
var checksToRun = flag.String("checks", "", "specific checks to run, instead of all")
|
||||
|
||||
type result struct {
|
||||
cr checks.CheckResult
|
||||
name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
@ -32,6 +38,7 @@ func main() {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Use our custom roundtripper
|
||||
rt := roundtripper.NewTransport(ctx)
|
||||
|
||||
client := &http.Client{
|
||||
@ -47,10 +54,12 @@ func main() {
|
||||
Repo: repo,
|
||||
}
|
||||
|
||||
resultsCh := make(chan result)
|
||||
wg := sync.WaitGroup{}
|
||||
for _, check := range checks.AllChecks {
|
||||
check := check
|
||||
wg.Add(1)
|
||||
log.Printf("Starting [%s]\n", check.Name)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
var r checks.CheckResult
|
||||
@ -62,9 +71,33 @@ func main() {
|
||||
}
|
||||
break
|
||||
}
|
||||
fmt.Println(check.Name, r.Confidence, r.Pass)
|
||||
resultsCh <- result{
|
||||
name: check.Name,
|
||||
cr: r,
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(resultsCh)
|
||||
}()
|
||||
|
||||
// Collect results
|
||||
results := []result{}
|
||||
for result := range resultsCh {
|
||||
log.Printf("Finished [%s]\n", result.name)
|
||||
results = append(results, result)
|
||||
}
|
||||
|
||||
// Sort them by name
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
return results[i].name < results[j].name
|
||||
})
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("RESULTS")
|
||||
fmt.Println("-------")
|
||||
for _, r := range results {
|
||||
fmt.Println(r.name, r.cr.Pass, r.cr.Confidence)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user