Skip to content

Commit d0c5ba3

Browse files
timoknappchristophwitzko
authored andcommitted
feat: add config flag 'force-bump-patch'
1 parent 4e36c21 commit d0c5ba3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Config struct {
3333
Dry bool
3434
AllowInitialDevelopmentVersions bool
3535
AllowNoChanges bool
36+
ForceBumpPatch bool
3637
MaintainedVersion string
3738
PrependChangelog bool
3839
DownloadPlugins bool
@@ -122,6 +123,7 @@ func NewConfig(cmd *cobra.Command) (*Config, error) {
122123
Dry: mustGetBool(cmd, "dry"),
123124
AllowInitialDevelopmentVersions: mustGetBool(cmd, "allow-initial-development-versions"),
124125
AllowNoChanges: mustGetBool(cmd, "allow-no-changes"),
126+
ForceBumpPatch: mustGetBool(cmd, "force-bump-patch"),
125127
MaintainedVersion: viper.GetString("maintainedVersion"),
126128
PrependChangelog: mustGetBool(cmd, "prepend-changelog"),
127129
DownloadPlugins: mustGetBool(cmd, "download-plugins"),
@@ -177,6 +179,7 @@ func InitConfig(cmd *cobra.Command) error {
177179
cmd.Flags().Bool("dry", false, "do not create release")
178180
cmd.Flags().Bool("allow-initial-development-versions", false, "semantic-release will start your initial development release at 0.1.0")
179181
cmd.Flags().Bool("allow-no-changes", false, "exit with code 0 if no changes are found, useful if semantic-release is automatically run")
182+
cmd.Flags().Bool("force-bump-patch", false, "increments the patch version if no changes are found")
180183
cmd.Flags().Bool("prepend-changelog", false, "if the changelog file already exist the new changelog is prepended")
181184
cmd.Flags().Bool("download-plugins", false, "downloads all required plugins if needed")
182185
cmd.Flags().Bool("show-progress", false, "shows the plugin download progress")

pkg/semrel/semrel.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func calculateChange(commits []*Commit, latestRelease *Release) *Change {
2222
return change
2323
}
2424

25-
func applyChange(rawVersion string, rawChange *Change, allowInitialDevelopmentVersions bool) string {
25+
func applyChange(rawVersion string, rawChange *Change, allowInitialDevelopmentVersions bool, forceBumpPatchVersion bool) string {
2626
version := semver.MustParse(rawVersion)
2727
change := &Change{
2828
Major: rawChange.Major,
@@ -37,7 +37,11 @@ func applyChange(rawVersion string, rawChange *Change, allowInitialDevelopmentVe
3737
change.Minor = true
3838
}
3939
if !change.Major && !change.Minor && !change.Patch {
40-
return ""
40+
if forceBumpPatchVersion {
41+
change.Patch = true
42+
} else {
43+
return ""
44+
}
4145
}
4246
var newVersion semver.Version
4347
preRel := version.Prerelease()
@@ -67,5 +71,5 @@ func applyChange(rawVersion string, rawChange *Change, allowInitialDevelopmentVe
6771
}
6872

6973
func GetNewVersion(conf *config.Config, commits []*Commit, latestRelease *Release) string {
70-
return applyChange(latestRelease.Version, calculateChange(commits, latestRelease), conf.AllowInitialDevelopmentVersions)
74+
return applyChange(latestRelease.Version, calculateChange(commits, latestRelease), conf.AllowInitialDevelopmentVersions, conf.ForceBumpPatch)
7175
}

0 commit comments

Comments
 (0)