Merge pull request #812 from harshavardhana/pr_out_add_more_elaborate_tag_this_time_in_string_epoch_gitrev_format

Add more elaborate tag this time in [STRING-EPOCH-GITREV] format
This commit is contained in:
Harshavardhana
2015-06-16 18:31:47 -07:00
3 changed files with 40 additions and 10 deletions
+1
View File
@@ -74,6 +74,7 @@ func getSystemData() map[string]string {
"PLATFORM": platform,
"RUNTIME": goruntime,
"MEM": mem,
"TAG": Tag,
}
}
+29 -9
View File
@@ -23,6 +23,8 @@ import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"text/template"
"time"
@@ -30,14 +32,10 @@ import (
)
type Version struct {
Date string
TagDate string
Date string
Tag string
}
const (
tagTimeStampFormat = "2006.01.02-MST"
)
func writeVersion(version Version) error {
var versionTemplate = `// -------- DO NOT EDIT --------
// this is an autogenerated file
@@ -51,7 +49,15 @@ import (
// Version autogenerated
var Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}}
var TagVersion = {{if .TagDate}}"{{.TagDate}}"{{else}}""{{end}}
// Tag is of following format
//
// [[STRING]-[EPOCH]-[GITREV]]
//
// STRING is release string of your choice.
// EPOCH is unix seconds since Jan 1, 1970 UTC.
// GITREV is git commit id
var Tag = {{if .Tag}}"{{.Tag}}"{{else}}""{{end}}
// getVersion -
func getVersion() string {
@@ -123,10 +129,24 @@ func runMcRelease(ctx *cli.Context) {
if ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "release", 1) // last argument is exit code
}
git := command{exec.Command("git", "rev-parse", "--short", "HEAD"), &bytes.Buffer{}, &bytes.Buffer{}}
gitErr := git.runCommand()
if gitErr != nil {
fmt.Print(git)
os.Exit(1)
}
revParse := git.stdout.String()
t := time.Now().UTC()
date := t.Format(time.RFC3339Nano)
tagDate := t.Format(tagTimeStampFormat)
version := Version{Date: date, TagDate: tagDate}
// [[STRING]-[EPOCH]-[GITREV]]
//
// STRING is release string of your choice.
// EPOCH is unix seconds since Jan 1, 1970 UTC.
// GITREV is git commit id
tag := "release" + "-" + strconv.FormatInt(t.Unix(), 10) + "-" + strings.TrimSpace(revParse)
version := Version{Date: date, Tag: tag}
err := writeVersion(version)
if err != nil {
fmt.Print(err)
+10 -1
View File
@@ -9,7 +9,16 @@ import (
)
// Version autogenerated
var Version = "2015-06-12T02:05:16.449416257Z"
var Version = "2015-06-17T01:27:27.033965323Z"
// Tag is of following format
//
// [[STRING]-[EPOCH]-[GITREV]]
//
// STRING is release string of your choice.
// EPOCH is unix seconds since Jan 1, 1970 UTC.
// GITREV is git commit id
var Tag = "release-1434504447-bb790ed"
// getVersion -
func getVersion() string {