Skip to content

Commit

Permalink
Merge pull request #18 from tatsuo48/allow_prefix_at_date_tag
Browse files Browse the repository at this point in the history
Allow prefix at date tag
  • Loading branch information
itosho authored Mar 7, 2021
2 parents fc0f602 + 1be47d2 commit 0a75ede
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 13 additions & 9 deletions format.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"regexp"
"strconv"
"strings"
"time"
Expand All @@ -26,20 +27,23 @@ 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)

if tags[0] == today {
minor, err := strconv.Atoi(tags[1])
if err != nil {
return "", err
}
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 today + "." + next, nil
next := strconv.Itoa(minor + 1)
return m[1] + today + "." + next, nil
}
return m[1] + today + "." + "1", nil
}

return today + ".1", nil
}

Expand Down
24 changes: 24 additions & 0 deletions format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down

0 comments on commit 0a75ede

Please sign in to comment.