diff --git a/fstest/test_all/report.go b/fstest/test_all/report.go index 3de70e900..8a4cdc94b 100644 --- a/fstest/test_all/report.go +++ b/fstest/test_all/report.go @@ -3,6 +3,7 @@ package main import ( + "encoding/json" "fmt" "html/template" "io/ioutil" @@ -10,6 +11,8 @@ import ( "os" "os/exec" "path" + "regexp" + "runtime" "sort" "time" @@ -32,6 +35,11 @@ type Report struct { Previous string // previous test name if known IndexHTML string // path to the index.html file URL string // online version + Branch string // rclone branch + Commit string // rclone commit + GOOS string // Go OS + GOARCH string // Go Arch + GoVersion string // Go Version } // ReportRun is used in the templates to report on a test run @@ -40,11 +48,24 @@ type ReportRun struct { Runs Runs } +// Parse version numbers +// v1.49.0 +// v1.49.0-031-g2298834e-beta +// v1.49.0-032-g20793a5f-sharefile-beta +// match 1 is commit number +// match 2 is branch name +var parseVersion = regexp.MustCompile(`^v(?:[0-9.]+)-(?:\d+)-g([0-9a-f]+)(?:-(.*))?-beta$`) + +// FIXME take -issue or -pr parameter... + // NewReport initialises and returns a Report func NewReport() *Report { r := &Report{ StartTime: time.Now(), Version: fs.Version, + GOOS: runtime.GOOS, + GOARCH: runtime.GOARCH, + GoVersion: runtime.Version(), } r.DateTime = r.StartTime.Format(timeFormat) @@ -64,6 +85,16 @@ func NewReport() *Report { // Online version r.URL = *urlBase + r.DateTime + "/index.html" + // Get branch/commit out of version + parts := parseVersion.FindStringSubmatch(r.Version) + if len(parts) >= 3 { + r.Commit = parts[1] + r.Branch = parts[2] + } + if r.Branch == "" { + r.Branch = "master" + } + return r } @@ -116,6 +147,18 @@ func (r *Report) LogSummary() { } } +// LogJSON writes the summary to index.json in LogDir +func (r *Report) LogJSON() { + out, err := json.MarshalIndent(r, "", "\t") + if err != nil { + log.Fatalf("Failed to marshal data for index.json: %v", err) + } + err = ioutil.WriteFile(path.Join(r.LogDir, "index.json"), out, 0666) + if err != nil { + log.Fatalf("Failed to write index.json: %v", err) + } +} + // LogHTML writes the summary to index.html in LogDir func (r *Report) LogHTML() { r.IndexHTML = path.Join(r.LogDir, "index.html") @@ -195,6 +238,9 @@ a:focus {
Version | {{ .Version }} |
---|---|
Test | {{ .DateTime}} |
Branch | {{ .Branch }} |
Commit | {{ .Commit }} |
Go | {{ .GoVersion }} {{ .GOOS }}/{{ .GOARCH }} |
Duration | {{ .Duration }} |
Previous | {{ .Previous }} |
Up | Older Tests |