-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sc
141 lines (127 loc) · 4.08 KB
/
build.sc
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
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1`
import $ivy.`io.github.alexarchambault.mill::mill-native-image::0.1.29`
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.24`
import de.tobiasroeser.mill.vcs.version._
import io.github.alexarchambault.millnativeimage.NativeImage
import io.github.alexarchambault.millnativeimage.upload.Upload
import mill._
import mill.scalalib._
import scala.util.Properties
def scalaDefaultVersion = "2.13.15"
def coursierVersion = "2.1.23"
def graalVmVersion = "22.1.0"
def utestVersion = "0.8.4"
object `cs-m1` extends JavaModule with NativeImage {
def ivyDeps = super.ivyDeps() ++ Seq(
ivy"io.get-coursier:coursier-cli_2.13:$coursierVersion"
)
def nativeImageGraalVmJvmId = T {
sys.env.getOrElse("GRAALVM_ID", s"graalvm-java17:$graalVmVersion")
}
def nativeImageClassPath = runClasspath()
def nativeImageMainClass = "coursier.cli.Coursier"
def nativeImagePersist = System.getenv("CI") != null
def nativeImageOptions = T {
if (Properties.isLinux)
Seq(
// required on the Linux / ARM64 CI in particular (not sure why)
"-Djdk.lang.Process.launchMechanism=vfork", // https://mbien.dev/blog/entry/custom-java-runtimes-with-jlink
"-H:PageSize=65536" // Make sure binary runs on kernels with page size set to 4k, 16 and 64k
)
else
Nil
}
def copyToArtifacts(directory: String = "artifacts/") = T.command {
val _ = Upload.copyLauncher(
nativeImage().path,
directory,
"cs",
compress = true,
suffix = ""
)
}
}
object `cs-m1-tests` extends ScalaModule {
def scalaVersion = scalaDefaultVersion
def ivyDeps = super.ivyDeps() ++ Seq(
ivy"io.get-coursier:cli-tests_2.13:$coursierVersion"
)
object test extends Tests {
def ivyDeps = super.ivyDeps() ++ Seq(
ivy"com.lihaoyi::utest::$utestVersion"
)
def testFramework = "utest.runner.Framework"
def forkEnv = super.forkEnv() ++ Seq(
"COURSIER_M1_LAUNCHER" -> `cs-m1`.nativeImage().path.toString
)
}
}
object ci extends Module {
def upload(directory: String = "artifacts/") = T.command {
val version = tag()
val path = os.Path(directory, os.pwd)
val launchers = os.list(path).filter(os.isFile(_)).map { path =>
path -> path.last
}
val ghToken = Option(System.getenv("UPLOAD_GH_TOKEN")).getOrElse {
sys.error("UPLOAD_GH_TOKEN not set")
}
val (tag0, overwrite) =
if (version.endsWith("-SNAPSHOT")) ("nightly", true)
else ("v" + version, false)
Upload.upload(
"VirtusLab",
"coursier-m1",
ghToken,
tag0,
dryRun = false,
overwrite = overwrite
)(launchers: _*)
}
private def computePublishVersion(state: VcsState): String =
if (state.commitsSinceLastTag > 0) {
val versionOrEmpty = state.lastTag
.filter(_ != "latest")
.filter(_ != "nightly")
.map(_.stripPrefix("v"))
.flatMap { tag =>
val baseVersion = tag.takeWhile(c => c == '.' || c.isDigit)
if (
baseVersion == tag || tag
.stripPrefix(baseVersion)
.forall(c => c == '-' || c.isDigit)
) {
val idx = baseVersion.lastIndexOf(".")
if (idx >= 0)
Some(
baseVersion.take(idx + 1) + (baseVersion
.drop(idx + 1)
.toInt + 1).toString + "-SNAPSHOT"
)
else
None
}
else
Some(baseVersion + "-SNAPSHOT")
}
.getOrElse("0.0.1-SNAPSHOT")
Some(versionOrEmpty)
.filter(_.nonEmpty)
.getOrElse(state.format())
}
else
state.lastTag
.getOrElse(state.format())
.stripPrefix("v")
def tag = T {
val state = VcsVersion.vcsState()
computePublishVersion(state)
}
}
def copyTo(task: mill.main.Tasks[PathRef], dest: os.Path) = T.command {
if (task.value.length > 1)
sys.error("Expected a single task")
val ref = task.value.head()
os.makeDir.all(dest / os.up)
os.copy.over(ref.path, dest)
}