-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
128 lines (108 loc) · 3.63 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
import sbtrelease.ReleaseStateTransformations._
ThisBuild / onChangedBuildSource := ReloadOnSourceChanges
organization := "com.github.xuwei-k"
name := "sbt-jshell"
sbtPlugin := true
crossScalaVersions += "3.3.4"
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" =>
sbtVersion.value
case _ =>
"2.0.0-M2"
}
}
sbtPluginPublishLegacyMavenStyle := {
sys.env.isDefinedAt("GITHUB_ACTION") || isSnapshot.value
}
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions"
)
val tagName = Def.setting {
s"v${if (releaseUseGlobalVersion.value) (ThisBuild / version).value else version.value}"
}
val tagOrHash = Def.setting {
if (isSnapshot.value) sys.process.Process("git rev-parse HEAD").lineStream_!.head
else tagName.value
}
(Compile / doc / scalacOptions) ++= {
Seq(
"-sourcepath",
baseDirectory.value.getAbsolutePath,
"-doc-source-url",
s"https://github.com/xuwei-k/sbt-jshell/tree/${tagOrHash.value}€{FILE_PATH}.scala"
)
}
pomExtra := (
<url>https://github.com/xuwei-k/sbt-jshell</url>
<developers>
<developer>
<id>xuwei-k</id>
<name>Kenji Yoshida</name>
<url>https://github.com/xuwei-k</url>
</developer>
</developers>
<scm>
<url>[email protected]:xuwei-k/sbt-jshell.git</url>
<connection>scm:git:[email protected]:xuwei-k/sbt-jshell.git</connection>
<tag>{tagOrHash.value}</tag>
</scm>
)
licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT"))
releaseTagName := tagName.value
val updateReadme: State => State = { state: State =>
val sonatypeURL = "https://oss.sonatype.org/service/local/repositories/"
val extracted = Project.extract(state)
val scalaV = extracted get scalaBinaryVersion
val sbtV = extracted get sbtBinaryVersion
val v = extracted get version
val org = extracted get organization
val n = extracted get name
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")
if (line.startsWith("addSbtPlugin") && matchReleaseOrSnapshot) {
s"""addSbtPlugin("${org}" % "${n}" % "$v")"""
} else if (line.contains(sonatypeURL) && matchReleaseOrSnapshot) {
s"- [API Documentation](${sonatypeURL}${snapshotOrRelease}/archive/${org.replace('.', '/')}/${n}_${scalaV}_${sbtV}/${v}/${n}-${v}-javadoc.jar/!/sbtjshell/index.html)"
} else line
}
.mkString("", "\n", "\n")
IO.write(readmeFile, newReadme)
val git = new sbtrelease.Git(extracted get baseDirectory)
git.add(readme) ! state.log
git.commit(message = "update " + readme, sign = false, signOff = false) ! state.log
sys.process.Process(Seq("git", "diff", "HEAD^")).!
state
}
commands += Command.command("updateReadme")(updateReadme)
val updateReadmeProcess: ReleaseStep = updateReadme
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
updateReadmeProcess,
tagRelease,
releaseStepCommandAndRemaining("set ThisBuild / useSuperShell := false"),
releaseStepCommandAndRemaining("+ publishSigned"),
releaseStepCommandAndRemaining("set ThisBuild / useSuperShell := true"),
releaseStepCommandAndRemaining("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
updateReadmeProcess,
pushChanges,
)
publishTo := sonatypePublishToBundle.value
enablePlugins(JShellPlugin)