-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.sc
More file actions
249 lines (225 loc) · 7.37 KB
/
Copy pathbuild.sc
File metadata and controls
249 lines (225 loc) · 7.37 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import $ivy.`com.github.lolgab::mill-mima::0.0.24`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $file.deps, deps.{Deps, Scala, Versions}
import java.io.File
import com.github.lolgab.mill.mima.Mima
import de.tobiasroeser.mill.vcs.version._
import mill._
import mill.scalalib._
import mill.scalajslib._
import mill.scalanativelib._
import scala.concurrent.duration.DurationInt
object dependency extends Module {
object jvm extends Cross[DependencyJvm](Scala.all)
object js extends Cross[DependencyJs](Scala.all)
object native extends Cross[DependencyNative](Scala.all)
}
object `dependency-interface` extends Cross[DependencyInterface](Scala.all)
trait DependencyPublishModule extends PublishModule {
import mill.scalalib.publish._
def pomSettings = PomSettings(
description = artifactName(),
organization = "io.get-coursier",
url = "https://github.com/coursier/dependency",
licenses = Seq(License.`BSD-3-Clause`),
versionControl = VersionControl.github("coursier", "dependency"),
developers = Seq(
Developer("alexarchambault", "Alex Archambault","https://github.com/alexarchambault")
)
)
def publishVersion = T {
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 DependencyMima extends Mima {
def mimaPreviousVersions: T[Seq[String]] = T.input {
val current = os.proc("git", "describe", "--tags", "--match", "v*")
.call(cwd = T.workspace)
.out.trim()
os.proc("git", "tag", "-l")
.call(cwd = T.workspace)
.out.lines()
.filter(_ != current)
.filter(_.startsWith("v"))
.filter(!_.contains("-"))
.map(_.stripPrefix("v"))
.filter(!_.startsWith("0.0."))
.filter(!_.startsWith("0.1."))
.filter(!_.startsWith("0.2."))
.map(coursier.core.Version(_))
.sorted
.map(_.repr)
}
// Remove once 0.3.0 is out
def mimaPreviousArtifacts = T {
val versions = mimaPreviousVersions()
val organization = pomSettings().organization
val artifactId0 = artifactId()
Agg.from(
versions.map(version => ivy"$organization:$artifactId0:$version")
)
}
}
private def scalaDirNames(sv: String): Seq[String] = {
val split = sv.split('.')
val major = split.head
val sbv = split.take(2).mkString(".")
Seq("scala", s"scala-$major", s"scala-$sbv", s"scala-$sv")
}
trait Dependency extends CrossSbtModule with DependencyPublishModule {
def sources = T.sources {
super.sources() ++ scalaDirNames(scalaVersion()).map(T.workspace / "dependency" / "shared" / "src" / "main" / _).map(PathRef(_))
}
def compileIvyDeps = T{
val sv = scalaVersion()
if (sv.startsWith("2.")) Agg(Deps.scalaReflect(sv))
else Agg.empty[Dep]
}
def scalacOptions = super.scalacOptions() ++ Seq("-release", "8")
}
trait DependencyJvm extends Dependency with DependencyMima {
def artifactName = "dependency"
object test extends CrossSbtTests with TestModule.Munit {
def sources = T.sources {
super.sources() ++ scalaDirNames(scalaVersion()).map(T.workspace / "dependency" / "shared" / "src" / "test" / _).map(PathRef(_))
}
def ivyDeps = Agg(
Deps.expecty,
Deps.munit,
Deps.pprint
)
}
}
trait DependencyJs extends Dependency with ScalaJSModule {
def artifactName = "dependency"
def scalaJSVersion = Versions.scalaJs
object test extends CrossSbtTests with ScalaJSTests with TestModule.Munit {
def sources = T.sources {
super.sources() ++ scalaDirNames(scalaVersion()).map(T.workspace / "dependency" / "shared" / "src" / "test" / _).map(PathRef(_))
}
def ivyDeps = Agg(
Deps.expecty,
Deps.munit,
Deps.pprint
)
}
}
trait DependencyNative extends Dependency with ScalaNativeModule {
def artifactName = "dependency"
def scalaNativeVersion = Versions.scalaNative
object test extends CrossSbtTests with ScalaNativeTests with TestModule.Munit {
def sources = T.sources {
super.sources() ++ scalaDirNames(scalaVersion()).map(T.workspace / "dependency" / "shared" / "src" / "test" / _).map(PathRef(_))
}
def ivyDeps = Agg(
Deps.expecty,
Deps.munit,
Deps.pprint
)
}
}
trait DependencyInterface extends CrossSbtModule with DependencyPublishModule {
def moduleDeps = super.moduleDeps ++ Seq(
dependency.jvm()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.interface
)
def scalacOptions = super.scalacOptions() ++ Seq("-release", "8")
object test extends CrossSbtTests with TestModule.Munit {
def ivyDeps = Agg(
Deps.expecty,
Deps.munit
)
}
}
def readme = T.sources {
Seq(PathRef(T.workspace / "README.md"))
}
private def mdocScalaVersion = Scala.scala213
def mdoc(args: String*) = T.command {
val readme0 = readme().head.path
val dest = T.dest / "README.md"
val cp = (dependency.jvm(mdocScalaVersion).runClasspath() :+ dependency.jvm(mdocScalaVersion).jar())
.map(_.path)
.filter(os.exists(_))
.filter(!os.isDir(_))
val cmd = Seq("cs", "launch", s"mdoc:${Versions.mdoc}", "--scala", mdocScalaVersion)
val mdocArgs = Seq(
"--in", readme0.toString,
"--out", dest.toString,
"--classpath", cp.mkString(File.pathSeparator)
)
os.proc(cmd, "--", mdocArgs, args).call(
cwd = T.workspace,
stdin = os.Inherit,
stdout = os.Inherit,
stderr = os.Inherit
)
}
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) =
T.command {
import scala.concurrent.duration._
val data = T.sequence(tasks.value)()
val log = T.ctx().log
val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
val pgpPassword = sys.env("PGP_PASSPHRASE")
val timeout = 10.minutes
val artifacts = data.map {
case PublishModule.PublishData(a, s) =>
(s.map { case (p, f) => (p.path, f) }, a)
}
val isRelease = {
val versions = artifacts.map(_._2.version).toSet
val set = versions.map(!_.endsWith("-SNAPSHOT"))
assert(
set.size == 1,
s"Found both snapshot and non-snapshot versions: ${versions.toVector.sorted.mkString(", ")}",
)
set.head
}
val publisher = new scalalib.publish.SonatypePublisher(
uri = "https://oss.sonatype.org/service/local",
snapshotUri = "https://oss.sonatype.org/content/repositories/snapshots",
credentials = credentials,
signed = true,
gpgArgs = Seq(
"--detach-sign",
"--batch=true",
"--yes",
"--pinentry-mode",
"loopback",
"--passphrase",
pgpPassword,
"--armor",
"--use-agent",
),
readTimeout = timeout.toMillis.toInt,
connectTimeout = timeout.toMillis.toInt,
log = log,
workspace = T.workspace,
env = Map.empty,
awaitTimeout = timeout.toMillis.toInt,
stagingRelease = isRelease,
)
publisher.publishAll(isRelease, artifacts: _*)
}