-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ohnosequences/pr/8
Parametrize release task with the version tag
- Loading branch information
Showing
5 changed files
with
114 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
resolvers += "Era7 maven releases" at "https://s3-eu-west-1.amazonaws.com/releases.era7.com" | ||
|
||
addSbtPlugin("ohnosequences" % "nice-sbt-settings" % "0.8.0-RC2-8-gc3118aa") | ||
|
||
// resolvers += "Era7 maven snapshots" at "https://s3-eu-west-1.amazonaws.com/snapshots.era7.com" | ||
// addSbtPlugin("ohnosequences" % "nice-sbt-settings" % "0.8.0-RC2+") | ||
addSbtPlugin("ohnosequences" % "nice-sbt-settings" % "0.8.0-RC2-10-gf28fae6") | ||
|
||
// addSbtPlugin("ohnosequences" % "sbt-github-release" % "0.1.2-SNAPSHOT") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,57 @@ | ||
package ohnosequences.sbt | ||
|
||
import sbt._, Keys._ | ||
|
||
import sbt._, Keys._, complete._, DefaultParsers._ | ||
import org.kohsuke.github._ | ||
import scala.collection.JavaConversions._ | ||
import scala.util.Try | ||
import GithubRelease._, keys._ | ||
|
||
case object SbtGithubReleasePlugin extends AutoPlugin { | ||
|
||
// This plugin will load automatically | ||
override def trigger = allRequirements | ||
override def requires = empty | ||
|
||
val autoImport = GithubRelease.keys | ||
|
||
import GithubRelease._, keys._ | ||
|
||
// Default settings | ||
override lazy val projectSettings = Seq[Setting[_]]( | ||
ghreleaseNotes := baseDirectory.value / "notes" / (version.value+".markdown"), | ||
ghreleaseNotes := { tagName => | ||
val ver = tagName.stripPrefix("v") | ||
IO.read(baseDirectory.value / "notes" / s"${ver}.markdown") | ||
}, | ||
ghreleaseRepoOrg := organization.value, | ||
ghreleaseRepoName := name.value, | ||
ghreleaseTag := "v"+version.value, | ||
ghreleaseTitle := name.value +" "+ ghreleaseTag.value, | ||
ghreleaseCommitish := "", | ||
ghreleaseTitle := { tagName => s"${name.value} ${tagName}" }, | ||
// According to the Semantic Versioning Specification (rule 9) | ||
// a version containing a hyphen is a pre-release version | ||
ghreleaseIsPrerelease := { _.matches(""".*-.*""") }, | ||
|
||
ghreleaseMediaTypesMap := { | ||
val typeMap = new javax.activation.MimetypesFileTypeMap() | ||
// NOTE: github doesn't know about application/java-archive type (see https://developer.github.com/v3/repos/releases/#input-2) | ||
typeMap.addMimeTypes("application/zip jar zip") | ||
// and .pom is unlikely to be in the system's default MIME types map | ||
typeMap.addMimeTypes("application/xml pom xml") | ||
|
||
typeMap.getContentType | ||
}, | ||
|
||
ghreleaseAssets := packagedArtifacts.value.values.toSeq, | ||
|
||
ghreleaseCheckCredentials := { | ||
val log = streams.value.log | ||
val conf = file(System.getProperty("user.home")) / ".github" | ||
while (!conf.exists || !GitHub.connect.isCredentialValid) { | ||
log.warn("Your github credentials for sbt-github-release plugin are not set yet") | ||
SimpleReader.readLine("Go to https://github.com/settings/applications \ncreate a new token and paste it here: ") match { | ||
case Some(token) => { | ||
try { | ||
val gh = GitHub.connectUsingOAuth(token) | ||
if (gh.isCredentialValid) { | ||
IO.writeLines(conf, Seq("oauth = " + token))//, append = true) | ||
log.info("Wrote OAuth token to " + conf) | ||
} | ||
} catch { | ||
case e: Exception => log.error(e.toString) | ||
} | ||
} | ||
case _ => sys.error("If you want to use sbt-github-release plugin, you should set credentials correctly") | ||
} | ||
} | ||
log.info("Github credentials are ok") | ||
GitHub.connect | ||
}, | ||
|
||
ghreleaseCheckRepo := { | ||
val log = streams.value.log | ||
val github = ghreleaseCheckCredentials.value | ||
val repo = s"${ghreleaseRepoOrg.value}/${ghreleaseRepoName.value}" | ||
ghreleaseIsPrerelease := { _.matches(""".*-.*""") }, | ||
ghreleaseMediaTypesMap := defs.ghreleaseMediaTypesMap, | ||
ghreleaseAssets := packagedArtifacts.value.values.toSeq, | ||
ghreleaseGetCredentials := defs.ghreleaseGetCredentials.value, | ||
ghreleaseGetRepo := defs.ghreleaseGetRepo.value, | ||
|
||
ghreleaseGetReleaseBuilder := Def.inputTaskDyn { | ||
defs.ghreleaseGetReleaseBuilder(tagNameArg.parsed) | ||
}.evaluated, | ||
|
||
githubRelease := Def.inputTaskDyn { | ||
defs.githubRelease(tagNameArg.parsed) | ||
}.evaluated | ||
) | ||
|
||
val repository = Try { github.getRepository(repo) } getOrElse { | ||
sys.error(s"Repository ${repo} doesn't exist or is not accessible.") | ||
} | ||
repository | ||
}, | ||
def tagNameArg: Def.Initialize[Parser[String]] = Def.setting { | ||
val gitOut: Try[String] = Try { | ||
sys.process.Process(Seq("git", "tag", "--list"), baseDirectory.value).!! | ||
} | ||
|
||
// ghreleaseCheckReleaseBuilder := getReleaseBuilder.value, | ||
val suggestions: Try[Parser[String]] = gitOut.map { out => | ||
oneOf( | ||
out.split('\n').map { tag => token(tag.trim) } | ||
) | ||
} | ||
|
||
githubRelease := defs.githubRelease.value | ||
) | ||
val fallback = s"v${version.value}" | ||
|
||
(Space ~> suggestions.getOrElse(StringBasic)) ?? fallback | ||
} | ||
} |