Skip to content

Commit

Permalink
Fix Github asset upload
Browse files Browse the repository at this point in the history
If seem to fail when shortening the URL.
As I don't know why we need to short url (we don't process it)
I just gracefully continue by returning the long URL.

I did investigated why shortening the URL no longer works.
  • Loading branch information
lefou committed Jan 17, 2022
1 parent 76892d1 commit b328131
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
35 changes: 18 additions & 17 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ object contrib extends MillModule {
"MILL_SCOVERAGE_REPORT_WORKER" -> worker.compile().classes.path,
"MILL_SCALA_2_13_VERSION" -> Deps.scalaVersion,
"MILL_SCALA_2_12_VERSION" -> Deps.workerScalaVersion212,
"MILL_SCOVERAGE_VERSION" -> Deps.scalacScoveragePlugin.dep.version,
"MILL_SCOVERAGE_VERSION" -> Deps.scalacScoveragePlugin.dep.version
)
scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
Expand Down Expand Up @@ -1239,6 +1239,7 @@ def uploadToGithub(authKey: String) = T.command {
))

if (releaseTag == label) {
// TODO: check if the tag already exists (e.g. because we created it manually) and do not fail
scalaj.http.Http(
s"https://api.github.com/repos/${Settings.githubOrg}/${Settings.githubRepo}/releases"
)
Expand All @@ -1254,29 +1255,29 @@ def uploadToGithub(authKey: String) = T.command {
.asString
}

for (example <- Seq("example-1", "example-2", "example-3")) {
os.copy(os.pwd / "example" / example, T.dest / example)
os.copy(launcher().path, T.dest / example / "mill")
os.proc("zip", "-r", T.dest / s"$example.zip", example).call(cwd = T.dest)
val exampleZips = Seq("example-1", "example-2", "example-3")
.map { example =>
os.copy(os.pwd / "example" / example, T.dest / example)
os.copy(launcher().path, T.dest / example / "mill")
os.proc("zip", "-r", T.dest / s"$example.zip", example).call(cwd = T.dest)
(T.dest / s"$example.zip", label + "-" + example + ".zip")
}

val zips = exampleZips ++ Seq(
(assembly().path, label + "-assembly"),
(launcher().path, label)
)

for ((zip, name) <- zips) {
upload.apply(
T.dest / s"$example.zip",
zip,
releaseTag,
label + "-" + example + ".zip",
name,
authKey,
Settings.githubOrg,
Settings.githubRepo
)
}
upload.apply(
assembly().path,
releaseTag,
label + "-assembly",
authKey,
Settings.githubOrg,
Settings.githubRepo
)

upload.apply(launcher().path, releaseTag, label, authKey, Settings.githubOrg, Settings.githubRepo)
}

def validate(ev: Evaluator): Command[Unit] = T.command {
Expand Down
18 changes: 13 additions & 5 deletions ci/upload.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env amm
import scala.util.Try
import scala.util.control.NonFatal

import scalaj.http._

@main
Expand All @@ -24,7 +27,8 @@ def apply(
): String = {

val response = Http(
s"https://api.github.com/repos/${githubOrg}/${githubRepo}/releases/tags/${tagName}")
s"https://api.github.com/repos/${githubOrg}/${githubRepo}/releases/tags/${tagName}"
)
.header("Authorization", "token " + authKey)
.header("Accept", "application/vnd.github.v3+json")
.asString
Expand Down Expand Up @@ -53,8 +57,12 @@ def apply(

println("Long Url " + longUrl)

val shortUrl = shorten(longUrl)

println("Short Url " + shortUrl)
shortUrl
Try {
val shortUrl = shorten(longUrl)
println("Short Url " + shortUrl)
shortUrl
}.toOption.getOrElse {
// could not shorten the url
longUrl
}
}

0 comments on commit b328131

Please sign in to comment.