Skip to content

Commit

Permalink
Fix version increase logic (#346)
Browse files Browse the repository at this point in the history
* Update version bump logic
* Changelog
* gofmt & goimports
* Remove leftover code
* Simplify mock expectations
* Changelog typos
* Add FIX typo to test data
* Fix test
* Reword changelog
  • Loading branch information
marcogschmidt authored and soloio-bulldozer[bot] committed Nov 15, 2019
1 parent f40227d commit 4a401b8
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 154 deletions.
3 changes: 2 additions & 1 deletion botutils/botconfig/os_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions changelog/v0.10.28/version-increase-for-v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
changelog:
- type: FIX
description: >
When verifying changelog entries after the v1.0.0 release, the version utils currently require a minor version bump
for any non-breaking change. We need to update the logic to ensure that if a changelog entry is of type
`BREAKING_CHANGE` we must bump the major version, if it is of type `NEW_FEATURE` we must bump the minor version,
and else we have to bump the patch version.
issueLink: https://github.com/solo-io/go-utils/issues/345
4 changes: 3 additions & 1 deletion changelogutils/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,18 @@ func ComputeChangelogForNonRelease(fs afero.Fs, latestTag, proposedTag, changelo
return nil, err
}
breakingChanges := false
newFeature := false
releaseStableApi := false

for _, file := range changelog.Files {
for _, entry := range file.Entries {
breakingChanges = breakingChanges || entry.Type.BreakingChange()
newFeature = newFeature || entry.Type.NewFeature()
}
releaseStableApi = releaseStableApi || file.GetReleaseStableApi()
}

expectedVersion := latestVersion.IncrementVersion(breakingChanges)
expectedVersion := latestVersion.IncrementVersion(breakingChanges, newFeature)
if releaseStableApi {
if !proposedVersion.Equals(&versionutils.StableApiVersion) {
return nil, errors.Errorf("Changelog indicates this is a stable API release, which should be used only to indicate the release of v1.0.0, not %s", proposedVersion)
Expand Down
4 changes: 4 additions & 0 deletions changelogutils/entrytype.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (clt ChangelogEntryType) BreakingChange() bool {
return clt == BREAKING_CHANGE
}

func (clt ChangelogEntryType) NewFeature() bool {
return clt == NEW_FEATURE
}

func (clt ChangelogEntryType) MarshalJSON() ([]byte, error) {
if s, ok := interface{}(clt).(fmt.Stringer); ok {
return json.Marshal(s.String())
Expand Down
3 changes: 2 additions & 1 deletion changelogutils/mounted_repo_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions changelogutils/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ changelog:
description: foo2
issueLink: bar2
`

validChangelog2 = `
changelog:
- type: NON_USER_FACING
Expand All @@ -432,6 +433,7 @@ changelog:
issueLink: bar4
resolvesIssue: false
`

validChangelog3 = `
changelog:
- type: DEPENDENCY_BUMP
Expand All @@ -447,6 +449,31 @@ changelog:
issueLink: bar
`

validNewFeatureChangelog = `
changelog:
- type: NEW_FEATURE
description: cool new feature
issueLink: http://issue
`

validNonBreakingNorNewFeatureChangelog = `
changelog:
- type: NON_USER_FACING
- type: DEPENDENCY_BUMP
dependencyOwner: foo
dependencyRepo: bar
dependencyTag: baz
- type: UPGRADE
description: foo5
issueLink: bar5
- type: HELM
description: foo6
issueLink: bar6
- type: FIX
description: foo1
issueLink: bar1
`

validStableReleaseChangelog = `
changelog:
- type: NON_USER_FACING
Expand Down
4 changes: 3 additions & 1 deletion changelogutils/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,18 @@ func (c *changelogValidator) validateVersionBump(ctx context.Context, latestTag
return err
}
breakingChanges := false
newFeature := false
releaseStableApi := false

for _, file := range changelog.Files {
for _, entry := range file.Entries {
breakingChanges = breakingChanges || entry.Type.BreakingChange()
newFeature = newFeature || entry.Type.NewFeature()
}
releaseStableApi = releaseStableApi || file.GetReleaseStableApi()
}

expectedVersion := latestVersion.IncrementVersion(breakingChanges)
expectedVersion := latestVersion.IncrementVersion(breakingChanges, newFeature)
if releaseStableApi {
if !changelog.Version.Equals(&versionutils.StableApiVersion) {
return InvalidUseOfStableApiError(changelog.Version.String())
Expand Down
Loading

0 comments on commit 4a401b8

Please sign in to comment.