Skip to content

Commit

Permalink
fix: if allowInitialDevelopmentVersions is set the major version shou…
Browse files Browse the repository at this point in the history
…ld never be updated
  • Loading branch information
christophwitzko committed Mar 13, 2022
1 parent 79334cd commit 81aea83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func SetFlags(cmd *cobra.Command) {
cmd.Flags().Bool("ghr", false, "create a .ghr file with the parameters for ghr")
cmd.Flags().Bool("no-ci", false, "run semantic-release locally")
cmd.Flags().Bool("dry", false, "do not create release")
cmd.Flags().Bool("allow-initial-development-versions", false, "semantic-release will start your initial development release at 0.1.0")
cmd.Flags().Bool("allow-initial-development-versions", false, "semantic-release will start your initial development release at 0.1.0 and will handle breaking changes as minor version updates. This option will be ignored if a release with major version greater than or equal 1 exists.")
cmd.Flags().Bool("allow-no-changes", false, "exit with code 0 if no changes are found, useful if semantic-release is automatically run")
cmd.Flags().Bool("force-bump-patch-version", false, "increments the patch version if no changes are found")
cmd.Flags().Bool("prepend-changelog", false, "if the changelog file already exist the new changelog is prepended")
Expand Down
6 changes: 6 additions & 0 deletions pkg/semrel/semrel.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func applyChange(rawVersion string, rawChange *Change, allowInitialDevelopmentVe
change.Major = true
}

// never allow major version changed if allowInitialDevelopmentVersions is set
if allowInitialDevelopmentVersions && version.Major() == 0 && change.Major {
change.Major = false
change.Minor = true
}

if allowInitialDevelopmentVersions && version.Major() == 0 && version.Minor() == 0 {
change.Minor = true
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/semrel/semrel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestApplyChange(t *testing.T) {
{"0.0.0", NoChange, "0.1.0", true, false},
{"0.0.0", PatchChange, "0.1.0", true, false},
{"0.0.0", MinorChange, "0.1.0", true, false},
{"0.0.0", MajorChange, "1.0.0", true, false},
{"0.0.0", MajorChange, "0.1.0", true, false},

{"1.0.0", NoChange, "", false, false},
{"1.0.0", NoChange, "1.0.1", false, true},
Expand All @@ -63,6 +63,11 @@ func TestApplyChange(t *testing.T) {
{"2.0.0-beta", MajorChange, "2.0.0-beta.1", false, false},
{"2.0.0-beta.2", MajorChange, "2.0.0-beta.3", false, false},
{"2.0.0-beta.1.1", MajorChange, "2.0.0-beta.2", false, false},

{"0.1.0", MajorChange, "0.2.0", true, false},
{"1.0.0", MajorChange, "2.0.0", true, false},
{"0.1.0", MinorChange, "0.2.0", true, false},
{"0.1.0", NoChange, "0.1.1", true, true},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 81aea83

Please sign in to comment.