Merge pull request #1121 from harshavardhana/version

Fix mcVersion and keep it in http.TimeFormat by default
This commit is contained in:
Harshavardhana
2015-09-22 14:36:47 -07:00
7 changed files with 110 additions and 37 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ release: genversion
genversion:
@echo "Generating a new version.go:"
@go run genversion.go
@GO15VENDOREXPERIMENT=1 go run buildscripts/genversion.go
coverage:
@GO15VENDOREXPERIMENT=1 go test -race -coverprofile=cover.out ./
+77
View File
@@ -0,0 +1,77 @@
// +build ignore
/*
* Minio Client (C) 2014, 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"fmt"
"net/http"
"os"
"strings"
"text/template"
"time"
)
var versionTemplate = `// -------- DO NOT EDIT --------
// This file is autogenerated by genversion.go during the release process.
package main
const mcVersion = {{if .Version}}"{{.Version}}"{{else}}""{{end}}
const mcReleaseTag = {{if .ReleaseTag}}"{{.ReleaseTag}}"{{else}}""{{end}}
`
// genVersion generates ‘version.go’.
func genVersion(version string) {
t := template.Must(template.New("version").Parse(versionTemplate))
versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
fmt.Printf("genversion: Unable to generate ‘version.go’. Error: %s.\n", err)
os.Exit(1)
}
defer versionFile.Close()
err = t.Execute(versionFile, struct {
Version string
ReleaseTag string
}{version, genReleaseTag(version)})
if err != nil {
fmt.Printf("genversion: Unable to generate ‘version.go’. Error: %s.\n", err)
os.Exit(1)
}
}
// genReleaseTag prints release tag to the console for easy git tagging.
func genReleaseTag(version string) string {
relTag := strings.Replace(version, " ", "-", -1)
relTag = strings.Replace(relTag, ":", "-", -1)
relTag = strings.Replace(relTag, ",", "", -1)
return "RELEASE." + relTag
}
func main() {
// Version is in HTTP TimeFormat.
version := time.Now().UTC().Format(http.TimeFormat)
// generate ‘version.go’ file.
genVersion(version)
fmt.Println("Version: \"" + version + "\"")
fmt.Println("Release-Tag: " + genReleaseTag(version))
}
+1 -1
View File
@@ -27,7 +27,7 @@ var (
// mc configuration related constants.
const (
globalMCConfigVersion = "5"
globalMCVersion = Version
globalMCVersion = mcVersion
globalMCConfigDir = ".mc/"
globalMCConfigWindowsDir = "mc\\"
+1 -12
View File
@@ -18,12 +18,10 @@ package main
import (
"fmt"
"net/http"
"os"
"os/user"
"runtime"
"strconv"
"time"
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
@@ -110,15 +108,6 @@ func registerBefore(ctx *cli.Context) error {
return nil
}
// getFormattedVersion -
func getFormattedVersion() string {
t, _ := time.Parse(time.RFC3339Nano, Version)
if t.IsZero() {
return ""
}
return t.Format(http.TimeFormat)
}
func findClosestCommands(command string) []string {
var closestCommands []string
for _, value := range commandsTree.PrefixMatch(command) {
@@ -170,7 +159,7 @@ GLOBAL FLAGS:
{{range .Flags}}{{.}}
{{end}}{{end}}
VERSION:
` + getFormattedVersion() +
` + mcVersion +
`{{ "\n"}} {{range $key, $value := ExtraInfo}}
{{$key}}:
{{$value}}
+7 -7
View File
@@ -58,9 +58,9 @@ type Updates struct {
// UpdateMessage container to hold update messages
type UpdateMessage struct {
Update bool `json:"update"`
Download string `json:"downloadURL"`
Version time.Time `json:"version"`
Update bool `json:"update"`
Download string `json:"downloadURL"`
Version string `json:"version"`
}
// String colorized update message
@@ -126,7 +126,7 @@ func getExperimentalUpdate() {
data, _, err := clnt.GetObject(0, 0)
fatalIf(err.Trace(mcExperimentalURL), "Unable to read from experimental URL ‘"+mcExperimentalURL+"’.")
current, e := time.Parse(time.RFC3339Nano, Version)
current, e := time.Parse(http.TimeFormat, mcVersion)
fatalIf(probe.NewError(e), "Unable to parse Version string as time.")
if current.IsZero() {
@@ -153,7 +153,7 @@ func getExperimentalUpdate() {
updateMessage := UpdateMessage{
Download: downloadURL,
Version: latest,
Version: mcVersion,
}
if latest.After(current) {
updateMessage.Update = true
@@ -168,7 +168,7 @@ func getReleaseUpdate() {
data, _, err := clnt.GetObject(0, 0)
fatalIf(err.Trace(mcUpdateURL), "Unable to read from update URL ‘"+mcUpdateURL+"’.")
current, e := time.Parse(time.RFC3339Nano, Version)
current, e := time.Parse(http.TimeFormat, mcVersion)
fatalIf(probe.NewError(e), "Unable to parse Version string as time.")
if current.IsZero() {
@@ -191,7 +191,7 @@ func getReleaseUpdate() {
downloadURL := mcUpdateURLParse.Scheme + "://" + mcUpdateURLParse.Host + string(mcUpdateURLParse.Separator) + updates.Platforms[runtime.GOOS]
updateMessage := UpdateMessage{
Download: downloadURL,
Version: latest,
Version: mcVersion,
}
if latest.After(current) {
updateMessage.Update = true
+21 -14
View File
@@ -18,9 +18,9 @@ package main
import (
"encoding/json"
"net/http"
"time"
"fmt"
"github.com/fatih/color"
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/probe"
@@ -44,24 +44,31 @@ func mainVersion(ctx *cli.Context) {
if ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
}
t, _ := time.Parse(time.RFC3339Nano, Version)
if t.IsZero() {
console.Println("")
return
}
type Version struct {
Value time.Time `json:"value"`
Format string `json:"format"`
}
console.SetCustomTheme(map[string]*color.Color{
"Version": color.New(color.FgGreen, color.Bold),
})
if globalJSONFlag {
tB, e := json.Marshal(
struct {
Version Version `json:"version"`
}{Version: Version{t, "RFC3339Nano"}},
Version struct {
Value string `json:"value"`
Format string `json:"format"`
} `json:"version"`
}{
Version: struct {
Value string `json:"value"`
Format string `json:"format"`
}{
Value: mcVersion,
Format: "RFC2616",
},
},
)
fatalIf(probe.NewError(e), "Unable to construct version string.")
console.Println(string(tB))
return
}
console.Println(t.Format(http.TimeFormat))
msg := console.Colorize("Version", fmt.Sprintf("Version: %s\n", mcVersion))
msg += console.Colorize("Version", fmt.Sprintf("Release-Tag: %s", mcReleaseTag))
console.Println(msg)
}
+2 -2
View File
@@ -3,5 +3,5 @@
package main
// Version autogenerated
const Version = "2015-09-22T04:02:16.008862161Z"
const mcVersion = "Tue, 22 Sep 2015 21:15:45 GMT"
const mcReleaseTag = "RELEASE.Tue-22-Sep-2015-21-15-45-GMT"