-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
203 lines (187 loc) · 6.29 KB
/
build.sbt
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
import sbtrelease._
import ReleaseStateTransformations._
import sbtcrossproject.CrossProject
import scala.sys.process.Process
val isScala3 = Def.setting(
CrossVersion.partialVersion(scalaVersion.value).exists(_._1 == 3)
)
def Scala212 = "2.12.20"
def gitHash(): String = Process("git rev-parse HEAD").lineStream_!.head
val tagName = Def.setting{
s"v${if (releaseUseGlobalVersion.value) (ThisBuild / version).value else version.value}"
}
val tagOrHash = Def.setting{
if(isSnapshot.value) gitHash() else tagName.value
}
def releaseStepAggregateCross[A](key: TaskKey[A]): ReleaseStep = ReleaseStep(
action = { state =>
val extracted = Project extract state
extracted.runAggregated(extracted.get(thisProjectRef) / (Global / key), state)
},
enableCrossBuild = true
)
val sonatypeURL = "https://oss.sonatype.org/service/local/repositories/"
val projectName = "applybuilder"
val updateReadme = { state: State =>
val extracted = Project.extract(state)
val scalaV = "2.13"
val v = extracted get version
val org = extracted get organization
val modules = projectName :: Nil
val snapshotOrRelease = if(extracted get isSnapshot) "snapshots" else "releases"
val readme = "README.md"
val readmeFile = file(readme)
val newReadme = Predef.augmentString(IO.read(readmeFile)).lines.map{ line =>
val matchReleaseOrSnapshot = line.contains("SNAPSHOT") == v.contains("SNAPSHOT")
val i = modules.indexWhere(line.contains)
if(line.startsWith("libraryDependencies") && matchReleaseOrSnapshot){
s"""libraryDependencies += "${org}" %% "${modules(i)}" % "$v""""
}else if(line.contains(sonatypeURL) && matchReleaseOrSnapshot){
val n = modules(i)
s"- [API Documentation](${sonatypeURL}${snapshotOrRelease}/archive/${org.replace('.','/')}/${n}_${scalaV}/${v}/${n}_${scalaV}-${v}-javadoc.jar/!/index.html)"
}else line
}.mkString("", "\n", "\n")
IO.write(readmeFile, newReadme)
val git = new Git(extracted get baseDirectory)
git.add(readme) ! state.log
git.commit(message = "update " + readme, sign = false, signOff = false) ! state.log
Process("git diff HEAD^") ! state.log
state
}
val updateReadmeProcess: ReleaseStep = updateReadme
val unusedWarnings = (
"-Ywarn-unused" ::
Nil
)
val commonSettings = Def.settings(
publishTo := sonatypePublishToBundle.value,
name := projectName,
sourcesInBase := false,
fullResolvers ~= {_.filterNot(_.name == "jcenter")},
credentials ++= ((sys.env.get("SONATYPE_USER"), sys.env.get("SONATYPE_PASS")) match {
case (Some(user), Some(pass)) =>
Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", user, pass) :: Nil
case _ =>
Nil
}),
commands += Command.command("updateReadme")(updateReadme),
releaseTagName := tagName.value,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
updateReadmeProcess,
tagRelease,
releaseStepAggregateCross(PgpKeys.publishSigned),
releaseStepCommandAndRemaining("+ applybuilderNative/publishSigned"),
releaseStepCommandAndRemaining("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
updateReadmeProcess,
pushChanges
),
scalaVersion := Scala212,
crossScalaVersions := Scala212 :: "2.13.16" :: "3.3.4" :: Nil,
organization := "com.github.xuwei-k",
startYear := Some(2014),
description := "scalaz.Apply builder",
(Compile / doc / scalacOptions) ++= {
val tag = tagOrHash.value
if (isScala3.value) {
Nil
} else {
Seq(
"-sourcepath", baseDirectory.value.getAbsolutePath,
"-doc-source-url", s"https://github.com/xuwei-k/applybuilder/tree/${tag}€{FILE_PATH}.scala"
)
}
},
Test / logBuffered := false,
pomExtra := (
<url>https://github.com/xuwei-k/applybuilder</url>
<developers>
<developer>
<id>xuwei-k</id>
<name>Kenji Yoshida</name>
<url>https://github.com/xuwei-k</url>
</developer>
</developers>
<scm>
<url>git@github.com:xuwei-k/applybuilder.git</url>
<connection>scm:git:git@github.com:xuwei-k/applybuilder.git</connection>
<tag>{tagOrHash.value}</tag>
</scm>
),
licenses := Seq("MIT" -> url("https://opensource.org/license/MIT")),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 12 =>
Seq(
"-Ypartial-unification"
)
case _ =>
Nil
}
},
scalacOptions ++= (
"-deprecation" ::
"-Xlint" ::
"-unchecked" ::
"-language:existentials" ::
"-language:higherKinds" ::
"-language:implicitConversions" ::
Nil
) ++ PartialFunction.condOpt(CrossVersion.partialVersion(scalaVersion.value)){
case Some((2, v)) if v >= 11 => unusedWarnings
}.toList.flatten,
Seq(Compile, Test).flatMap(c =>
c / console / scalacOptions ~= {_.filterNot(unusedWarnings.toSet)}
)
)
val scalazVersion = SettingKey[String]("scalazVersion")
val applybuilder = CrossProject(
id = projectName,
base = file(".")
)(
JSPlatform, JVMPlatform, NativePlatform
).crossType(
CustomCrossType
).settings(
commonSettings,
scalazVersion := "7.3.8",
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v"),
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % "test",
libraryDependencies += "org.scalaz" %%% "scalaz-core" % scalazVersion.value
).jsSettings(
scalacOptions += {
val a = (LocalRootProject / baseDirectory).value.toURI.toString
val g = "https://raw.githubusercontent.com/xuwei-k/applybuilder/" + tagOrHash.value
val key = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
"-scalajs-mapSourceURI"
case _ =>
"-P:scalajs:mapSourceURI"
}
s"${key}:$a->$g/"
}
)
val applybuilderJVM = applybuilder.jvm
val applybuilderJS = applybuilder.js.enablePlugins(ScalaJSJUnitPlugin)
val applybuilderNative = applybuilder.native.enablePlugins(ScalaNativeJUnitPlugin)
val root = Project(
"root", file(".")
).settings(
commonSettings,
Compile / scalaSource := baseDirectory.value / "dummy",
Test / scalaSource := baseDirectory.value / "dummy",
PgpKeys.publishSigned := {},
PgpKeys.publishLocalSigned := {},
publishLocal := {},
Compile / publishArtifact := false,
publish := {}
).aggregate(
applybuilderJVM, applybuilderJS
)