summaryrefslogtreecommitdiff
path: root/build.sc
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-08-12 22:18:39 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-08-12 22:18:39 +0800
commitfd9c399db8c1c0d86cc65d5e1c41968b42a813d1 (patch)
tree8e8fc2875cb1c26f309384a9ca0ad72e1fa893f3 /build.sc
parent9bf8c31fa9321558d7d02f6a5b687cd55a924e7f (diff)
downloadcask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.tar.gz
cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.tar.bz2
cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.zip
auto-upload examples
Diffstat (limited to 'build.sc')
-rw-r--r--build.sc129
1 files changed, 123 insertions, 6 deletions
diff --git a/build.sc b/build.sc
index 2fd3976..f1fa42f 100644
--- a/build.sc
+++ b/build.sc
@@ -1,4 +1,22 @@
import mill._, scalalib._
+import ammonite.ops._, ujson.Js
+import $file.upload
+import $file.example.compress.build
+import $file.example.compress2.build
+import $file.example.compress3.build
+import $file.example.cookies.build
+import $file.example.decorated.build
+import $file.example.decorated2.build
+import $file.example.formJsonPost.build
+import $file.example.httpMethods.build
+import $file.example.minimalApplication.build
+import $file.example.minimalApplication2.build
+import $file.example.redirectAbort.build
+import $file.example.staticFiles.build
+import $file.example.todo.build
+import $file.example.todoApi.build
+import $file.example.todoDb.build
+import $file.example.variableRoutes.build
object cask extends ScalaModule{
def scalaVersion = "2.12.6"
@@ -26,12 +44,111 @@ object cask extends ScalaModule{
}
}
object example extends Module{
- object todo extends ScalaModule{
- def scalaVersion = "2.12.6"
+ trait LocalModule extends ScalaModule{
+ def ivyDeps = super.ivyDeps().filter(_ != ivy"com.lihaoyi::cask:0.0.1")
+
+ override def millSourcePath = super.millSourcePath / "app"
def moduleDeps = Seq(cask)
- def ivyDeps = Agg(
- ivy"org.xerial:sqlite-jdbc:3.18.0",
- ivy"io.getquill::quill-jdbc:2.5.4"
+ }
+ object compress extends $file.example.compress.build.AppModule with LocalModule
+ object compress2 extends $file.example.compress2.build.AppModule with LocalModule
+ object compress3 extends $file.example.compress3.build.AppModule with LocalModule
+ object cookies extends $file.example.cookies.build.AppModule with LocalModule
+ object decorated extends $file.example.decorated.build.AppModule with LocalModule
+ object decorated2 extends $file.example.decorated2.build.AppModule with LocalModule
+ object formJsonPost extends $file.example.formJsonPost.build.AppModule with LocalModule
+ object httpMethods extends $file.example.httpMethods.build.AppModule with LocalModule
+ object minimalApplication extends $file.example.minimalApplication.build.AppModule with LocalModule
+ object minimalApplication2 extends $file.example.minimalApplication2.build.AppModule with LocalModule
+ object redirectAbort extends $file.example.redirectAbort.build.AppModule with LocalModule
+ object staticFiles extends $file.example.staticFiles.build.AppModule with LocalModule
+ object todo extends $file.example.todo.build.AppModule with LocalModule
+ object todoApi extends $file.example.todoApi.build.AppModule with LocalModule
+ object todoDb extends $file.example.todoDb.build.AppModule with LocalModule
+ object variableRoutes extends $file.example.variableRoutes.build.AppModule with LocalModule
+}
+
+val isMasterCommit = {
+ sys.env.get("TRAVIS_PULL_REQUEST") == Some("false") &&
+ (sys.env.get("TRAVIS_BRANCH") == Some("master") || sys.env("TRAVIS_TAG") != "")
+}
+
+def gitHead = T.input{
+ sys.env.get("TRAVIS_COMMIT").getOrElse(
+ %%('git, "rev-parse", "HEAD")(pwd).out.string.trim()
+ )
+}
+
+
+def publishVersion = T.input{
+ val tag =
+ try Option(
+ %%('git, 'describe, "--exact-match", "--tags", "--always", gitHead())(pwd).out.string.trim()
)
+ catch{case e => None}
+
+ val dirtySuffix = %%('git, 'diff)(pwd).out.string.trim() match{
+ case "" => ""
+ case s => "-DIRTY" + Integer.toHexString(s.hashCode)
}
-} \ No newline at end of file
+
+ tag match{
+ case Some(t) => (t, t)
+ case None =>
+ val latestTaggedVersion = %%('git, 'describe, "--abbrev=0", "--always", "--tags")(pwd).out.trim
+
+ val commitsSinceLastTag =
+ %%('git, "rev-list", gitHead(), "--not", latestTaggedVersion, "--count")(pwd).out.trim.toInt
+
+ (latestTaggedVersion, s"$latestTaggedVersion-$commitsSinceLastTag-${gitHead().take(6)}$dirtySuffix")
+ }
+}
+
+def uploadToGithub(authKey: String) = T.command{
+ val (releaseTag, label) = publishVersion()
+
+ if (releaseTag == label){
+ scalaj.http.Http("https://api.github.com/repos/lihaoyi/cask/releases")
+ .postData(
+ ujson.write(
+ Js.Obj(
+ "tag_name" -> releaseTag,
+ "name" -> releaseTag
+ )
+ )
+ )
+ .header("Authorization", "token " + authKey)
+ .asString
+ }
+
+ val examples = Seq(
+ $file.example.compress.build.millSourcePath,
+ $file.example.compress2.build.millSourcePath,
+ $file.example.compress3.build.millSourcePath,
+ $file.example.cookies.build.millSourcePath,
+ $file.example.decorated.build.millSourcePath,
+ $file.example.decorated2.build.millSourcePath,
+ $file.example.formJsonPost.build.millSourcePath,
+ $file.example.httpMethods.build.millSourcePath,
+ $file.example.minimalApplication.build.millSourcePath,
+ $file.example.minimalApplication2.build.millSourcePath,
+ $file.example.redirectAbort.build.millSourcePath,
+ $file.example.staticFiles.build.millSourcePath,
+ $file.example.todo.build.millSourcePath,
+ $file.example.todoApi.build.millSourcePath,
+ $file.example.todoDb.build.millSourcePath,
+ $file.example.variableRoutes.build.millSourcePath,
+ )
+ for(example <- examples){
+ val f = tmp.dir()
+ cp(example, f/'folder)
+ write.over(
+ f/'folder/"build.sc",
+ read(f/'folder/"build.sc").replace("trait AppModule ", "object app ")
+ )
+
+ %%("zip", "-r", f/"out.zip", f/'folder)(T.ctx().dest)
+ upload.apply(f/"out.zip", releaseTag, label + "/" + example.last, authKey)
+ }
+}
+