forked from muuki88/sbt-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TravisSnapshotReleasePlugin.scala
72 lines (63 loc) · 2.57 KB
/
TravisSnapshotReleasePlugin.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
import com.typesafe.sbt.{GitPlugin, GitVersioning, SbtPgp}
import com.typesafe.sbt.SbtGit.git
import com.typesafe.sbt.pgp.PgpKeys.publishSigned
import sbt._
import sbt.Keys._
import sbttravisci.TravisCiPlugin
import sbttravisci.TravisCiPlugin.autoImport._
object TravisSnapshotReleasePlugin extends AutoPlugin {
override def trigger = PluginTrigger.AllRequirements
override def requires = GitVersioning && TravisCiPlugin && SbtPgp && GitPlugin
object autoImport {
val publishViaTravis: TaskKey[Unit] =
taskKey[Unit]("publish via travis CI")
val travisBranch: SettingKey[Option[String]] =
settingKey[Option[String]]("travis git branch")
}
import autoImport._
override def projectSettings: Seq[Setting[_]] = Seq(
travisBranch := sys.env.get("TRAVIS_BRANCH"),
publishViaTravis := Def
.taskDyn[Unit] {
val log = streams.value.log
// Travis sets the branch via an environment variable. Also tags are checked out as branches
val branch = travisBranch.value.getOrElse("<no travis branch>")
val currentTags = List(branch)
val tagToVersionNumber = git.gitTagToVersionNumber.value
val releaseTag = git.releaseVersion(currentTags, tagToVersionNumber, "")
log.info(s"Publish via travis on branch $branch")
log.info(s"Using version ${version.value}")
log.info(s"Release tag $releaseTag")
log.info(s"Sbt-git found branch ${git.gitCurrentBranch.value}")
log.info(s"Sbt-git found tags ${git.gitCurrentTags.value}")
if (!isTravisBuild.value) {
Def.task[Unit] {
log.warn("Not running on travis. Skip publish task")
}
} else if (travisPrNumber.value.isDefined) {
Def.task[Unit] {
log.warn("Building a pull request. Skip publish task")
}
} else if (branch == "snapshot") {
Def
.task[Unit] {
val snapshotVersion = version.value
log.success(s"Pushed to snapshot branch. Publishing $snapshotVersion")
}
.dependsOn(publishSigned)
} else if (releaseTag.isDefined) {
Def
.task[Unit] {
log.success(s"Pushed to master branch. Publishing a release with version ${version.value}")
}
.dependsOn(publishSigned)
} else {
Def.task[Unit] {
log.warn("Skip publishing from travis. No release tag found or not on snapshot branch")
log.warn(s"Branch $branch | Head commit: ${git.gitHeadCommit.value}")
}
}
}
.value
)
}