Skip to content

Commit

Permalink
Merge pull request #3 from jeffmay/review-followup
Browse files Browse the repository at this point in the history
Cleaned up references of rallyVersions and renamed semVerLimit
  • Loading branch information
jeffmay authored Jul 26, 2017
2 parents f75305d + 11f4b5c commit 9622e06
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 222 deletions.
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ Alternatively, you can add the following (if you want to use Maven style resolut
```scala
Resolver.bintrayRepo("rallyhealth", "sbt-plugins")
```
In either case, you should now be able to add the append the plugin dependency to the `project/plugins.sbt`:
In either case, you should now be able to add the plugin dependency to `project/plugins.sbt`:
```scala
addSbtPlugin("com.rallyhealth.sbt" % "git-versioning-sbt-plugin" % "x.y.z")
```
3. Enable the plugin and set `semVerVersionLimit` in `build.sbt` (see
3. Enable the plugin and set `semVerLimit` in `build.sbt` (see
[below](https://github.com/rallyhealth/git-versioning-sbt-plugin#semverversionlimit)
for details)

```scala
val example = project
.enablePlugins(SemVerPlugin)
// See https://github.com/rallyhealth/git-versioning-sbt-plugin#semverversionlimit
.settings(semVerVersionLimit := "x.y.z")
.settings(semVerLimit := "x.y.z")
```

# GitVersioningPlugin
Expand Down Expand Up @@ -196,7 +196,7 @@ You can run the check manually using `semVerCheck`. The check and also be run au

The output will look like this:
```
[info] [SemVer] Checking ENABLED with LIMIT target semVerVersionLimit=3.0.0
[info] [SemVer] Checking ENABLED with LIMIT target semVerLimit=3.0.0
[info] [SemVer] Check starting (prev=2.0.0 vs curr=3.0.0) ...
[warn] [SemVer] Errors total=4, backward=0, forward=4, required diffType=minor
[warn] [SemVer] (1/4) Forward -> method calamity()Double in class com.rallyhealth.semver.Equestria does not have a correspondent in previous version
Expand All @@ -209,7 +209,7 @@ The output will look like this:

When the SemVerPlugin halts the build it will look like:
```
[info] [SemVer] Checking ENABLED with LIMIT target semVerVersionLimit=2.0.1
[info] [SemVer] Checking ENABLED with LIMIT target semVerLimit=2.0.1
[info] [SemVer] Check starting (prev=2.0.0 vs curr=2.0.1) ...
[error] [SemVer] Errors total=4, backward=0, forward=4, required diffType=minor
[error] [SemVer] (1/4) Forward -> method calamity()Double in class com.rallyhealth.semver.Equestria does not have a correspondent in previous version
Expand All @@ -224,32 +224,32 @@ java.lang.IllegalStateException: Proposed RELEASE version=2.0.1 FAILED SemVer ru
[error] Total time: 2 s, completed Nov 15, 2016 3:27:36 PM
```

### semVerVersionLimit
### semVerLimit

Before using the check (manually or automatically), you *must* set the `semVerVersionLimit` key in your `build.sbt`.
Before using the check (manually or automatically), you *must* set the `semVerLimit` key in your `build.sbt`.
This is a version (e.g. "1.2.3") that tells SemVerPlugin when to halt the build. It prevents you from making any
compatibility changes that would *exceed* that version.

This is best explained with an example. Let's assume the latest tag is `1.2.3`:

* `semVerVersionLimit := 1.2.3` - you won't be able to make *any* changes
* `semVerVersionLimit := 1.2.**999**` - you will be allowed to make *patch* changes.
* `semVerVersionLimit := 1.**999.999**` - you will be allowed to make *minor or patch* changes.
* `semVerVersionLimit := ""` - you will be allowed to make *major, minor, or patch* changes (`semVerVersionLimit` is disabled)
* `semVerLimit := 1.2.3` - you won't be able to make *any* changes
* `semVerLimit := 1.2.**999**` - you will be allowed to make *patch* changes.
* `semVerLimit := 1.**999.999**` - you will be allowed to make *minor or patch* changes.
* `semVerLimit := ""` - you will be allowed to make *major, minor, or patch* changes (`semVerLimit` is disabled)

Here are a few stories to illustrate how `semVerVersionLimit` works.
Here are a few stories to illustrate how `semVerLimit` works.

#### Patch Change

1. Version is `1.2.3` and `semVerVersionLimit := 1.9.9`:
1. Version is `1.2.3` and `semVerLimit := 1.9.9`:
2. Fluttershy needs to fix a bug (patch change).
3. Fluttershy fixes, sees no backward or forward errors from SemVerPlugin.
4. Fluttershy commits, PRs, and merges.
5. Fluttershy successfully runs the release job for `1.2.4`.

#### Minor Change (with a human error)

1. Version is `1.2.4` (from above) and `semVerVersionLimit := 1.9.9`:
1. Version is `1.2.4` (from above) and `semVerLimit := 1.9.9`:
2. Applejack wants to add a new method (minor change).
3. Applejack adds the new method, commits, PRs, and merges.
4. Applejack runs the release job for `1.2.4` but the release job fails.
Expand All @@ -258,7 +258,7 @@ Here are a few stories to illustrate how `semVerVersionLimit` works.

#### A 'Big' Patch Change

1. Version is `1.3.0` (from above) and `semVerVersionLimit := 1.9.9`:
1. Version is `1.3.0` (from above) and `semVerLimit := 1.9.9`:
2. Twilight Sparkle found a potential bug for an edge case, e.g. some
'undefined' behavior. She only needs to make a *patch* change, but
someone could be relying on that 'undefined' behavior, she wants to release
Expand All @@ -270,37 +270,37 @@ change even though only *patch* was required)

#### Hot Fix (patch change)

1. Version is `1.4.0` (from above) and `semVerVersionLimit := 1.9.9`:
1. Version is `1.4.0` (from above) and `semVerLimit := 1.9.9`:
2. Rainbow Dash needs to make a hot fix.
3. Rainbow Dash changes `semVerVersionLimit := 1.4.1` so she's absolutely sure no minor changes sneak in.
3. Rainbow Dash changes `semVerLimit := 1.4.1` so she's absolutely sure no minor changes sneak in.
4. Rainbow Dash makes her fix, commits, PRs, and merges
5. Rainbow Dash successfully runs the release job for `1.4.1`.
6. *Unfortunately the next committer will need to reset `semVerVersionLimit := 1.9.9`*
7. Rainbow Dash helpfully merges a PR to revert `semVerVersionLimit := 1.9.9`
6. *Unfortunately the next committer will need to reset `semVerLimit := 1.9.9`*
7. Rainbow Dash helpfully merges a PR to revert `semVerLimit := 1.9.9`

#### Hot Fix Redux (patch change)

1. Version is `1.4.1` (from above) and `semVerVersionLimit := 1.9.9`:
1. Version is `1.4.1` (from above) and `semVerLimit := 1.9.9`:
2. Pinkie Pie needs to make another hot fix.
3. Pinkie Pie does not want to do a clean up commit like Rainbow Dash.
4. Pinkie Pie runs SBT and executes ```> set semVerVersionLimit := 1.4.2``` before any other command.
4. Pinkie Pie runs SBT and executes ```> set semVerLimit := 1.4.2``` before any other command.
5. Pinkie Pie makes her fix, commits, PRs
6. Pinkie Pie successfully runs the release job for `1.4.2`.

#### Major Change

1. Version is `1.4.2` (from above) and `semVerVersionLimit := 1.9.9`:
1. Version is `1.4.2` (from above) and `semVerLimit := 1.9.9`:
2. Rarity wants to make a major breaking API change.
3. Rarity changes `semVerVersionLimit := 2.0.0` so she can release `2.9.9` when she is done.
3. Rarity changes `semVerLimit := 2.0.0` so she can release `2.9.9` when she is done.
4. Rarity makes her API change, commits, PRs, and merges.
5. Rarity successfully runs the release job for `2.0.0`.

#### What should you choose for `semVerVersionLimit`?
#### What should you choose for `semVerLimit`?

* First, talk to the team working on the service, or the users of the library. What do they want?
* If you want to allow any backward compatible changes might choose a limit like `semVerVersionLimit := 1.999.999`
* If you want to avoid changes you might choose a limit like `semVerVersionLimit := 1.0.999`
* If you don't care about *any* changes you can disable the limt using `semVerVersionLimit := ""`.
* If you want to allow any backward compatible changes might choose a limit like `semVerLimit := 1.999.999`
* If you want to avoid changes you might choose a limit like `semVerLimit := 1.0.999`
* If you don't care about *any* changes you can disable the limt using `semVerLimit := ""`.

## Information

Expand Down
16 changes: 8 additions & 8 deletions src/main/scala/com/rallyhealth/sbt/semver/SemVerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object SemVerPlugin extends AutoPlugin {
* This is really a setting, but settings are checked at startup so if any are missing or throw exceptions SBT
* fails to load. But tasks won't be checked until they are actually used, so its like a lazy setting.
*/
lazy val semVerVersionLimit: TaskKey[String] = taskKey[String](
"'semVerVersionLimit' is a threshold Release version, it is a version you do NOT want to exceed with these" +
lazy val semVerLimit: TaskKey[String] = taskKey[String](
"'semVerLimit' is a threshold Release version, it is a version you do NOT want to exceed with these" +
" changes. If non-empty the `semVerCheck` will ensure that your changes do not require a release EQUAL or" +
" GREATER than this version. (no default value)")

Expand Down Expand Up @@ -86,16 +86,16 @@ object SemVerPlugin extends AutoPlugin {
* If you don't provide this a value you get a rather generic error as soon as you run SBT:
* {{{
* References to undefined settings:
* :semVerVersionLimit from *:test ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* :semVerVersionLimit from *:publishLocal ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* :semVerVersionLimit from *:compile ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* :semVerVersionLimit from *:semVerCheck ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* :semVerLimit from *:test ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* :semVerLimit from *:publishLocal ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* :semVerLimit from *:compile ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* :semVerLimit from *:semVerCheck ((com.rallyhealth.sbt.semver.SemVerPlugin) SemVerPlugin.scala:NNN)
* }}}
* I think a clear error message that allows you to load SBT an fail when you run the task is a better choice.
*/
semVerVersionLimit := {
semVerLimit := {
throw new IllegalArgumentException(
s"${SemVerPluginUtils.ConfigErrorPrefix} 'semVerVersionLimit' is not set in your 'build.sbt'"
s"${SemVerPluginUtils.ConfigErrorPrefix} 'semVerLimit' is not set in your 'build.sbt'"
)
}
)
Expand Down
32 changes: 16 additions & 16 deletions src/main/scala/com/rallyhealth/sbt/semver/SemVerPluginUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ object SemVerPluginUtils {
// often hard to mock

// "version" SettingKey is assumed to be a SemanticVersion; see the overload in RallyVersioningPlugin
val rallyVersion: SemanticVersion = SemanticVersion.fromString(version.value).getOrElse(
val semver: SemanticVersion = SemanticVersion.fromString(version.value).getOrElse(
throw new IllegalArgumentException(s"version=${version.value} is not a valid SemVer"))
val enforceAfterVersion: Option[ReleaseVersion] = semVerEnforceAfterVersion.value.map(parseAsCleanOrThrow)

val preReleaseEnabled = semVerPreRelease.value
val taskStreams: TaskStreams = streams.value
implicit val logger: sbt.Logger = taskStreams.log

if (rallyVersion.isPreRelease && !preReleaseEnabled) {
logger.info(s"$SemVerPrefix Checking DISABLED for pre-release version=$rallyVersion")
} else if (enforceAfterVersion.isDefined && rallyVersion <= enforceAfterVersion.get) {
logger.info(s"$SemVerPrefix Checking DISABLED for version=$rallyVersion less than or equal to" +
if (semver.isPreRelease && !preReleaseEnabled) {
logger.info(s"$SemVerPrefix Checking DISABLED for pre-release version=$semver")
} else if (enforceAfterVersion.isDefined && semver <= enforceAfterVersion.get) {
logger.info(s"$SemVerPrefix Checking DISABLED for version=$semver less than or equal to" +
s" enforceAfterVersion=${enforceAfterVersion.get} $noViolationsSuffix")
} else {

val maybeTargetVersion = calcTargetVersion(
versionOverride.value, semVerVersionLimit.value, versionFromGit.value, logger)
versionOverride.value, semVerLimit.value, versionFromGit.value, logger)

maybeTargetVersion.foreach { targetVersion =>

Expand Down Expand Up @@ -125,7 +125,7 @@ object SemVerPluginUtils {
* Figures out the version we will be using for SemVer checking, the "target" version. The target version either:
* - [[versionOverride]] (if available) is the version the developer is trying to release.
* - [[versionFromGit]] (if a clean release) is the version of the actual code.
* - [[semVerVersionLimit]] (if available) the version the developer wants to stay under.
* - [[semVerLimit]] (if available) the version the developer wants to stay under.
* If none of these are available then SemVer checking will be disabled.
*
* Why do we not consider [[version]]? The [[version]] is not necessarily what the developer wants -- it is either
Expand All @@ -134,7 +134,7 @@ object SemVerPluginUtils {
* the last release version).
*
* @param maybeVersionOverrideStr From [[versionOverride]]
* @param versionLimitStr From [[semVerVersionLimit]]
* @param versionLimitStr From [[semVerLimit]]
* @param versionFromGit From [[versionFromGit]] from [[GitDriver.calcCurrentVersion()]] -- NOT [[version]] since
* could be either [[versionOverride]] or [[versionFromGit]]
* @return The version we will target for the SemVer comparison, or None to disable SemVer checking.
Expand Down Expand Up @@ -166,14 +166,14 @@ object SemVerPluginUtils {
logger.info(s"$SemVerPrefix Checking ENABLED with SPECIFIC target versionFromGit=$versionFromGit")
Some(SemVerSpecificTargetVersion(verFromGit))

// semVerVersionLimit has the third highest precedence (limit < specific)
// semVerLimit has the third highest precedence (limit < specific)
case (None, Some(verLimit), _) =>
logger.info(s"$SemVerPrefix Checking ENABLED with LIMIT target semVerVersionLimit=$verLimit")
logger.info(s"$SemVerPrefix Checking ENABLED with LIMIT target semVerLimit=$verLimit")
Some(SemVerLimitTargetVersion(verLimit))

case (None, None, _) =>
logger.info(
s"$SemVerPrefix Checking DISABLED with empty semVerVersionLimit, empty versionOverride, and dirty and/or" +
s"$SemVerPrefix Checking DISABLED with empty semVerLimit, empty versionOverride, and dirty and/or" +
" SNAPSHOT versionFromGit")
None
}
Expand All @@ -193,7 +193,7 @@ object SemVerPluginUtils {
* a nonsensical situation.
*
* @param maybeVersionOverride From [[versionOverride]]
* @param maybeVersionLimit From [[semVerVersionLimit]]
* @param maybeVersionLimit From [[semVerLimit]]
* @param versionFromGit From [[versionFromGit]] from [[GitDriver.calcCurrentVersion()]] -- NOT [[version]] since
* could be either [[versionOverride]] or [[versionFromGit]]
* @return The version we will target for the SemVer comparison, or None to disable SemVer checking.
Expand All @@ -215,7 +215,7 @@ object SemVerPluginUtils {
Option((maybeVersionOverride, maybeVersionLimit, versionFromGit)).collect {

case (Some(verOverride), Some(verLimit), _) if verOverride > verLimit =>
s"semVerVersionLimit=$verLimit cannot be less than versionOverride=$verOverride;" +
s"semVerLimit=$verLimit cannot be less than versionOverride=$verOverride;" +
" your limit wasn't updated after the last release, and would likely prevent ANY new changes"

// this is most likely a user error -- you are forcing a version with uncommitted changes. you typically force
Expand All @@ -238,16 +238,16 @@ object SemVerPluginUtils {
s"versionOverride=$verOverride cannot be less than or equal to SNAPSHOT version=$verGit;" +
" cannot create new release with un-tagged commits that are less previously released version"

// we do NOT check EQUAL here because its okay if semVerVersionLimit matches the versionFromGit: it usually means
// we do NOT check EQUAL here because its okay if semVerLimit matches the versionFromGit: it usually means
// the developer tagged FIRST and updated the limit. That's a valid order of operations -- SemVer will still
// catch if new changes are made beyond that tag
case (_, Some(verLimit), verGit: ReleaseVersion) if verLimit < verGit =>
s"semVerVersionLimit=$verLimit cannot be less than or equal to version=$verGit;" +
s"semVerLimit=$verLimit cannot be less than or equal to version=$verGit;" +
" your limit prevents new ANY changes, update it to something greater than the last release"

// Same as above, but we have to fix the version due to the incrementing done by GitDriver.calcCurrentVersion()
case (_, Some(verLimit), verGit: SnapshotVersion) if verLimit <= verGit.undoNextVersion().toRelease =>
s"semVerVersionLimit=$verLimit cannot be less than or equal version=$verGit;" +
s"semVerLimit=$verLimit cannot be less than or equal version=$verGit;" +
" your limit prevents new ANY changes, update it to something greater than the last release"

}.foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sealed trait SemVerTargetVersion {
}

/**
* If the user sets [[SemVerPlugin.autoImport.semVerVersionLimit]] then the [[ReleaseVersion]] is a limit, an upper
* If the user sets [[SemVerPlugin.autoImport.semVerLimit]] then the [[ReleaseVersion]] is a limit, an upper
* bound. It is cannot be used for some errors, like [[NotNormalizedSemVerDiff]].
*
* This class should ALWAYS have higher precedence than [[SemVerSpecificTargetVersion]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object GitVersioningPlugin extends AutoPlugin {
* up to v2.0.0-4-aabcdef-SNAPSHOT without tagging:
*
* {{{
* rallyVersionSnapshotLowerBound := "2.0.0"
* gitVersioningSnapshotLowerBound := "2.0.0"
* }}}
*
* [[gitVersioningSnapshotLowerBound]] acts as a lower bound and has no effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ object ReleaseVersion {
*
* For example:
* {{{
* val rallyVersioningSnapshotLowerBound = settingKey[Option[ReleaseVersion]]("...")
* rallyVersioningSnapshotLowerBound := "1.2.3"
* val gitVersioningSnapshotLowerBound = settingKey[Option[ReleaseVersion]]("...")
* gitVersioningSnapshotLowerBound := "1.2.3"
* }}}
*
* {{{
* sbt> set rallyVersioningSnapshotLowerBound := "1.2.3"
* sbt> set gitVersioningSnapshotLowerBound := "1.2.3"
* }}}
*/
implicit def fromStringToMaybeReleaseVersion(s: String): Option[ReleaseVersion] = unapply(s)
Expand Down
Loading

0 comments on commit 9622e06

Please sign in to comment.