diff --git a/CHANGELOG.md b/CHANGELOG.md index 61d38f6f..981dbc49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/next-version/action.yml b/next-version/action.yml index 0264869b..8574ce4c 100644 --- a/next-version/action.yml +++ b/next-version/action.yml @@ -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 diff --git a/src/app/nextversion/nextversion.go b/src/app/nextversion/nextversion.go index fdcb7536..4769607a 100644 --- a/src/app/nextversion/nextversion.go +++ b/src/app/nextversion/nextversion.go @@ -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, @@ -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: diff --git a/src/app/nextversion/nextversion_test.go b/src/app/nextversion/nextversion_test.go index 572b1ae5..2b920c2c 100644 --- a/src/app/nextversion/nextversion_test.go +++ b/src/app/nextversion/nextversion_test.go @@ -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. @@ -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: [] `), },