diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 427f5c72f8..36870d4991 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -67,6 +67,10 @@ jobs: release_name: ${{ github.ref }} body: draft: false + - name: Publish Example Zips + run: ./mill uploadToGithub $GITHUB_ACCESS_TOKEN + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token generate_docs: if: github.repository == 'com-lihaoyi/cask' && contains(github.ref, 'refs/tags/') diff --git a/build.sc b/build.sc index 4fd1ce6cdf..d064fdb3d1 100644 --- a/build.sc +++ b/build.sc @@ -24,6 +24,8 @@ import $file.example.websockets.build import $file.example.websockets2.build import $file.example.websockets3.build import $file.example.websockets4.build +import $file.ci.version +import $file.ci.upload import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version_mill0.9:0.1.1` import de.tobiasroeser.mill.vcs.version.VcsVersion @@ -191,3 +193,76 @@ object example extends Module{ object websockets4 extends Cross[Websockets4Module](allVersions: _*) } + + +def publishVersion = T.input($file.ci.version.publishVersion) +def gitHead = T.input($file.ci.version.gitHead) + +def uploadToGithub(authKey: String) = T.command{ + val (releaseTag, label) = publishVersion() + + if (releaseTag == label){ + requests.post( + "https://api.github.com/repos/lihaoyi/cask/releases", + data = ujson.write( + ujson.Obj( + "tag_name" -> releaseTag, + "name" -> releaseTag + ) + ), + headers = Seq("Authorization" -> s"token $authKey") + ) + } + + 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.endpoints.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.scalatags.build.millSourcePath, + $file.example.staticFiles.build.millSourcePath, + $file.example.staticFiles2.build.millSourcePath, + $file.example.todo.build.millSourcePath, + $file.example.todoApi.build.millSourcePath, + $file.example.todoDb.build.millSourcePath, + $file.example.twirl.build.millSourcePath, + $file.example.variableRoutes.build.millSourcePath, + $file.example.websockets.build.millSourcePath, + $file.example.websockets2.build.millSourcePath, + $file.example.websockets3.build.millSourcePath, + $file.example.websockets4.build.millSourcePath, + ) + for(example <- examples){ + val f = T.ctx().dest + val last = example.last + "-" + label + os.copy(example, f / last) + os.write.over( + f / last / "mill", + os.read(os.pwd / "mill") + ) + os.proc("chmod", "+x", f/last/"mill").call(f/last) + os.write.over( + f / last / "build.sc", + os.read(f / last / "build.sc") + .replaceFirst( + "trait AppModule extends CrossScalaModule\\s*\\{", + "object app extends ScalaModule \\{\n def scalaVersion = \"2.13.5\"") + .replaceFirst( + "def ivyDeps = Agg\\[Dep\\]\\(", + "def ivyDeps = Agg(\n ivy\"com.lihaoyi::cask:" + releaseTag + "\"," + ) + ) + + os.remove.all(f / "out.zip") + os.proc("zip", "-r", f / "out.zip", last).call(f) + upload.apply(f / "out.zip", releaseTag, last + ".zip", authKey) + } +} diff --git a/ci/upload.sc b/ci/upload.sc new file mode 100644 index 0000000000..783f76802c --- /dev/null +++ b/ci/upload.sc @@ -0,0 +1,56 @@ +#!/usr/bin/env amm +import ammonite.ops._ + +@main +def shorten(longUrl: String) = { + println("shorten longUrl " + longUrl) + val shortUrl = requests.post( + "https://git.io", + data = Seq("url" -> longUrl), + ).headers("location").head + + println("shorten shortUrl " + shortUrl) + shortUrl +} +@main +def apply(uploadedFile: Path, + tagName: String, + uploadName: String, + authKey: String): String = { + val body = requests.get( + s"https://api.github.com/repos/lihaoyi/cask/releases/tags/$tagName", + headers = Seq("Authorization" -> s"token $authKey") + ).text + + val parsed = ujson.read(body) + + println(body) + + val snapshotReleaseId = parsed("id").num.toInt + + + val uploadUrl = + s"https://uploads.github.com/repos/lihaoyi/cask/releases/" + + s"$snapshotReleaseId/assets?name=$uploadName" + + val res = requests.post( + uploadUrl, + data = read.bytes! uploadedFile, + headers = Seq( + "Content-Type" -> "application/octet-stream", + "Authorization" -> s"token $authKey" + ), + connectTimeout = 5000, readTimeout = 60000 + ) + + + println(res.text) + val longUrl = ujson.read(res.text)("browser_download_url").str.toString + + println("Long Url " + longUrl) + + val shortUrl = shorten(longUrl) + + println("Short Url " + shortUrl) + shortUrl +} diff --git a/readme.md b/readme.md index 4ecf65eca3..1ef4ef7bc0 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -Cask: a Scala HTTP micro-framework [![Build Status][travis-badge]][travis-link] [![Gitter Chat][gitter-badge]][gitter-link] [![Patreon][patreon-badge]][patreon-link] +Cask 0.7.15: a Scala HTTP micro-framework [![Build Status][travis-badge]][travis-link] [![Gitter Chat][gitter-badge]][gitter-link] [![Patreon][patreon-badge]][patreon-link] ===================================================================================================================================================================== [travis-badge]: https://travis-ci.org/lihaoyi/cask.svg @@ -46,6 +46,10 @@ courtesy of EJ Technologies ## Changelog +### 0.7.15 + +- Fix example project zips + ### 0.7.14 - Update Castor to 0.1.8