Skip to content
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
8 changes: 4 additions & 4 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version = 3.9.6
runner.dialect = scala213source3
fileOverride."glob:**.mill".runner.dialect = scala3Future
project.git = true
version = 3.10.3
runner.dialect = scala3
maxColumn = 120
align.preset = more
assumeStandardLibraryStripMargin = true
rewrite.rules = [AvoidInfix, RedundantBraces, RedundantParens, SortModifiers, Imports]
rewrite.redundantBraces.stringInterpolation = true
rewrite.imports.sort = original
rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.removeOptionalBraces = oldSyntaxToo
18 changes: 8 additions & 10 deletions build.mill
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//| mill-version: 1.0.1-native
//| mill-version: 1.0.6-native
//| mill-jvm-version: 17
//| repositories:
//| - https://central.sonatype.com/repository/maven-snapshots
//| - https://oss.sonatype.org/content/repositories/snapshots
//| mvnDeps:
//| - com.goyeau::mill-git::0.3.0
//| - com.goyeau::mill-git::0.3.2
//| - com.goyeau::mill-scalafix::0.6.0
//| - org.typelevel::scalac-options:0.1.7

Expand All @@ -24,7 +24,7 @@ trait MillGitCross
with GitVersionedPublishModule
with SonatypeCentralPublishModule:
val millVersion = crossValue
override def scalaVersion = "3.7.1"
override def scalaVersion = "3.7.4"
override def scalacOptions = super.scalacOptions() ++ ScalacOptions.tokensForVersion(
ScalaVersion.unsafeFromString(scalaVersion()),
ScalacOptions.default + source3 ++ fatalWarningOptions
Expand All @@ -34,20 +34,18 @@ trait MillGitCross
mvn"com.lihaoyi::mill-libs-scalalib:$millVersion",
mvn"com.lihaoyi::mill-contrib-docker:$millVersion"
)
override def mvnDeps = super.mvnDeps() ++ Seq(mvn"org.eclipse.jgit:org.eclipse.jgit:7.1.0.202411261347-r")
override def mvnDeps = super.mvnDeps() ++ Seq(mvn"org.eclipse.jgit:org.eclipse.jgit:7.5.0.202512021534-r")

object test extends ScalaTests with TestModule.Munit:
object test extends ScalaTests with TestModule.Munit with StyleModule:
override def mvnDeps = Seq(
mvn"org.scalameta::munit::1.1.0",
mvn"org.scalameta::munit::1.2.1",
mvn"com.lihaoyi::mill-testkit:$millVersion"
)
override def forkEnv = Map("MILL_EXECUTABLE_PATH" -> millExecutable.assembly().path.toString)

// Create a Mill executable configured for testing our plugin
object millExecutable extends JavaModule:
override def mvnDeps = millVersion match
case version if version.startsWith("1.0") => Seq(mvn"com.lihaoyi:mill-runner-launcher_3:$millVersion")
case _ => Seq(mvn"com.lihaoyi:mill-dist:$millVersion")
override def mvnDeps = Seq(mvn"com.lihaoyi:mill-runner-launcher_3:$millVersion")
override def mainClass = Some("mill.launcher.MillLauncherMain")
end test

Expand All @@ -65,5 +63,5 @@ end MillGitCross

def millBinaryVersion(millVersion: String) = millVersion match
case version if version.startsWith("0.12") => "0.11" // 0.12.x is binary compatible with 0.11.x
case version if version.startsWith("1.0") => "1"
case version if version.startsWith("1.") => "1"
case _ => throw IllegalArgumentException(s"Unsupported Mill version: $millVersion")
11 changes: 5 additions & 6 deletions mill-git/src/com/goyeau/mill/git/GitTaggedDockerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import mill.*
import mill.contrib.docker.DockerModule
import mill.scalalib.JavaModule

trait GitTaggedDockerModule extends DockerModule { outer: JavaModule =>
trait GitTaggedDocker extends DockerConfig {
def tagLatest: T[Boolean] = false
trait GitTaggedDockerModule extends DockerModule:
outer: JavaModule =>
trait GitTaggedDocker extends DockerConfig:
def tagLatest: T[Boolean] = false
override def tags: T[Seq[String]] =
super.tags().map(tag => s"$tag:${GitVersionModule.version()()}") ++
(if (tagLatest()) super.tags().map(tag => s"$tag:latest") else Seq.empty)
}
}
(if tagLatest() then super.tags().map(tag => s"$tag:latest") else Seq.empty)
22 changes: 9 additions & 13 deletions mill-git/src/com/goyeau/mill/git/GitVersionModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.util.Failure as TryFailure
import scala.util.Success as TrySuccess
import scala.util.Try

object GitVersionModule extends ExternalModule {
object GitVersionModule extends ExternalModule:

/** Version derived from git.
*/
Expand All @@ -26,36 +26,34 @@ object GitVersionModule extends ExternalModule {
val git = Git.open(gitRoot.toIO)
val status = git.status().call()
val isDirty = status.hasUncommittedChanges || !status.getUntracked.isEmpty
val snapshotSuffix = if (withSnapshotSuffix) "-SNAPSHOT" else ""
val snapshotSuffix = if withSnapshotSuffix then "-SNAPSHOT" else ""
def uncommitted() = s"${uncommittedHash(git, hashLength)}$snapshotSuffix"

val describeResult = Try(git.describe().setTags(true).setMatch("v[0-9]*").setAlways(true).call())

describeResult match {
case TryFailure(_) => Result.Success(uncommitted())
describeResult match
case TryFailure(_) => Result.Success(uncommitted())
case TrySuccess(description) =>
val taggedRegex = """v(\d.*?)(?:-(\d+)-g([\da-f]+))?""".r
val untaggedRegex = """([\da-f]+)""".r

description match {
description match
case taggedRegex(tag, distance, hash) =>
val distanceHash = Option(distance).fold {
if (isDirty) s"-1-${uncommitted()}"
if isDirty then s"-1-${uncommitted()}"
else ""
} { distance =>
if (isDirty) s"-${distance.toInt + 1}-${uncommitted()}"
if isDirty then s"-${distance.toInt + 1}-${uncommitted()}"
else s"-$distance-${hash.take(hashLength)}$snapshotSuffix"
}
Result.Success(s"$tag$distanceHash")
case untaggedRegex(hash) =>
if (isDirty) Result.Success(uncommitted())
if isDirty then Result.Success(uncommitted())
else Result.Success(s"${hash.take(hashLength)}$snapshotSuffix")
case _ => Result.Failure(s"Unexpected git describe output: $description")
}
}
}

private def uncommittedHash(git: Git, hashLength: Int): String = {
private def uncommittedHash(git: Git, hashLength: Int): String =
val indexCopy = os.temp.dir() / "index"
val _ = Try(copy(pwd / ".git" / "index", indexCopy, replaceExisting = true, createFolders = true))

Expand All @@ -69,7 +67,5 @@ object GitVersionModule extends ExternalModule {
)
val cache = altGit.add().addFilepattern(".").call()
cache.writeTree(altGit.getRepository.newObjectInserter()).abbreviate(hashLength).name()
}

override lazy val millDiscover = Discover[this.type]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ package com.goyeau.mill.git
import mill.*
import mill.scalalib.PublishModule

trait GitVersionedPublishModule extends PublishModule {
trait GitVersionedPublishModule extends PublishModule:
def publishVersion: T[String] = GitVersionModule.version()()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.goyeau.mill.git

import munit.FunSuite

import scala.concurrent.duration.*

class CustomProjectIntegrationTests extends FunSuite {
class CustomProjectIntegrationTests extends FunSuite:
override val munitTimeout: Duration = 2.minute

test("Uncommitted changes") {
Expand Down Expand Up @@ -101,4 +102,3 @@ class CustomProjectIntegrationTests extends FunSuite {
s"${result.out} is not a version and distance from it, followed by a 7 chars hash"
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.goyeau.mill.git

import munit.FunSuite

import scala.concurrent.duration.*

class DockerProjectIntegrationTests extends FunSuite {
class DockerProjectIntegrationTests extends FunSuite:
override val munitTimeout: Duration = 2.minute

test("Uncommitted changes") {
Expand Down Expand Up @@ -130,4 +131,3 @@ class DockerProjectIntegrationTests extends FunSuite {
s"${result.out} is not a version and distance from it, followed by a 7 chars hash"
)
}
}
4 changes: 2 additions & 2 deletions mill-git/test/src/com/goyeau/mill/git/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.goyeau.mill.git

import mill.testkit.ExampleTester
import munit.FunSuite

import scala.concurrent.duration.*

class ExampleTests extends FunSuite {
class ExampleTests extends FunSuite:
override val munitTimeout: Duration = 2.minute

test("Custom example") {
Expand All @@ -15,4 +16,3 @@ class ExampleTests extends FunSuite {
millExecutable = os.Path(sys.env("MILL_EXECUTABLE_PATH"))
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.goyeau.mill.git

import munit.FunSuite

import scala.concurrent.duration.*

class PublishProjectIntegrationTests extends FunSuite {
class PublishProjectIntegrationTests extends FunSuite:
override val munitTimeout: Duration = 2.minute

test("Uncommitted changes") {
Expand Down Expand Up @@ -101,4 +102,3 @@ class PublishProjectIntegrationTests extends FunSuite {
s"${result.out} is not a version and distance from it, followed by a 7 chars hash"
)
}
}
6 changes: 2 additions & 4 deletions mill-git/test/src/com/goyeau/mill/git/Tester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package com.goyeau.mill.git
import mill.testkit.IntegrationTester
import os.RelPath

object Tester {
def create(project: RelPath) = {
object Tester:
def create(project: RelPath) =
val resourceFolder = os.Path(sys.env("MILL_TEST_RESOURCE_DIR"))
new IntegrationTester(
daemonMode = true,
workspaceSourcePath = resourceFolder / project,
millExecutable = os.Path(sys.env("MILL_EXECUTABLE_PATH"))
)
}
}