88 "strings"
99
1010 "github.com/spf13/cobra"
11+
1112 "go.k6.io/k6/cmd/state"
1213 "go.k6.io/k6/ext"
1314 "go.k6.io/k6/internal/build"
@@ -16,6 +17,7 @@ import (
1617const (
1718 commitKey = "commit"
1819 commitDirtyKey = "commit_dirty"
20+ mainK6Path = "go.k6.io/k6"
1921)
2022
2123// fullVersion returns the maximally full version and build information for
@@ -44,13 +46,13 @@ func fullVersion() string {
4446}
4547
4648// versionDetails returns the structured details about version
47- func versionDetails () map [string ]interface {} {
49+ func versionDetails () map [string ]any {
4850 v := build .Version
4951 if ! strings .HasPrefix (v , "v" ) {
5052 v = "v" + v
5153 }
5254
53- details := map [string ]interface {} {
55+ details := map [string ]any {
5456 "version" : v ,
5557 "go_version" : runtime .Version (),
5658 "go_os" : runtime .GOOS ,
@@ -62,35 +64,33 @@ func versionDetails() map[string]interface{} {
6264 return details
6365 }
6466
65- var (
66- commit string
67- dirty bool
68- )
69- for _ , s := range buildInfo .Settings {
70- switch s .Key {
71- case "vcs.revision" :
72- commitLen := 10
73- if len (s .Value ) < commitLen {
74- commitLen = len (s .Value )
67+ if buildInfo .Main .Path == mainK6Path {
68+ details ["version" ] = buildInfo .Main .Version
69+ if buildInfo .Main .Version == "(devel)" {
70+ details ["version" ] = v
71+ details [commitKey ] = "devel"
72+ }
73+ for _ , s := range buildInfo .Settings {
74+ switch s .Key {
75+ case "vcs.revision" :
76+ commitLen := min (len (s .Value ), 10 )
77+ details [commitKey ] = s .Value [:commitLen ]
78+ case "vcs.modified" :
79+ if s .Value == "true" {
80+ details [commitDirtyKey ] = true
81+ }
82+ default :
7583 }
76- commit = s .Value [:commitLen ]
77- case "vcs.modified" :
78- if s .Value == "true" {
79- dirty = true
84+ }
85+ } else {
86+ for _ , dep := range buildInfo .Deps {
87+ if dep .Path == mainK6Path {
88+ details ["version" ] = dep .Version
89+ break
8090 }
81- default :
8291 }
8392 }
8493
85- if commit == "" {
86- return details
87- }
88-
89- details [commitKey ] = commit
90- if dirty {
91- details [commitDirtyKey ] = true
92- }
93-
9494 return details
9595}
9696
0 commit comments