Skip to content
Snippets Groups Projects
Verified Commit 21be2b5d authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new predict feat #1

parent aa4874d1
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ComposerSettings">
<execution />
</component>
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
......
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="version auto test" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="version" />
<working_directory value="$PROJECT_DIR$/../../alvine/local-dev/components/alvine/apps/test" />
<parameters value="auto --verbose" />
<EXTENSION ID="com.fapiko.jetbrains.plugins.better_direnv.runconfigs.GolandRunConfigurationExtension">
<option name="DIRENV_ENABLED" value="false" />
<option name="DIRENV_TRUSTED" value="false" />
</EXTENSION>
<kind value="PACKAGE" />
<package value="gitlab.schukai.com/oss/utilities/version" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
</component>
\ No newline at end of file
......@@ -71,18 +71,26 @@ it will trigger a patch or a major version bump respectively.
Here is how you can use the 'auto' feature:
```bash
version auto --git
version auto
```
Without the '--git' flag, the tool will use the last tag in the git history
as the starting point for the version calculation. The result will be printed
to stdout or written to a file if the '--path' flag is provided.
This command implies the '--git' flag, which means that the tool will tag the
git repository with the new version. The tag name will be the new version number.
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-beta.2/)
follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
message format.
**Predict**
The `predict` command allows you to predict the next version based on the
project's git commit history since the last tag. Other than the `auto` command,
this command does not write the result to a file or tag the git repository.
```bash
version predict
```
**Makefile**
......
......@@ -31,7 +31,9 @@ type commandLineOptions struct {
Date struct {
} `command:"date" description:"print the current date and time in the format YYYYMMDDHHMMSS"`
Auto struct {
} `command:"auto" description:"check the git repository and increase the version if necessary. Implies --git"`
} `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"`
Print struct {
} `command:"print" description:"print the current version, you can combine this with --git to print the last tag"`
}
......@@ -69,6 +71,8 @@ func increaseMajor() (string, error) {
var verbosity = false
var nullTerminated = false
var command string
var predict = false
func executeCommand() {
......@@ -89,7 +93,7 @@ func executeCommand() {
}
var newVersion string
command := activeCommand.Name
command = activeCommand.Name
if arguments.Verbose {
verbosity = true
......@@ -99,7 +103,25 @@ func executeCommand() {
nullTerminated = true
}
if arguments.Git || command == "auto" {
if command == "predict" {
predict = true
}
if command == "auto" || command == "predict" {
arguments.Git = true
if arguments.Path != "" || arguments.Selector != "" {
msg := "Error: cannot use --path or --selector with auto or predict\n"
_, err := fmt.Fprintf(os.Stderr, msg)
if err != nil {
fmt.Printf(msg)
}
os.Exit(1)
}
}
if arguments.Git {
path, err := os.Getwd()
if err != nil {
......@@ -124,7 +146,7 @@ func executeCommand() {
}
}
if command == "auto" {
if command == "auto" || command == "predict" {
commitType, err := GetCommitType()
if arguments.Verbose {
......
......@@ -236,6 +236,16 @@ func writeVersionToGit(version string) error {
func writeVersion(version string) error {
if predict == true {
if nullTerminated {
version += string(rune(0))
fmt.Printf("%s", version)
} else {
fmt.Printf(version)
}
return nil
}
if arguments.Git {
return writeVersionToGit(version)
} else if currentType == "json" {
......@@ -254,5 +264,12 @@ func writeVersion(version string) error {
return nil
}
msg := fmt.Sprintf("Unknown type: %s for path: %s", currentType, arguments.Path)
_, err := fmt.Fprintf(os.Stderr, "%s\n", msg)
if err != nil {
fmt.Printf("%s\n", msg)
}
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment