/
RFReleasePlugin.scala
107 lines (97 loc) · 3.67 KB
/
RFReleasePlugin.scala
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
/*
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright 2019 Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* [http://www.apache.org/licenses/LICENSE-2.0]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
import sbt.Keys._
import sbt._
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
import sbtrelease.ReleasePlugin.autoImport._
import com.typesafe.sbt.sbtghpages.GhpagesPlugin
import com.typesafe.sbt.sbtghpages.GhpagesPlugin.autoImport.ghpagesPushSite
import com.typesafe.sbt.site.SitePlugin
import com.typesafe.sbt.site.SitePlugin.autoImport.makeSite
import scala.sys.process.{Process => SProcess}
/** Release process support. */
object RFReleasePlugin extends AutoPlugin {
override def trigger: PluginTrigger = noTrigger
override def requires = RFProjectPlugin && SitePlugin && GhpagesPlugin
override def projectSettings = {
val buildSite: State ⇒ State = releaseStepTask(makeSite in LocalProject("docs"))
val publishSite: State ⇒ State = releaseStepTask(ghpagesPushSite in LocalProject("docs"))
Seq(
releaseIgnoreUntrackedFiles := true,
releaseTagName := s"${version.value}",
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
checkGitFlowExists,
inquireVersions,
runClean,
runTest,
gitFlowReleaseStart,
setReleaseVersion,
buildSite,
commitReleaseVersion,
tagRelease,
releaseStepCommand("publishSigned"),
releaseStepCommand("sonatypeReleaseAll"),
publishSite,
gitFlowReleaseFinish,
setNextVersion,
commitNextVersion,
remindMeToPush
),
commands += Command.command("bumpVersion"){ st ⇒
val extracted = Project.extract(st)
val ver = extracted.get(version)
val nextFun = extracted.runTask(releaseNextVersion, st)._2
val nextVersion = nextFun(ver)
val file = extracted.get(releaseVersionFile)
IO.writeLines(file, Seq(s"""version in ThisBuild := "$nextVersion""""))
extracted.appendWithSession(Seq(version := nextVersion), st)
}
)
}
def releaseVersion(state: State): String =
state.get(ReleaseKeys.versions).map(_._1).getOrElse {
sys.error("No versions are set! Was this release part executed before inquireVersions?")
}
val gitFlowReleaseStart = ReleaseStep(state ⇒ {
val version = releaseVersion(state)
SProcess(Seq("git", "flow", "release", "start", version)).!
state
})
val gitFlowReleaseFinish = ReleaseStep(state ⇒ {
val version = releaseVersion(state)
SProcess(Seq("git", "flow", "release", "finish", "-n", s"$version")).!
state
})
val remindMeToPush = ReleaseStep(state ⇒ {
state.log.warn("Don't forget to git push master AND develop!")
state
})
val checkGitFlowExists = ReleaseStep(state => {
SProcess(Seq("command", "-v", "git-flow")).!! match {
case "" => sys.error("git-flow is required for release. See https://github.com/nvie/gitflow for installation instructions.")
case _ => SProcess(Seq("git", "flow", "init", "-d")).! match {
case 0 => state
case e => sys.error(s"git-flow init failed with error code $e")
}
}
})
}