forked from sbt/sbt-release
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReleasePlugin.scala
89 lines (72 loc) · 2.78 KB
/
ReleasePlugin.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
package sbtrelease
import sbt._
import Keys._
import complete.DefaultParsers._
object ReleasePlugin extends Plugin {
object ReleaseKeys {
lazy val snapshotDependencies = TaskKey[Seq[ModuleID]]("release-snapshot-dependencies")
lazy val releaseProcess = SettingKey[Seq[ReleasePart]]("release-process")
lazy val releaseVersion = SettingKey[String => String]("release-release-version")
lazy val nextVersion = SettingKey[String => String]("release-next-version")
lazy val tagName = SettingKey[String]("release-tag-name")
lazy val versions = AttributeKey[Versions]("release-versions")
lazy val useDefaults = AttributeKey[Boolean]("release-use-defaults")
lazy val skipTests = AttributeKey[Boolean]("release-skip-tests")
private lazy val releaseCommandKey = "release"
private val WithDefaults = "with-defaults"
private val SkipTests = "skip-tests"
private val releaseParser = (Space ~> WithDefaults | Space ~> SkipTests).*
val releaseCommand: Command = Command(releaseCommandKey)(_ => releaseParser) { (st, args) =>
val extracted = Project.extract(st)
val process = extracted.get(releaseProcess)
val startState = st
.put(useDefaults, args.contains(WithDefaults))
.put(skipTests, args.contains(SkipTests))
Function.chain(process)(startState)
}
}
import ReleaseKeys._
lazy val releaseSettings = Seq[Setting[_]](
snapshotDependencies <<= (managedClasspath in Runtime) map { cp: Classpath =>
val moduleIds = cp.flatMap(_.get(moduleID.key))
val snapshots = moduleIds.filter(m => m.isChanging || m.revision.endsWith("-SNAPSHOT"))
snapshots
},
releaseVersion := { ver => Version(ver).map(_.withoutQualifier.string).getOrElse(versionFormatError) },
nextVersion := { ver => Version(ver).map(_.bumpMinor.asSnapshot.string).getOrElse(versionFormatError) },
tagName <<= (version in ThisBuild) (v => "v" + v),
releaseProcess <<= thisProjectRef apply { ref =>
import ReleaseStateTransformations._
Seq[ReleasePart](
initialGitChecks,
checkSnapshotDependencies,
inquireVersions,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseTask(publish in Global in ref),
setNextVersion,
commitNextVersion,
pushChanges
)
},
commands += releaseCommand
)
lazy val extraReleaseCommands = {
import ExtraReleaseCommands._
Seq[Setting[_]](
commands ++= Seq(
checkSnapshotDependenciesCommand,
inquireVersionsCommand,
setReleaseVersionCommand,
setNextVersionCommand,
initialGitChecksCommand,
commitReleaseVersionCommand,
commitNextVersionCommand,
tagReleaseCommand,
pushChangesCommand
)
)
}
}