-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix 'cmtc install' on windows - Introduce Li Haoyi's 'requests' and 'os' libraries - Clean-up build dependencies file - Swap file download via scala process API to `requests/os` API - Add trimming of output of `git ls-remote` command * Update native-image config files
- Loading branch information
Showing
5 changed files
with
78 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,6 @@ import com.lunatech.cmt.Releasables.{*, given} | |
|
||
import sys.process.* | ||
import scala.util.{Failure, Success, Try} | ||
import java.io.File | ||
import java.net.URL | ||
import scala.util.Using | ||
|
||
object Install: | ||
|
@@ -124,27 +122,25 @@ object Install: | |
Right(()) | ||
} | ||
|
||
private def getProjectTags(gitPrefix: String, githubProject: GithubProject): Try[Seq[String]] = | ||
val cwd = file(".").getCanonicalFile | ||
val uri = s"${gitPrefix}${githubProject.organisation}/${githubProject.project}.git" | ||
val cmd = Seq("git", "-c", "versionsort.suffix=-", "ls-remote", "--tags", "--refs", "--sort", "v:refname", uri) | ||
Try(Process(cmd, cwd).!!(ignoreProcessStdOutStdErr).split("\n").to(Seq).map(extractTag)) | ||
|
||
private def installFromGithubProject( | ||
githubProject: GithubProject, | ||
configuration: Configuration, | ||
forceDelete: Boolean): Either[CmtError, String] = { | ||
for { | ||
_ <- checkPreExistingTargetFolder(githubProject.project, configuration, forceDelete) | ||
installCompletionMessage <- { | ||
val cwd = file(".").getCanonicalFile | ||
val maybeTags = Try( | ||
Process( | ||
Seq( | ||
"git", | ||
"-c", | ||
"versionsort.suffix=-", | ||
"ls-remote", | ||
"--tags", | ||
"--refs", | ||
"--sort", | ||
"v:refname", | ||
s"[email protected]:${githubProject.organisation}/${githubProject.project}.git"), | ||
cwd).!!(ignoreProcessStdOutStdErr).split("\n").to(Seq).map(extractTag)) | ||
val maybeTags = | ||
for { | ||
tags <- getProjectTags("[email protected]:", githubProject).recoverWith(g_ => | ||
getProjectTags("https://github.com/", githubProject)) | ||
trimmedTags = tags.map(_.trim()) | ||
} yield trimmedTags | ||
val tags: Seq[String] = maybeTags match { | ||
case Success(s) => s | ||
case Failure(_) => Seq.empty[String] | ||
|
@@ -194,7 +190,8 @@ object Install: | |
private def getStudentAssetUrl(githubProject: GithubProject, tag: String): Either[CmtError, String] = { | ||
val organisation = githubProject.organisation | ||
val project = githubProject.project | ||
Right(s"https://github.com/$organisation/$project/releases/download/$tag/$project-student.zip") | ||
val url = s"https://github.com/${organisation}/${project}/releases/download/${tag}/${project}-student.zip" | ||
Right(url) | ||
} | ||
|
||
private def downloadStudentAsset( | ||
|
@@ -208,13 +205,9 @@ object Install: | |
} | ||
|
||
private def downloadFile(fileUri: String, destination: ZipFile): Either[CmtError, Unit] = | ||
Try((new URL(fileUri) #> new File(destination.value.getAbsolutePath)).!) match { | ||
case Success(0) => Right(()) | ||
case Success(exitCode) => | ||
s"""Failed to download asset: ${fileUri} | ||
| | ||
|Command exit code = $exitCode | ||
|""".stripMargin.toExecuteCommandErrorMessage.asLeft | ||
val destinationPath = os.Path(Helpers.adaptToOSSeparatorChar(destination.value.getCanonicalPath())) | ||
Try(os.write.over(destinationPath, requests.get.stream(fileUri), createFolders = true)) match { | ||
case Success(()) => Right(()) | ||
case Failure(e) => | ||
s"""Failed to download asset: ${fileUri} | ||
| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters