-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.mill
More file actions
189 lines (170 loc) · 5.22 KB
/
build.mill
File metadata and controls
189 lines (170 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//| mill-version: 1.1.3
//| mvnDeps:
//| - com.github.lolgab::mill-mima::0.2.1
import com.github.lolgab.mill.mima.*
import mill.*
import mill.api.BuildCtx
import mill.scalajslib.*
import mill.scalalib.*
import mill.scalalib.publish.*
import mill.util.VcsVersion
import java.io.File
object DepVersions {
def mdoc = "2.3.6"
def scala213 = "2.13.18"
def scalaJs = "1.20.2"
def scala = Seq(scala213, "2.12.21")
}
object Deps {
def macroParadise = mvn"org.scalamacros:::paradise:2.1.1"
def pprint = mvn"com.lihaoyi::pprint::0.9.6"
def utest = mvn"com.lihaoyi::utest::0.8.9"
}
trait VersionsMima extends Mima with PublishModule {
def mimaPreviousVersions: T[Seq[String]] = Task.Input {
val current = os.proc("git", "describe", "--tags", "--match", "v*")
.call(cwd = BuildCtx.workspaceRoot)
.out.trim()
val cutOff = coursier.version.Version("0.4.0")
os.proc("git", "tag", "-l")
.call(cwd = BuildCtx.workspaceRoot)
.out.lines()
.filter(_ != current)
.filter(_.startsWith("v"))
.map(_.stripPrefix("v"))
.map(coursier.version.Version(_))
.filter(_ > cutOff)
.sorted
.map(_.repr)
}
// required if mimaPreviousVersions is empty
def mimaPreviousArtifacts = Task {
val versions = mimaPreviousVersions().distinct
mill.api.Result.Success(
versions.map(version =>
mvn"${pomSettings().organization}:${artifactId()}:$version"
)
)
}
}
trait VersionsPublishModule extends PublishModule with VersionsMima {
def pomSettings = PomSettings(
description = artifactName(),
organization = "io.get-coursier",
url = "https://github.com/coursier/versions",
licenses = Seq(License.`Apache-2.0`),
versionControl = VersionControl.github("coursier", "versions"),
developers = Seq(
Developer("alexarchambault", "Alex Archambault","https://github.com/alexarchambault")
)
)
def publishVersion = Task {
val state = VcsVersion.vcsState()
if (state.commitsSinceLastTag > 0) {
val versionOrEmpty = state.lastTag
.filter(_ != "latest")
.map(_.stripPrefix("v"))
.flatMap { tag =>
val idx = tag.lastIndexOf(".")
if (idx >= 0)
Some(tag.take(idx + 1) + (tag.drop(idx + 1).takeWhile(_.isDigit).toInt + 1).toString + "-SNAPSHOT")
else None
}
.getOrElse("0.0.1-SNAPSHOT")
Some(versionOrEmpty)
.filter(_.nonEmpty)
.getOrElse(state.format())
} else
state
.lastTag
.getOrElse(state.format())
.stripPrefix("v")
}
}
trait Versions extends Cross.Module[String] with ScalaModule with VersionsPublishModule {
def artifactName = "versions"
def scalaVersion = crossValue
def scalacPluginMvnDeps = Task {
val sv = scalaVersion()
val scala212Plugins =
if (sv.startsWith("2.12.")) Seq(Deps.macroParadise)
else Nil
super.scalacPluginMvnDeps() ++ scala212Plugins
}
def scalacOptions = Task {
val sv = scalaVersion()
val scala213Opts =
if (sv.startsWith("2.13.")) Seq("-Ymacro-annotations")
else Nil
super.scalacOptions() ++ scala213Opts ++ Seq(
"-deprecation",
"--release",
"8"
)
}
def sources = Task {
super.sources() ++ Seq(versions.shared.sources())
}
def compileMvnDeps = Seq(
mvn"io.github.alexarchambault::data-class:0.2.7"
)
def mimaBinaryIssueFilters = super.mimaBinaryIssueFilters() ++ Seq(
// Additional abstract method on *sealed* trait
ProblemFilter.exclude[ReversedMissingMethodProblem]("coursier.version.VersionCompatibility.minimumCompatibleVersion")
)
}
trait VersionsJvm extends Versions {
object test extends ScalaTests {
def mvnDeps = super.mvnDeps() ++ Seq(
Deps.pprint,
Deps.utest
)
def testFramework = "utest.runner.Framework"
def sources = Task {
super.sources() ++ Seq(versions.shared.testSources())
}
}
}
trait VersionsJs extends Versions with ScalaJSModule {
def scalaJSVersion = DepVersions.scalaJs
object test extends ScalaJSTests {
def mvnDeps = super.mvnDeps() ++ Seq(
Deps.pprint,
Deps.utest
)
def testFramework = "utest.runner.Framework"
def sources = Task {
super.sources() ++ Seq(versions.shared.testSources())
}
}
}
object versions extends Module {
object shared extends Module {
def sources = Task.Source("src")
def testSources = Task.Source("test/src")
}
object jvm extends Cross[VersionsJvm](DepVersions.scala)
object js extends Cross[VersionsJs](DepVersions.scala)
}
def readme = Task.Source("README.md")
private def mdocScalaVersion = DepVersions.scala213
def mdoc(args: String*) = Task.Command {
val readme0 = readme().path
val dest = Task.dest / "README.md"
val cp = (versions.jvm(mdocScalaVersion).runClasspath() :+ versions.jvm(mdocScalaVersion).jar())
.map(_.path)
.filter(os.exists(_))
.filter(!os.isDir(_))
val cmd = Seq("cs", "launch", s"mdoc:${DepVersions.mdoc}", "--scala", mdocScalaVersion)
val mdocArgs = Seq(
"--in", readme0.toString,
"--out", dest.toString,
"--classpath", cp.mkString(File.pathSeparator)
)
os.proc(cmd, "--", mdocArgs, args).call(
cwd = BuildCtx.workspaceRoot,
stdin = os.Inherit,
stdout = os.Inherit,
stderr = os.Inherit
)
}