Add the release candidate to versioning.

This commit is contained in:
2021-07-12 16:53:19 +01:00
parent 08d2679846
commit c621cdf9e5
4 changed files with 76 additions and 26 deletions
+21 -15
View File
@@ -114,23 +114,27 @@ Linux/arm64, Linux/amd64
#### Calculations example [standard]
* 0.0.1 - PATCH - starting commit
* 0.0.2 - PATCH - another commit
* 0.0.4 - PATCH - another commit with word 'Update' => DOUBLE increment PATCH
* 0.1.0 - MINOR - after commit with word 'Change' => increment MINOR, reset PATCH
* 0.1.1 - PATCH - additional commit
* 1.0.1 - MAJOR - commit with word 'BREAKING' = > INCREMENT MAJOR, reset MINOR
* 1.0.2 - PATCH - another commit
```bash
- 0.0.1 - PATCH - starting commit
- 0.0.2 - PATCH - another commit
- 0.0.4 - PATCH - another commit with word 'Update' => DOUBLE increment PATCH
- 0.1.0 - MINOR - after commit with word 'Change' => increment MINOR, reset PATCH
- 0.1.1 - PATCH - additional commit
- 1.0.1 - MAJOR - commit with word 'BREAKING' = > INCREMENT MAJOR, reset MINOR
- 1.0.2 - PATCH - another commit
```
#### Calculations example [strict matching]
* 0.0.1 - PATCH - starting commit
* 0.0.1 - PATCH - another commit
* 0.0.1 - PATCH - another commit with word 'Update' => SINGLE increment PATCH
* 0.1.0 - MINOR - after commit with word 'Change' => increment MINOR, reset PATCH
* 0.1.0 - PATCH - additional commit
* 1.0.0 - MAJOR - commit with word 'BREAKING' = > INCREMENT MAJOR, reset MINOR
* 1.0.0 - PATCH - another commit
```bash
- 0.0.1 - PATCH - starting commit
- 0.0.1 - PATCH - another commit
- 0.0.1 - PATCH - another commit with word 'Update' => SINGLE increment PATCH
- 0.1.0 - MINOR - after commit with word 'Change' => increment MINOR, reset PATCH
- 0.1.0 - PATCH - additional commit
- 1.0.0 - MAJOR - commit with word 'BREAKING' = > INCREMENT MAJOR, reset MINOR
- 1.0.0 - PATCH - another commit
```
#### Example configuration
@@ -146,12 +150,14 @@ wording:
- update
- initial
minor:
- add
- change
- improve
major:
- breaking
- the # For testing purposes
release:
- release-candidate
- add-rc
```
* `version`: is not respected at the moment, introduced for potential backwards compatibility in future
+26 -9
View File
@@ -41,9 +41,10 @@ var (
)
type Wording struct {
Patch []string
Minor []string
Major []string
Patch []string
Minor []string
Major []string
Release []string
}
type Force struct {
@@ -54,9 +55,11 @@ type Force struct {
}
type SemVer struct {
Patch int
Minor int
Major int
Patch int
Minor int
Major int
Release int
EnableReleaseCandidate bool
}
type Setup struct {
@@ -106,19 +109,30 @@ func (s *Setup) CalculateSemver() SemVer {
matchPatch := checkMatches(commitSlice, s.Wording.Patch)
matchMinor := checkMatches(commitSlice, s.Wording.Minor)
matchMajor := checkMatches(commitSlice, s.Wording.Major)
matchReleaseCandidate := checkMatches(commitSlice, s.Wording.Release)
if matchPatch {
s.Semver.Patch++
debugPrint(fmt.Sprintln("Incrementing patch (WORDING) on ", strings.TrimSuffix(commit.Message, "\n"), "| Semver:", s.getSemver()))
}
if matchReleaseCandidate {
s.Semver.Release++
s.Semver.Patch = 1
s.Semver.EnableReleaseCandidate = true
debugPrint(fmt.Sprintln("Incrementing release candidate (WORDING) on ", strings.TrimSuffix(commit.Message, "\n"), "| Semver:", s.getSemver()))
}
if matchMinor {
s.Semver.Minor++
s.Semver.Patch = 1
s.Semver.EnableReleaseCandidate = false
s.Semver.Release = 0
debugPrint(fmt.Sprintln("Incrementing minor (WORDING) on ", strings.TrimSuffix(commit.Message, "\n"), "| Semver:", s.getSemver()))
}
if matchMajor {
s.Semver.Major++
s.Semver.Minor = 0
s.Semver.Patch = 1
s.Semver.EnableReleaseCandidate = false
s.Semver.Release = 0
debugPrint(fmt.Sprintln("Incrementing major (WORDING) on ", strings.TrimSuffix(commit.Message, "\n"), "| Semver:", s.getSemver()))
}
}
@@ -156,7 +170,6 @@ func (s *Setup) ListCommits() ([]CommitDetails, error) {
}
debugPrint(fmt.Sprintln("\n---COMMITS AFTER CUT---\n", s.Commits))
return s.Commits, err
}
@@ -219,8 +232,12 @@ func (s *Setup) ReadConfig(file string) error {
return err
}
func (s *Setup) getSemver() string {
return fmt.Sprintf("%d.%d.%d", s.Semver.Major, s.Semver.Minor, s.Semver.Patch)
func (s *Setup) getSemver() (semverReturned string) {
semverReturned = fmt.Sprintf("%d.%d.%d", s.Semver.Major, s.Semver.Minor, s.Semver.Patch)
if s.Semver.EnableReleaseCandidate {
semverReturned = fmt.Sprintf("%s-rc.%d", semverReturned, s.Semver.Release)
}
return semverReturned
}
func main() {
+26
View File
@@ -66,6 +66,32 @@ func (suite *Tests) TestSetup_getSemver() {
},
want: "1.3.7",
},
{
name: "Return 1.3.7-rc.2",
fields: fields{
Semver: SemVer{
Major: 1,
Minor: 3,
Patch: 7,
Release: 2,
EnableReleaseCandidate: true,
},
},
want: "1.3.7-rc.2",
},
{
name: "Return 1.3.9",
fields: fields{
Semver: SemVer{
Major: 1,
Minor: 3,
Patch: 9,
Release: 2,
EnableReleaseCandidate: false,
},
},
want: "1.3.9",
},
}
for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) {
+3 -2
View File
@@ -7,8 +7,9 @@ wording:
- initial
- fix
minor:
- add
- change
- improve
major:
- breaking
- breaking
release:
- release-candidate