From b3281310b126e590109244b38c434cb9144f40be Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 17 Jan 2022 19:57:28 +0100 Subject: [PATCH] Fix Github asset upload 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. --- build.sc | 35 ++++++++++++++++++----------------- ci/upload.sc | 18 +++++++++++++----- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/build.sc b/build.sc index 52c88856946..abe183bb37c 100755 --- a/build.sc +++ b/build.sc @@ -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() ++ @@ -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" ) @@ -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 { diff --git a/ci/upload.sc b/ci/upload.sc index a1510a03c5b..03f9b7622bb 100644 --- a/ci/upload.sc +++ b/ci/upload.sc @@ -1,4 +1,7 @@ #!/usr/bin/env amm +import scala.util.Try +import scala.util.control.NonFatal + import scalaj.http._ @main @@ -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 @@ -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 + } }