Unverified Commit 0c950877 authored by Massimiliano Pippi's avatar Massimiliano Pippi Committed by GitHub

remove build date from the version (#300)

parent 633e9ab2
...@@ -55,8 +55,8 @@ func runDaemonCommand(cmd *cobra.Command, args []string) { ...@@ -55,8 +55,8 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
} }
s := grpc.NewServer() s := grpc.NewServer()
userAgentValue := fmt.Sprintf("%s/%s daemon (%s; %s; %s) Commit:%s/Build:%s", globals.VersionInfo.Application, userAgentValue := fmt.Sprintf("%s/%s daemon (%s; %s; %s) Commit:%s", globals.VersionInfo.Application,
globals.VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), globals.VersionInfo.Commit, globals.VersionInfo.BuildDate) globals.VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), globals.VersionInfo.Commit)
headers := http.Header{"User-Agent": []string{userAgentValue}} headers := http.Header{"User-Agent": []string{userAgentValue}}
coreServer := daemon.ArduinoCoreServerImpl{ coreServer := daemon.ArduinoCoreServerImpl{
......
...@@ -42,8 +42,8 @@ var ( ...@@ -42,8 +42,8 @@ var (
) )
func getHTTPClientHeader() http.Header { func getHTTPClientHeader() http.Header {
userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", VersionInfo.Application, userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s", VersionInfo.Application,
VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit, VersionInfo.BuildDate) VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit)
downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}} downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}}
return downloaderHeaders return downloaderHeaders
} }
...@@ -106,4 +106,3 @@ def test_command_version(): ...@@ -106,4 +106,3 @@ def test_command_version():
assert parsed_out.get('Application', False) == 'arduino-cli' assert parsed_out.get('Application', False) == 'arduino-cli'
assert isinstance(semver.parse(parsed_out.get('VersionString', False)), dict) assert isinstance(semver.parse(parsed_out.get('VersionString', False)), dict)
assert isinstance(parsed_out.get('Commit', False), str) assert isinstance(parsed_out.get('Commit', False), str)
assert datetime.strptime(parsed_out.get('BuildDate')[:-2], '%Y-%m-%dT%H:%M:%S.%f')
...@@ -19,34 +19,19 @@ package version ...@@ -19,34 +19,19 @@ package version
import ( import (
"fmt" "fmt"
"time"
) )
var ( var (
defaultVersionString = "0.3.7-alpha.preview" defaultVersionString = "0.3.7-alpha.preview"
versionString = "" versionString = ""
commit = "" commit = ""
buildDate = rfc3339Time{}
) )
type rfc3339Time struct {
time.Time
}
func (r rfc3339Time) format() string {
return r.Time.Format(time.RFC3339)
}
func (r rfc3339Time) MarshalJSON() ([]byte, error) {
return []byte(`"` + r.format() + `"`), nil
}
// Info FIXMEDOC // Info FIXMEDOC
type Info struct { type Info struct {
Application string `json:"Application"` Application string `json:"Application"`
VersionString string `json:"VersionString"` VersionString string `json:"VersionString"`
Commit string `json:"Commit"` Commit string `json:"Commit"`
BuildDate rfc3339Time `json:"BuildDate"`
} }
// NewInfo FIXMEDOC // NewInfo FIXMEDOC
...@@ -55,12 +40,11 @@ func NewInfo(application string) *Info { ...@@ -55,12 +40,11 @@ func NewInfo(application string) *Info {
Application: application, Application: application,
VersionString: versionString, VersionString: versionString,
Commit: commit, Commit: commit,
BuildDate: buildDate,
} }
} }
func (i *Info) String() string { func (i *Info) String() string {
return fmt.Sprintf("%s Version: %s Commit: %s BuildDate: %s", i.Application, i.VersionString, i.Commit, i.BuildDate.format()) return fmt.Sprintf("%s Version: %s Commit: %s", i.Application, i.VersionString, i.Commit)
} }
//nolint:gochecknoinits //nolint:gochecknoinits
...@@ -68,5 +52,4 @@ func init() { ...@@ -68,5 +52,4 @@ func init() {
if versionString == "" { if versionString == "" {
versionString = defaultVersionString versionString = defaultVersionString
} }
buildDate = rfc3339Time{time.Now().UTC()}
} }
...@@ -19,7 +19,6 @@ package version ...@@ -19,7 +19,6 @@ package version
import ( import (
"testing" "testing"
"time"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -35,12 +34,9 @@ func TestBuildInjectedInfo(t *testing.T) { ...@@ -35,12 +34,9 @@ func TestBuildInjectedInfo(t *testing.T) {
Application: goldenAppName, Application: goldenAppName,
VersionString: "0.0.0-test.preview", VersionString: "0.0.0-test.preview",
Commit: "deadbeef", Commit: "deadbeef",
BuildDate: rfc3339Time{time.Time{}},
} }
info := NewInfo(goldenAppName) info := NewInfo(goldenAppName)
require.Equal(t, goldenInfo.Application, info.Application) require.Equal(t, goldenInfo.Application, info.Application)
require.Equal(t, goldenInfo.VersionString, info.VersionString) require.Equal(t, goldenInfo.VersionString, info.VersionString)
require.Equal(t, goldenInfo.Commit, info.Commit) require.Equal(t, goldenInfo.Commit, info.Commit)
require.IsType(t, rfc3339Time{time.Time{}}, info.BuildDate)
require.False(t, info.BuildDate.IsZero())
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment