Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support omitting the commit count #65

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The `format` method has the following options:

* `noTagFallback: String = "0.0.0"` - will be used when no tag was found
* `countSep: String = "-"` - will be printed before the commit count when it is greater than zero
* `commitCountPad: Byte = 0` - if greater that zero, the commit count will be padded to the given length
* `commitCountPad: Byte = 0` - if greater than zero, the commit count will be padded to the given length; a negative value results in never adding the commit count
* `revSep: String = "-"` - will be printed before the revision hash if it is not a tagged revision
* `revHashDigits: Int = 6` - the number of digits to be used for the revision hash
* `dirtySep: String = "-DIRTY"` - will be printed before the dirty hash if the local repository is in modified state
Expand Down
2 changes: 1 addition & 1 deletion core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ case class VcsState(
val commitCountPart = if (lastTag.isEmpty || commitsSinceLastTag > 0) {
s"$countSep${if (commitCountPad > 0) {
(10000000000000L + commitsSinceLastTag).toString().substring(14 - commitCountPad, 14)
} else commitsSinceLastTag}"
} else if (commitCountPad == 0) commitsSinceLastTag else ""}"
Copy link
Contributor

@ckipp01 ckipp01 Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even with this change the revisionPart will still come after it won't it? So if

  1. tag 0.1.0
  2. commit twice
  3. wouldn't this produce 0.1.0-SNAPSHOT_revisionPart_

If so, that'd be what I'm trying to avoid. According to sonatype snapshots the version has to end with -SNAPSHOT in order to be published.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more context, my goal is this https://github.com/ckipp01/mill-ci-release/actions/workflows/release.yml

Release a snapshot for every merge into main. I'm hacking it now, but the way my versions looks here is what I'd want: 0.1.1-2-16b374-SNAPSHOT for example. So that every one is unique and ends in -SNAPSHOT.

Copy link
Owner Author

@lefou lefou Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then a completely misunderstood your request. To my (probably outdated) knowledge, Maven is handling -SNAPSHOT dependencies specially when deploying to a remote repository, by replacing the SNAPSHOT suffix with a timestamp.

But now I see, that you don't want to rely on that mechanism, but instead just want to append the -SNAPSHOT. I think the -SNAPSHOT suffix was initially only intended to be used in local repositories, but it looks like it is nowadays commonly used, so yeah, we can also implement that.

I think we still want to keep the essential change of this PR, omitting the count.

} else ""

val revisionPart = if (lastTag.isEmpty || commitsSinceLastTag > 0) {
Expand Down
10 changes: 10 additions & 0 deletions core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ class VcsStateSpec extends AnyFreeSpec {
case t => t
}) === "0.7.3v"
)
}

"should not render the commit count when commitCountPad is negative" in {
assert(
state("0.7.3", 4, "a6ea44d3726", "61568ec80f2465f3f01ea2c7e92273f4fbf94b01")
.format(dirtyHashDigits = 8, commitCountPad = -1, countSep = "") === "0.7.3-61568e-DIRTYa6ea44d3"
)
assert(
state("0.7.3", 4, null, "61568ec80f2465f3f01ea2c7e92273f4fbf94b01")
.format(dirtyHashDigits = 8, commitCountPad = -1, countSep = "") === "0.7.3-61568e"
)
}

"Example format configs" - {
Expand Down