1
0
mirror of https://github.com/rclone/rclone.git synced 2025-11-23 21:44:49 +02:00

test_all: fix branch name in test report

This commit is contained in:
Nick Craig-Wood
2025-09-24 15:35:09 +01:00
parent 5d6d79e7d4
commit a9b05e4c7a

View File

@@ -1,15 +1,16 @@
package runs package runs
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"os" "os"
"os/exec" "os/exec"
"path" "path"
"regexp"
"runtime" "runtime"
"sort" "sort"
"strings"
"time" "time"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
@@ -45,14 +46,6 @@ type ReportRun struct {
Runs Runs 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... // FIXME take -issue or -pr parameter...
// NewReport initialises and returns a Report // NewReport initialises and returns a Report
@@ -82,19 +75,35 @@ func NewReport(Opt RunOpt) *Report {
// Online version // Online version
r.URL = Opt.URLBase + r.DateTime + "/index.html" r.URL = Opt.URLBase + r.DateTime + "/index.html"
// Get branch/commit out of version // Get branch/commit
parts := parseVersion.FindStringSubmatch(r.Version) r.Branch, r.Commit = gitBranchAndCommit()
if len(parts) >= 3 {
r.Commit = parts[1]
r.Branch = parts[2]
}
if r.Branch == "" {
r.Branch = "master"
}
return r return r
} }
// gitBranchAndCommit returns the current branch and commit hash.
//
// It returns "" on error.
func gitBranchAndCommit() (branch, commit string) {
// branch (empty if detached)
var b bytes.Buffer
cmdB := exec.Command("git", "symbolic-ref", "--short", "-q", "HEAD")
cmdB.Stdout = &b
if e := cmdB.Run(); e == nil {
branch = strings.TrimSpace(b.String())
}
// commit (full SHA)
var c bytes.Buffer
cmdC := exec.Command("git", "rev-parse", "HEAD")
cmdC.Stdout = &c
if e := cmdC.Run(); e == nil {
commit = strings.TrimSpace(c.String())
}
return branch, commit
}
// End should be called when the tests are complete // End should be called when the tests are complete
func (r *Report) End() { func (r *Report) End() {
r.Duration = time.Since(r.StartTime) r.Duration = time.Since(r.StartTime)