Skip to content

Commit

Permalink
Merge branch 'release/0.14.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodian committed Sep 4, 2023
2 parents e989feb + 31777ec commit 88ce9e2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.14.0] - 2023-09-04

### Added

- GiHub styled vX.Y.Z semver, by @oz-rw

## [0.13.0] - 2022-09-18

### Added
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ Use `--newline` flag if you prefer to see the newline.
release next --type hotfix
0.8.1

### Github-style semver `vx.y.z`

The tool also supports [Github-style semver](https://semver.org/#is-v123-a-semantic-version):

release show -v v0.1.0
release to -v v0.2.0

## Development

### Run
Expand Down
15 changes: 13 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ const (
// Version transforms 0.1.0 to [0.1.0].
// Returns error when given input is not following SemVar.
func Version(in string) (string, error) {
githubStyleSemver := false

if len(in) > 0 && in[0] == 'v' {
in = in[1:]
githubStyleSemver = true
}

v, err := semver.Make(in)

if err != nil {
return "", errors.New("given version is not compatible with Semantic Versioning")
}

return fmt.Sprintf("[%s]", v.String()), nil
if githubStyleSemver == true {
return fmt.Sprintf("[v%s]", v.String()), nil
} else {
return fmt.Sprintf("[%s]", v.String()), nil
}
}

// To returns document replaced with given version.
Expand Down Expand Up @@ -135,7 +146,7 @@ func Show(doc string, ver string) ([]string, error) {
// This operation simply matches to the first h2 header.
func Latest(doc string) (string, error) {

re := regexp.MustCompile(`## \[(\d*\.\d*\.\d*)\]`)
re := regexp.MustCompile(`## \[([v]?\d*\.\d*\.\d*)\]`)

for _, line := range strings.Split(doc, "\n") {
got := re.FindStringSubmatch(line)
Expand Down
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestOpenRepository(t *testing.T) {
"0.1.0",
"0.1.0-beta",
"100.200.300",
"v1.2.3",
}

for _, p := range pats {
Expand Down
6 changes: 6 additions & 0 deletions parser/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func (c SemanticVersion) Increment(in VersionType) SemanticVersion {
func CastVersion(name, val string) (int, error) {
const failcode = -1

if name == "major" {
if val[0] == 'v' {
val = val[1:]
}
}

i, err := strconv.Atoi(val)

if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion parser/semver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
"1.2.3a",
"1 2 3",
"v100",
"v1.2.3",
"v1.20",
"1.20.a",
"🍎",
Expand Down Expand Up @@ -50,6 +49,10 @@ func TestNewSemanticVersion(t *testing.T) {
expected: parser.SemanticVersion{Major: 123, Minor: 456, Patch: 789},
sample: "123.456.789",
},
{
expected: parser.SemanticVersion{Major: 1, Minor: 2, Patch: 3},
sample: "v1.2.3",
},
}

for _, p := range pats {
Expand Down

0 comments on commit 88ce9e2

Please sign in to comment.