Skip to content

Commit

Permalink
next-version should fail if there is no version to bump
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-makes committed Oct 15, 2024
1 parent c4404fb commit e8b15ff
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ Unreleased section should follow [Release Toolkit](https://github.com/newrelic/r
encourages the user to hack the YAML if needed. This is also needed so an empty YAML is there for the
other actions like `is-empty` or `is-held` to work properly.

`next-version` should also follow the composable nature of `release-toolkit`. But this part of the tool
should fail if there is no new version in case a user hack the YAML to a point that is not bumping the
version. Not failing can lead scripts to override an already existing version. This is also a change
on the default behavior.

### Breaking
- `ohi-release-notes` action has been moved to another repository
- `generate-yaml` does not fail to create an empty YAML by default
- `next-version` fail if there are no version to be bumped

## v1.2.0 - 2024-08-09

Expand Down
2 changes: 1 addition & 1 deletion next-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inputs:
fail:
description: Fail if no new version found, by default the current version will be returned in that case
required: false
default: "0"
default: "1"
outputs:
next-version:
description: Semver next version, with leading v
Expand Down
9 changes: 5 additions & 4 deletions src/app/nextversion/nextversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ next-version will exit with an error if no previous versions are found in the gi
EnvVars: common.EnvFor(failFlag),
Usage: "If set, command will exit with a code of 1 if no new version bump is produced. If not set," +
"the current version will be returned.",
Value: false,
Value: true,
},
},
Action: NextVersion,
Expand Down Expand Up @@ -166,10 +166,11 @@ func NextVersion(cCtx *cli.Context) error {
case nextOverride == nil && next != nil:
// If we don't have an override, the bumper did not bump anything, and the user has set `--fail`, then we should error out.
if errors.Is(err, bumper.ErrNoNewVersion) {
log.Warnf("None of the changelog entries produced a version bump, returning current version")
if cCtx.Bool("fail") {
return fmt.Errorf("failing by user request: %w", err)
if cCtx.Bool(failFlag) {
return fmt.Errorf("none of the changelog entries produced a version bump: %w", err)
}

log.Warnf("None of the changelog entries produced a version bump, returning current version")
}

case nextOverride == nil && next == nil:
Expand Down
13 changes: 11 additions & 2 deletions src/app/nextversion/nextversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/newrelic/release-toolkit/src/app"
"github.com/newrelic/release-toolkit/src/bump"
"github.com/newrelic/release-toolkit/src/bumper"
)

//nolint:paralleltest, funlen // urfave/cli cannot be tested concurrently.
Expand Down Expand Up @@ -87,10 +88,18 @@ changes:
`),
},
{
name: "No_Bump",
args: "-current v1.2.3",
name: "No_Bump_without_failing",
args: "-current v1.2.3 -fail=false",
expected: "v1.2.3",
yaml: strings.TrimSpace(`
changes: []
`),
},
{
name: "No_Bump_fails_by_default",
args: "-current v1.2.3",
errorExpected: bumper.ErrNoNewVersion,
yaml: strings.TrimSpace(`
changes: []
`),
},
Expand Down

0 comments on commit e8b15ff

Please sign in to comment.