summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-04 02:41:00 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-04 02:41:00 -0800
commita5fb5d0ea8a0d7c1322ec95e7452c1a6160166a9 (patch)
tree6dfa056e28e7bc4b0b637ec28df6eb16eced32cd
parentf7a46fe9fb756803e3fdd81f427a7fd42001e71e (diff)
downloadmill-a5fb5d0ea8a0d7c1322ec95e7452c1a6160166a9.tar.gz
mill-a5fb5d0ea8a0d7c1322ec95e7452c1a6160166a9.tar.bz2
mill-a5fb5d0ea8a0d7c1322ec95e7452c1a6160166a9.zip
wip auto publishing...
-rwxr-xr-xbuild.sc54
-rwxr-xr-xci/release.sh5
-rw-r--r--core/src/mill/define/Ctx.scala2
-rw-r--r--core/src/mill/main/Resolve.scala3
-rw-r--r--scalalib/src/mill/scalalib/PublishModule.scala4
-rw-r--r--upload.sc52
6 files changed, 113 insertions, 7 deletions
diff --git a/build.sc b/build.sc
index e6c45175..819b8dd6 100755
--- a/build.sc
+++ b/build.sc
@@ -1,4 +1,5 @@
import $file.shared
+import $file.upload
import java.io.File
import ammonite.ops._
@@ -6,10 +7,10 @@ import coursier.maven.MavenRepository
import mill._
import mill.scalalib._, publish._
import mill.modules.Jvm.createAssembly
-
+import upickle.Js
trait MillPublishModule extends PublishModule{
def scalaVersion = "2.12.4"
- def publishVersion = "0.0.1"
+ def publishVersion = build.publishVersion()._2
def artifactName = "mill-" + super.artifactName()
def pomSettings = PomSettings(
description = artifactName(),
@@ -199,4 +200,53 @@ def releaseAssembly = T{
assemblyBase(Agg.from(assemblyClasspath().flatten.map(_.path)), "")
}
+val isMasterCommit = {
+ sys.env.get("TRAVIS_PULL_REQUEST") == Some("false") &&
+ (sys.env.get("TRAVIS_BRANCH") == Some("master") || sys.env("TRAVIS_TAG") != "")
+}
+
+def publishVersion = T.input{
+ val tag =
+ try Option(%%('git, 'describe, "--exact-match", "--tags", 'HEAD)(pwd).out.string)
+ catch{case e => None}
+
+ tag match{
+ case Some(t) => (t, t)
+ case None =>
+ val timestamp = java.time.Instant.now().toString.replaceAll(":|\\.", "-")
+ val gitHash = %%('git, "rev-parse", "head")(pwd).out.string.trim()
+ ("unstable", timestamp + "-" + gitHash)
+ }
+}
+
+def uploadToGithub(assembly: Path, authKey: String, release: String, label: String) = {
+ if (release == "unstable"){
+ scalaj.http.Http("https://api.github.com/repos/lihaoyi/mill/releases")
+ .postData(
+ upickle.json.write(
+ Js.Obj(
+ "tag_name" -> Js.Str(release),
+ "name" -> Js.Str(release)
+ )
+ )
+ )
+ .header("Authorization", "token " + authKey)
+ .asString
+
+
+ upload.apply(assembly, release, label, authKey)
+ }
+}
+
+def releaseCI(githubAuthKey: String, sonatypeCreds: String, gpgPassphrase: String) =
+ if (isMasterCommit) T.command()
+ else T.command{
+ scalaworker.publish(sonatypeCreds, gpgPassphrase)()
+ scalajslib.jsbridges("0.6").publish(sonatypeCreds, gpgPassphrase)()
+ scalajslib.jsbridges("1.0").publish(sonatypeCreds, gpgPassphrase)()
+ val (release, label) = publishVersion()
+ uploadToGithub(releaseAssembly().path, githubAuthKey, release, label)
+ ()
+ }
+
def idea() = T.command{ mill.scalalib.GenIdea() }
diff --git a/ci/release.sh b/ci/release.sh
index 29b4e688..892e8e49 100755
--- a/ci/release.sh
+++ b/ci/release.sh
@@ -2,4 +2,7 @@
set -eux
-sbt bin/test:assembly \ No newline at end of file
+echo $GPG_PRIVATE_KEY_B64 | base64 --decode > ~/gpg.key
+gpg import ~/gpg.key
+
+target/bin/mill releaseCI $GITHUB_ACCESS_TOKEN lihaoyi:$SONATYPE_PASSWORD $GPG_PASSWORD
diff --git a/core/src/mill/define/Ctx.scala b/core/src/mill/define/Ctx.scala
index 405f45ed..47035f71 100644
--- a/core/src/mill/define/Ctx.scala
+++ b/core/src/mill/define/Ctx.scala
@@ -30,7 +30,7 @@ case class BasePath(value: Path)
case class Segments(value: Segment*){
def ++(other: Seq[Segment]): Segments = Segments(value ++ other:_*)
def ++(other: Segments): Segments = Segments(value ++ other.value:_*)
- def render = value match {
+ def render = value.toList match {
case Nil => ""
case Segment.Label(head) :: rest =>
val stringSegments = rest.map{
diff --git a/core/src/mill/main/Resolve.scala b/core/src/mill/main/Resolve.scala
index fa39e81c..f4eeb8fe 100644
--- a/core/src/mill/main/Resolve.scala
+++ b/core/src/mill/main/Resolve.scala
@@ -25,7 +25,8 @@ object Resolve {
.map(Right(_))
def invokeCommand(target: mill.Module, name: String) = for{
- (cls, entryPoints) <- discover.value.filterKeys(_.isAssignableFrom(target.getClass))
+ (cls, entryPoints) <- discover.value
+ if cls.isAssignableFrom(target.getClass)
ep <- entryPoints
if ep._2.name == name
} yield ammonite.main.Scripts.runMainMethod(
diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala
index 58334e41..460defcb 100644
--- a/scalalib/src/mill/scalalib/PublishModule.scala
+++ b/scalalib/src/mill/scalalib/PublishModule.scala
@@ -51,7 +51,7 @@ trait PublishModule extends ScalaModule { outer =>
def sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots"
- def publish(credentials: String, gpgPassphrase: String): define.Command[Unit] = T.command {
+ def publish(sonatypeCreds: String, gpgPassphrase: String): define.Command[Unit] = T.command {
val baseName = s"${artifactId()}-${publishVersion()}"
val artifacts = Seq(
jar().path -> s"${baseName}.jar",
@@ -62,7 +62,7 @@ trait PublishModule extends ScalaModule { outer =>
new SonatypePublisher(
sonatypeUri,
sonatypeSnapshotUri,
- credentials,
+ sonatypeCreds,
gpgPassphrase,
T.ctx().log
).publish(artifacts, artifact())
diff --git a/upload.sc b/upload.sc
new file mode 100644
index 00000000..6013c8d9
--- /dev/null
+++ b/upload.sc
@@ -0,0 +1,52 @@
+#!/usr/bin/env amm
+import ammonite.ops._
+import scalaj.http._
+
+@main
+def shorten(longUrl: String) = {
+ println("shorten longUrl " + longUrl)
+ val shortUrl = Http("https://git.io")
+ .postForm(Seq("url" -> longUrl))
+ .asString
+ .headers("Location")
+ .head
+ println("shorten shortUrl " + shortUrl)
+ shortUrl
+}
+@main
+def apply(uploadedFile: Path,
+ tagName: String,
+ uploadName: String,
+ authKey: String): String = {
+ val body = Http("https://api.github.com/repos/lihaoyi/mill/releases/tags/" + tagName)
+ .header("Authorization", "token " + authKey)
+ .asString.body
+
+ val parsed = upickle.json.read(body)
+
+ println(body)
+
+ val snapshotReleaseId = parsed("id").num.toInt
+
+
+ val uploadUrl =
+ s"https://uploads.github.com/repos/lihaoyi/mill/releases/" +
+ s"$snapshotReleaseId/assets?name=$uploadName"
+
+ val res = Http(uploadUrl)
+ .header("Content-Type", "application/octet-stream")
+ .header("Authorization", "token " + authKey)
+ .timeout(connTimeoutMs = 5000, readTimeoutMs = 60000)
+ .postData(read.bytes! uploadedFile)
+ .asString
+
+ println(res.body)
+ val longUrl = upickle.json.read(res.body)("browser_download_url").str.toString
+
+ println("Long Url " + longUrl)
+
+ val shortUrl = shorten(longUrl)
+
+ println("Short Url " + shortUrl)
+ shortUrl
+} \ No newline at end of file