From f9d4958195433864b66fe1e66b5af3fc2bcf1d21 Mon Sep 17 00:00:00 2001 From: tatsuo48 Date: Sat, 27 Feb 2021 08:42:59 +0900 Subject: [PATCH 1/5] allow prefix at date tag --- format.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/format.go b/format.go index ed6d1dc..356b65e 100644 --- a/format.go +++ b/format.go @@ -1,6 +1,7 @@ package main import ( + "regexp" "strconv" "strings" "time" @@ -30,16 +31,19 @@ func GetNextVersion(tag string) (string, error) { const layout = "20060102" today := time.Now().Format(layout) - if tags[0] == today { - minor, err := strconv.Atoi(tags[1]) - if err != nil { - return "", err - } + dateRe := regexp.MustCompile(`(.*)(\d{8})(\.)(.+)`) + if match := dateRe.FindStringSubmatch(tag); match != nil { + if match[2] == today { + minor, err := strconv.Atoi(match[4]) + if err != nil { + return "", err + } - next := strconv.Itoa(minor + 1) - return today + "." + next, nil + next := strconv.Itoa(minor + 1) + return match[1] + today + "." + next, nil + } + return match[1] + today + "." + "1", nil } - return today + ".1", nil } From 2ed4da7a05164ccd62b56502e4b7b99fc3f723f3 Mon Sep 17 00:00:00 2001 From: tatsuo48 Date: Sat, 27 Feb 2021 08:56:31 +0900 Subject: [PATCH 2/5] add test --- format_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/format_test.go b/format_test.go index f6f4d8b..e6e4d03 100644 --- a/format_test.go +++ b/format_test.go @@ -53,6 +53,30 @@ func TestGetNextVersion_DatePlus(t *testing.T) { } } +func TestGetNextVersion_DateWithPrefix(t *testing.T) { + const prefix = "release_" + tag, _ := GetNextVersion(prefix + "20180525.1") + + const layout = "20060102" + today := time.Now().Format(layout) + expected := prefix + today + ".1" + if tag != expected { + t.Errorf("Output=%q, Expected=%q", tag, expected) + } +} + +func TestGetNextVersion_DatePlusWithPrefix(t *testing.T) { + const prefix = "release_" + const layout = "20060102" + today := time.Now().Format(layout) + tag, _ := GetNextVersion(prefix + today + ".1") + + expected := prefix + today + ".2" + if tag != expected { + t.Errorf("Output=%q, Expected=%q", tag, expected) + } +} + func TestGetNextVersion_DateError(t *testing.T) { const layout = "20060102" today := time.Now().Format(layout) From 18b36b8fe4afc199f9e181c01b9e513d9c48030c Mon Sep 17 00:00:00 2001 From: tatsuo48 Date: Sat, 27 Feb 2021 09:12:47 +0900 Subject: [PATCH 3/5] fix --- format.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/format.go b/format.go index 356b65e..d56b856 100644 --- a/format.go +++ b/format.go @@ -31,18 +31,18 @@ func GetNextVersion(tag string) (string, error) { const layout = "20060102" today := time.Now().Format(layout) - dateRe := regexp.MustCompile(`(.*)(\d{8})(\.)(.+)`) - if match := dateRe.FindStringSubmatch(tag); match != nil { - if match[2] == today { - minor, err := strconv.Atoi(match[4]) + dateRe := regexp.MustCompile(`(.*)(\d{8})\.(.+)`) + if m := dateRe.FindStringSubmatch(tag); m != nil { + if m[2] == today { + minor, err := strconv.Atoi(m[3]) if err != nil { return "", err } next := strconv.Itoa(minor + 1) - return match[1] + today + "." + next, nil + return m[1] + today + "." + next, nil } - return match[1] + today + "." + "1", nil + return m[1] + today + "." + "1", nil } return today + ".1", nil } From 2aca8d5350c48ce840cc7fd2ffa70bdbc6e7b736 Mon Sep 17 00:00:00 2001 From: itosho Date: Mon, 8 Mar 2021 00:04:23 +0900 Subject: [PATCH 4/5] Improve a document --- README.md | 2 +- format.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 025bcdc..f5a2a97 100755 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ $ gdp publish ### Supported tag's format - [semantic version](https://semver.org/): e.g. v1.2.3 or 1.2.3 -- date version: e.g. 20180525.1 +- date version: e.g. 20180525.1 or release_20180525 ### How to create generate note Release note content is generated based on merge commit messages. diff --git a/format.go b/format.go index d56b856..a8eccd3 100644 --- a/format.go +++ b/format.go @@ -27,7 +27,7 @@ func GetNextVersion(tag string) (string, error) { return strings.Join(tags, "."), nil } - // date version(e.g. 20180525.1) + // date version(e.g. 20180525.1 or release_20180525.1) const layout = "20060102" today := time.Now().Format(layout) From 1be47d2b4d269877de575cf2b846bf8dcfb13af0 Mon Sep 17 00:00:00 2001 From: itosho Date: Mon, 8 Mar 2021 00:06:44 +0900 Subject: [PATCH 5/5] Update a version --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 916d061..5104157 100755 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( ) // Version is GDP's version. -const Version string = "v0.2.4" +const Version string = "v0.2.5" // Usage is GDP's usage. const Usage string = "usage: gdp deploy|publish [options]"