Skip to content

Commit 4b7f6cc

Browse files
committed
GitVersionModule.version to handle concurrent calls
1 parent 0a741a3 commit 4b7f6cc

File tree

7 files changed

+91
-89
lines changed

7 files changed

+91
-89
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ jobs:
2020
- name: Checks
2121
run: |
2222
git config --global user.name "CI"
23-
./mill __.checkStyle
24-
./mill __.test
25-
./mill __.docJar
26-
./mill __.publishLocal
23+
./mill __.checkStyle + __.test + __.docJar + __.publishLocal
2724
- name: Publish
2825
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
2926
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mill-git
22

3-
![Maven Central](https://img.shields.io/maven-central/v/com.goyeau/mill-git_mill0.10_2.13)
3+
![Maven Central](https://img.shields.io/maven-central/v/com.goyeau/mill-git_mill0.11_2.13)
44

55
A git version plugin for Mill build tool.
66

build.mill

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import $ivy.`org.typelevel::scalac-options:0.1.7`
44
import com.goyeau.mill.git.{GitVersionModule, GitVersionedPublishModule}
55
import com.goyeau.mill.scalafix.StyleModule
66
import mill._
7+
import mill.Task.dest
78
import mill.scalalib._
89
import mill.scalalib.api.ZincWorkerUtil.scalaNativeBinaryVersion
910
import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl}
1011
import org.typelevel.scalacoptions.ScalacOptions._
1112
import org.typelevel.scalacoptions.{ScalaVersion, ScalacOptions}
1213

1314
val millVersions = Seq("0.12.0")
15+
def millBinaryVersion(millVersion: String) = scalaNativeBinaryVersion(millVersion) match {
16+
case "0.12" => "0.11"
17+
case version => version
18+
}
1419

1520
object `mill-git` extends Cross[MillGitCross](millVersions)
1621
trait MillGitCross extends Cross.Module[String] with StyleModule with GitVersionedPublishModule {
@@ -20,7 +25,6 @@ trait MillGitCross extends Cross.Module[String] with StyleModule with GitVersion
2025
ScalaVersion.unsafeFromString(scalaVersion()),
2126
ScalacOptions.default + source3 ++ fatalWarningOptions
2227
)
23-
override def artifactName = s"mill-git_mill${scalaNativeBinaryVersion(millVersion)}"
2428

2529
override def compileIvyDeps = super.compileIvyDeps() ++ Agg(
2630
ivy"com.lihaoyi::mill-main:$millVersion",
@@ -41,13 +45,14 @@ trait MillGitCross extends Cross.Module[String] with StyleModule with GitVersion
4145
override def ivyDeps = Agg(ivy"com.lihaoyi:mill-dist:$millVersion")
4246
override def mainClass = Some("mill.runner.client.MillClientMain")
4347
override def resources = T {
44-
val p = Task.dest / "mill/local-test-overrides" / s"com.lihaoyi-${MillGitCross.this.artifactId()}"
48+
val p = dest / MillGitCross.this.artifactId()
4549
os.write(p, MillGitCross.this.localClasspath().map(_.path).mkString("\n"), createFolders = true)
46-
Seq(PathRef(T.dest))
50+
Seq(PathRef(dest))
4751
}
4852
}
4953
}
5054

55+
override def artifactName = s"mill-git_mill${millBinaryVersion(millVersion)}"
5156
override def publishVersion = GitVersionModule.version(withSnapshotSuffix = true)()
5257
def pomSettings = PomSettings(
5358
description = "A git version plugin for Mill build tool",

mill-git/src/com/goyeau/mill/git/GitVersionModule.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package com.goyeau.mill.git
22

3-
import mill._
4-
import mill.api.Result.{Exception => MillException, OuterStack, Success => MillSuccess}
3+
import mill.*
4+
import mill.api.Result.{Exception as MillException, OuterStack, Success as MillSuccess}
5+
import mill.Task.workspace
56
import mill.define.{Command, Discover, ExternalModule}
67
import org.eclipse.jgit.api.Git
78
import org.eclipse.jgit.lib.RepositoryBuilder
8-
import os._
9-
import scala.util.{Failure => TryFailure, Success => TrySuccess, Try}
9+
import os.*
10+
import scala.util.{Failure as TryFailure, Success as TrySuccess, Try}
1011

1112
object GitVersionModule extends ExternalModule {
1213

1314
/** Version derived from git.
1415
*/
1516
def version(hashLength: Int = 7, withSnapshotSuffix: Boolean = false): Command[String] =
16-
T.command {
17-
val workspacePath = T.workspace
18-
val git = Git.open(workspacePath.toIO)
17+
Task.Command {
18+
val git = Git.open(workspace.toIO)
1919
val status = git.status().call()
2020
val isDirty = status.hasUncommittedChanges || !status.getUntracked.isEmpty
2121
val snapshotSuffix = if (withSnapshotSuffix) "-SNAPSHOT" else ""
22-
def uncommitted() = s"${uncommittedHash(git, T.ctx().dest, hashLength)}$snapshotSuffix"
22+
def uncommitted() = s"${uncommittedHash(git, hashLength)}$snapshotSuffix"
2323

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

@@ -49,8 +49,8 @@ object GitVersionModule extends ExternalModule {
4949
}
5050
}
5151

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

5656
// Use different index file to avoid messing up current git status

mill-git/test/src/com/goyeau/mill/git/CustomProjectIntegrationTests.scala

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class CustomProjectIntegrationTests extends FunSuite {
77
val tester = Tester.create(os.rel / "custom")
88
val _ = os.proc("git", "init").call(cwd = tester.workspacePath)
99

10-
val res1 = tester.eval(Seq("show", "project.jobVersion"))
11-
assert(res1.isSuccess, res1.err)
12-
assert(res1.out.matches(""""[\da-f]{7}""""), s"${res1.out} is not a 7 chars hash")
10+
val result = tester.eval(Seq("show", "project.jobVersion"))
11+
assert(result.isSuccess, result.err)
12+
assert(result.out.matches(""""[\da-f]{7}""""), s"${result.out} is not a 7 chars hash")
1313
}
1414

1515
test("Commit without tag") {
@@ -19,9 +19,9 @@ class CustomProjectIntegrationTests extends FunSuite {
1919
val _ = os.proc("git", "commit", "-m", "Some commit").call(cwd = tester.workspacePath)
2020
val hash = os.proc("git", "rev-parse", "HEAD").call(cwd = tester.workspacePath).out.trim().take(7)
2121

22-
val res1 = tester.eval(Seq("show", "project.jobVersion"))
23-
assert(res1.isSuccess, res1.err)
24-
assertEquals(res1.out, s""""$hash"""")
22+
val result = tester.eval(Seq("show", "project.jobVersion"))
23+
assert(result.isSuccess, result.err)
24+
assertEquals(result.out, s""""$hash"""")
2525
}
2626

2727
test("Uncommitted changes after commit without tag") {
@@ -31,9 +31,9 @@ class CustomProjectIntegrationTests extends FunSuite {
3131
val _ = os.proc("git", "commit", "-m", "Some commit").call(cwd = tester.workspacePath)
3232
val _ = os.write(tester.workspacePath / "some-file", "Some change!")
3333

34-
val res1 = tester.eval(Seq("show", "project.jobVersion"))
35-
assert(res1.isSuccess, res1.err)
36-
assert(res1.out.matches(""""[\da-f]{7}""""), s"${res1.out} is not a 7 chars hash")
34+
val result = tester.eval(Seq("show", "project.jobVersion"))
35+
assert(result.isSuccess, result.err)
36+
assert(result.out.matches(""""[\da-f]{7}""""), s"${result.out} is not a 7 chars hash")
3737
}
3838

3939
test("Head tagged") {
@@ -43,9 +43,9 @@ class CustomProjectIntegrationTests extends FunSuite {
4343
val _ = os.proc("git", "commit", "-m", "Some commit").call(cwd = tester.workspacePath)
4444
val _ = os.proc("git", "tag", "-a", "v1.0.0", "-m", "v1.0.0").call(cwd = tester.workspacePath)
4545

46-
val res1 = tester.eval(Seq("show", "project.jobVersion"))
47-
assert(res1.isSuccess, res1.err)
48-
assertEquals(res1.out, """"1.0.0"""")
46+
val result = tester.eval(Seq("show", "project.jobVersion"))
47+
assert(result.isSuccess, result.err)
48+
assertEquals(result.out, """"1.0.0"""")
4949
}
5050

5151
test("Uncommitted changes after tag") {
@@ -56,11 +56,11 @@ class CustomProjectIntegrationTests extends FunSuite {
5656
val _ = os.proc("git", "tag", "-a", "v1.0.0", "-m", "v1.0.0").call(cwd = tester.workspacePath)
5757
val _ = os.write(tester.workspacePath / "some-file", "Some change!")
5858

59-
val res1 = tester.eval(Seq("show", "project.jobVersion"))
60-
assert(res1.isSuccess, res1.err)
59+
val result = tester.eval(Seq("show", "project.jobVersion"))
60+
assert(result.isSuccess, result.err)
6161
assert(
62-
res1.out.matches(""""1\.0\.0-1-[\da-f]{7}""""),
63-
s"${res1.out} is not a version and distance from it, followed by a 7 chars hash"
62+
result.out.matches(""""1\.0\.0-1-[\da-f]{7}""""),
63+
s"${result.out} is not a version and distance from it, followed by a 7 chars hash"
6464
)
6565
}
6666

@@ -75,9 +75,9 @@ class CustomProjectIntegrationTests extends FunSuite {
7575
val _ = os.proc("git", "commit", "-m", "Some commit 2").call(cwd = tester.workspacePath)
7676
val hash = os.proc("git", "rev-parse", "HEAD").call(cwd = tester.workspacePath).out.trim().take(7)
7777

78-
val res1 = tester.eval(Seq("show", "project.jobVersion"))
79-
assert(res1.isSuccess, res1.err)
80-
assertEquals(res1.out, s""""1.0.0-1-$hash"""")
78+
val result = tester.eval(Seq("show", "project.jobVersion"))
79+
assert(result.isSuccess, result.err)
80+
assertEquals(result.out, s""""1.0.0-1-$hash"""")
8181
}
8282

8383
test("Uncommitted changes after tag and after commit") {
@@ -91,11 +91,11 @@ class CustomProjectIntegrationTests extends FunSuite {
9191
val _ = os.proc("git", "commit", "-m", "Some commit 2").call(cwd = tester.workspacePath)
9292
val _ = os.write.append(tester.workspacePath / "some-file", "Some change 2!")
9393

94-
val res1 = tester.eval(Seq("show", "project.jobVersion"))
95-
assert(res1.isSuccess, res1.err)
94+
val result = tester.eval(Seq("show", "project.jobVersion"))
95+
assert(result.isSuccess, result.err)
9696
assert(
97-
res1.out.matches(""""1\.0\.0-2-[\da-f]{7}""""),
98-
s"${res1.out} is not a version and distance from it, followed by a 7 chars hash"
97+
result.out.matches(""""1\.0\.0-2-[\da-f]{7}""""),
98+
s"${result.out} is not a version and distance from it, followed by a 7 chars hash"
9999
)
100100
}
101101
}

mill-git/test/src/com/goyeau/mill/git/DockerProjectIntegrationTests.scala

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ class DockerProjectIntegrationTests extends FunSuite {
77
val tester = Tester.create(os.rel / "docker")
88
val _ = os.proc("git", "init").call(cwd = tester.workspacePath)
99

10-
val res1 = tester.eval(Seq("show", "project.docker.tags"))
11-
assert(res1.isSuccess, res1.err)
10+
val result = tester.eval(Seq("show", "project.docker.tags"))
11+
assert(result.isSuccess, result.err)
1212
assert(
13-
res1.out.matches("""\[
13+
result.out.matches("""\[
1414
| "project:[\da-f]{7}",
1515
| "project:latest"
1616
|\]""".stripMargin),
17-
s"${res1.out} is not an array with 7 chars hash and latest tags"
17+
s"${result.out} is not an array with 7 chars hash and latest tags"
1818
)
1919
}
2020

@@ -25,10 +25,10 @@ class DockerProjectIntegrationTests extends FunSuite {
2525
val _ = os.proc("git", "commit", "-m", "Some commit").call(cwd = tester.workspacePath)
2626
val hash = os.proc("git", "rev-parse", "HEAD").call(cwd = tester.workspacePath).out.trim().take(7)
2727

28-
val res1 = tester.eval(Seq("show", "project.docker.tags"))
29-
assert(res1.isSuccess, res1.err)
28+
val result = tester.eval(Seq("show", "project.docker.tags"))
29+
assert(result.isSuccess, result.err)
3030
assertEquals(
31-
res1.out,
31+
result.out,
3232
s"""[
3333
| "project:$hash",
3434
| "project:latest"
@@ -43,14 +43,14 @@ class DockerProjectIntegrationTests extends FunSuite {
4343
val _ = os.proc("git", "commit", "-m", "Some commit").call(cwd = tester.workspacePath)
4444
val _ = os.write(tester.workspacePath / "some-file", "Some change!")
4545

46-
val res1 = tester.eval(Seq("show", "project.docker.tags"))
47-
assert(res1.isSuccess, res1.err)
46+
val result = tester.eval(Seq("show", "project.docker.tags"))
47+
assert(result.isSuccess, result.err)
4848
assert(
49-
res1.out.matches("""\[
49+
result.out.matches("""\[
5050
| "project:[\da-f]{7}",
5151
| "project:latest"
5252
|\]""".stripMargin),
53-
s"${res1.out} is not a 7 chars hash"
53+
s"${result.out} is not a 7 chars hash"
5454
)
5555
}
5656

@@ -61,10 +61,10 @@ class DockerProjectIntegrationTests extends FunSuite {
6161
val _ = os.proc("git", "commit", "-m", "Some commit").call(cwd = tester.workspacePath)
6262
val _ = os.proc("git", "tag", "-a", "v1.0.0", "-m", "v1.0.0").call(cwd = tester.workspacePath)
6363

64-
val res1 = tester.eval(Seq("show", "project.docker.tags"))
65-
assert(res1.isSuccess, res1.err)
64+
val result = tester.eval(Seq("show", "project.docker.tags"))
65+
assert(result.isSuccess, result.err)
6666
assertEquals(
67-
res1.out,
67+
result.out,
6868
"""[
6969
| "project:1.0.0",
7070
| "project:latest"
@@ -80,14 +80,14 @@ class DockerProjectIntegrationTests extends FunSuite {
8080
val _ = os.proc("git", "tag", "-a", "v1.0.0", "-m", "v1.0.0").call(cwd = tester.workspacePath)
8181
val _ = os.write(tester.workspacePath / "some-file", "Some change!")
8282

83-
val res1 = tester.eval(Seq("show", "project.docker.tags"))
84-
assert(res1.isSuccess, res1.err)
83+
val result = tester.eval(Seq("show", "project.docker.tags"))
84+
assert(result.isSuccess, result.err)
8585
assert(
86-
res1.out.matches("""\[
86+
result.out.matches("""\[
8787
| "project:1\.0\.0-1-[\da-f]{7}",
8888
| "project:latest"
8989
|\]""".stripMargin),
90-
s"${res1.out} is not a version and distance from it, followed by a 7 chars hash"
90+
s"${result.out} is not a version and distance from it, followed by a 7 chars hash"
9191
)
9292
}
9393

@@ -102,10 +102,10 @@ class DockerProjectIntegrationTests extends FunSuite {
102102
val _ = os.proc("git", "commit", "-m", "Some commit 2").call(cwd = tester.workspacePath)
103103
val hash = os.proc("git", "rev-parse", "HEAD").call(cwd = tester.workspacePath).out.trim().take(7)
104104

105-
val res1 = tester.eval(Seq("show", "project.docker.tags"))
106-
assert(res1.isSuccess, res1.err)
105+
val result = tester.eval(Seq("show", "project.docker.tags"))
106+
assert(result.isSuccess, result.err)
107107
assertEquals(
108-
res1.out,
108+
result.out,
109109
s"""[
110110
| "project:1.0.0-1-$hash",
111111
| "project:latest"
@@ -124,14 +124,14 @@ class DockerProjectIntegrationTests extends FunSuite {
124124
val _ = os.proc("git", "commit", "-m", "Some commit 2").call(cwd = tester.workspacePath)
125125
val _ = os.write.append(tester.workspacePath / "some-file", "Some change 2!")
126126

127-
val res1 = tester.eval(Seq("show", "project.docker.tags"))
128-
assert(res1.isSuccess, res1.err)
127+
val result = tester.eval(Seq("show", "project.docker.tags"))
128+
assert(result.isSuccess, result.err)
129129
assert(
130-
res1.out.matches("""\[
130+
result.out.matches("""\[
131131
| "project:1\.0\.0-2-[\da-f]{7}",
132132
| "project:latest"
133133
|\]""".stripMargin),
134-
s"${res1.out} is not a version and distance from it, followed by a 7 chars hash"
134+
s"${result.out} is not a version and distance from it, followed by a 7 chars hash"
135135
)
136136
}
137137
}

0 commit comments

Comments
 (0)