From 3957b21632ded91d57451f337bafdb45b352d0b0 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Wed, 22 Nov 2023 23:33:52 +0100 Subject: [PATCH] feat: new flag exit-code-if-no-bump #4 --- .idea/runConfigurations/version_auto___git.xml | 2 +- .idea/version.iml | 1 + README.md | 9 +++++++++ source/commandline.go | 9 ++++++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.idea/runConfigurations/version_auto___git.xml b/.idea/runConfigurations/version_auto___git.xml index 45d5563..ca30067 100644 --- a/.idea/runConfigurations/version_auto___git.xml +++ b/.idea/runConfigurations/version_auto___git.xml @@ -1,7 +1,7 @@ <component name="ProjectRunConfigurationManager"> <configuration default="false" name="version auto --git" type="GoApplicationRunConfiguration" factoryName="Go Application"> <module name="version" /> - <working_directory value="$PROJECT_DIR$" /> + <working_directory value="$PROJECT_DIR$/../../alvine/components/alvine.dispatcher" /> <parameters value="auto --git" /> <EXTENSION ID="com.fapiko.jetbrains.plugins.better_direnv.runconfigs.GolandRunConfigurationExtension"> <option name="DIRENV_ENABLED" value="false" /> diff --git a/.idea/version.iml b/.idea/version.iml index e03d8ec..c9286c2 100644 --- a/.idea/version.iml +++ b/.idea/version.iml @@ -7,6 +7,7 @@ <excludeFolder url="file://$MODULE_DIR$/.devenv" /> <excludeFolder url="file://$MODULE_DIR$/.direnv" /> <excludeFolder url="file://$MODULE_DIR$/build" /> + <excludeFolder url="file://$MODULE_DIR$/.task" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> diff --git a/README.md b/README.md index cb3c006..ec369c2 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,15 @@ It is important to note that this feature requires that your commit messages follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) message format. +The `exit-code-if-no-bump` flag can be used to make the command exit with a non-zero exit. +This is useful for CI/CD pipelines. + +```bash +version auto --exit-code-if-no-bump +``` + +In this case, the command will exit with the exit code 1 if no version bump is required. + **Predict** The `predict` command allows you to predict the next version based on the diff --git a/source/commandline.go b/source/commandline.go index fb8736c..6acbb62 100644 --- a/source/commandline.go +++ b/source/commandline.go @@ -31,6 +31,7 @@ type commandLineOptions struct { Date struct { } `command:"date" description:"print the current date and time in the format YYYYMMDDHHMMSS"` Auto struct { + ExitCode bool `short:"e" long:"exit-code-if-no-bump" description:"exit code to use if no notable changes are found" default:"0"` } `command:"auto" description:"check the git repository and increase the version if necessary. This implies --git"` Predict struct { } `command:"predict" description:"predict the next version based on the git history. This implies --git"` @@ -178,7 +179,13 @@ func executeCommand() { case OtherCommit: fmt.Println("No notable changes found.") fmt.Println("If you want to force a version\nincrease, use the major, minor\nor patch command.") - os.Exit(0) + + exitCode := 0 + if arguments.Auto.ExitCode { + exitCode = 1 + } + + os.Exit(exitCode) } } -- GitLab