Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download test repos via coursier #4066

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions ci/shared.mill
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package build.ci

import coursier.cache.FileCache
import coursier.util.Artifact


def downloadTestRepo(label: String, commit: String, dest: os.Path) = {
os.unzip.stream(requests.get.stream(s"https://github.com/$label/archive/$commit.zip"), dest)
def downloadTestRepo(label: String, commit: String, dest: os.Path)(implicit ctx: mill.api.Ctx.Log) = {
val cache = FileCache()
// Uncomment when rebootstrapping Mill, to get better logging
// .withLogger(mill.util.CoursierSupport.millLogger())
val file = cache.file(Artifact(s"https://github.com/$label/archive/$commit.zip"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noob question: I just can create a file cache and download a arbitrary file?
Where is this then cached and what is its cache key? I assume the key is the URL?

Because this seems very useful in general. I have a 'manual' cache so far.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using the cache of coursier, which downloads dependencies in Mill (JVM ones at least). The exact cache location depends on the OS.

That doesn't support query strings, and if the artifact might change, one should call withChanging(true) on the Artifact created in the code above (then if the last check is older than a TTL, coursier will check if the file changed).

.run.unsafeRun()(cache.ec)
.fold(ex => throw new Exception(ex), identity)
os.unzip(os.Path(file), dest)
dest
}
3 changes: 3 additions & 0 deletions main/util/src/mill/util/CoursierSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ trait CoursierSupport {

object CoursierSupport {

def millLogger()(implicit ctx: Ctx.Log): CacheLogger =
new TickerResolutionLogger(ctx)

/**
* A Coursier Cache.Logger implementation that updates the ticker with the count and
* overall byte size of artifacts being downloaded.
Expand Down
Loading