Skip to content

Commit

Permalink
Fix resolveArtifacts (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-goral authored Oct 12, 2020
1 parent e911c9e commit 425e668
Showing 1 changed file with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
package flank.scripts.testartifacts.core

import com.jcabi.github.Repo
import java.io.File

fun Context.resolveArtifacts(repo: Repo = testArtifactsRepo()) {
resolveRemotelyOrFallback(
repo = repo,
fallback = { resolveFallback(repo) }
)
}

private fun Context.resolveRemotelyOrFallback(repo: Repo, fallback: () -> Unit) {
fun Context.resolveArtifacts(
repo: Repo = testArtifactsRepo()
) {
if (isNewVersionAvailable(repo)) {
downloadFixtures()
unzipTestArtifacts()
linkArtifacts()
} else fallback()
}

private fun Context.resolveFallback(repo: Repo) {
projectRoot.testArtifacts(branch).run {
} else projectRoot.testArtifacts(branch).run {
if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath")
else tryResolveForMaster(repo)
else copy(branch = "master").run {
if (isNewVersionAvailable(repo)) {
downloadFixtures()
unzipTestArtifacts()
linkArtifacts()
} else projectRoot.testArtifacts(branch).run {
if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath")
else throw Exception("Cannot resolve test artifacts")
}
}
}
}

private fun Context.tryResolveForMaster(repo: Repo) {
copy(branch = "master").resolveRemotelyOrFallback(
repo = repo,
fallback = { projectRoot.testArtifacts(branch).resolveLocallyOrThrow(branch) }
)
}

private fun File.resolveLocallyOrThrow(branch: String) {
if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath")
else throw Exception("Cannot resolve test artifacts")
}

0 comments on commit 425e668

Please sign in to comment.