Skip to content

Commit

Permalink
0.7.15
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Nov 15, 2021
1 parent d1c59fd commit a63c734
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down
75 changes: 75 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}
56 changes: 56 additions & 0 deletions ci/upload.sc
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a63c734

Please sign in to comment.