CI: Install the pkg we cloned (#14770)

This commit is contained in:
Clyybber
2020-06-24 17:27:46 +02:00
committed by GitHub
parent 2220ff70be
commit 302e3b7f44
3 changed files with 45 additions and 57 deletions

View File

@@ -1,32 +0,0 @@
##[
internal API for now, API subject to change
]##
import std/[os,osproc,sugar,strutils]
proc actionRetry*(maxRetry: int, backoffDuration: float, action: proc(): bool): bool =
## retry `action` up to `maxRetry` times with exponential backoff and initial
## duraton of `backoffDuration` seconds
var t = backoffDuration
for i in 0..<maxRetry:
if action(): return true
if i == maxRetry - 1: break
sleep(int(t * 1000))
t = t * 2 # exponential backoff
return false
proc nimbleInstall*(name: string, message: var string): bool =
let cmd = "nimble install -y " & name
let (outp, status) = execCmdEx(cmd)
if status != 0:
message = "'$1' failed:\n$2" % [cmd, outp]
result = false
else: result = true
when isMainModule:
block:
var msg: string
let ok = actionRetry(maxRetry = 2, backoffDuration = 0.1):
(proc(): bool = nimbleInstall("nonexistant", msg))
doAssert "Package not found" in msg
doAssert not ok

View File

@@ -13,7 +13,6 @@
# included from testament.nim
import important_packages
import std/private/nimbleutils
const
specialCategories = [
@@ -453,15 +452,15 @@ type
ppOne
ppTwo
iterator listPackages(part: PkgPart): tuple[name, url, cmd: string, hasDeps: bool] =
iterator listPackages(part: PkgPart): tuple[name, url, cmd: string, hasDeps: bool, useHead: bool] =
let packageList = parseFile(packageIndex)
let importantList =
case part
of ppOne: important_packages.packages1
of ppTwo: important_packages.packages2
for n, cmd, hasDeps, url in importantList.items:
for n, cmd, hasDeps, url, useHead in importantList.items:
if url.len != 0:
yield (n, url, cmd, hasDeps)
yield (n, url, cmd, hasDeps, useHead)
else:
var found = false
for package in packageList.items:
@@ -469,7 +468,7 @@ iterator listPackages(part: PkgPart): tuple[name, url, cmd: string, hasDeps: boo
if name == n:
found = true
let pUrl = package["url"].str
yield (name, pUrl, cmd, hasDeps)
yield (name, pUrl, cmd, hasDeps, useHead)
break
if not found:
raise newException(ValueError, "Cannot find package '$#'." % n)
@@ -480,6 +479,16 @@ proc makeSupTest(test, options: string, cat: Category): TTest =
result.options = options
result.startTime = epochTime()
proc actionRetry(maxRetry: int, backoffDuration: float, action: proc: bool): bool =
## retry `action` up to `maxRetry` times with exponential backoff and initial
## duraton of `backoffDuration` seconds
var t = backoffDuration
for i in 0..<maxRetry:
if action(): return true
if i == maxRetry - 1: break
sleep(int(t * 1000))
t *= 2 # exponential backoff
proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string, part: PkgPart) =
if nimbleExe == "":
echo "[Warning] - Cannot run nimble tests: Nimble binary not found."
@@ -492,26 +501,38 @@ proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string, p
let packagesDir = "pkgstemp"
var errors = 0
try:
for name, url, cmd, hasDep in listPackages(part):
for name, url, cmd, hasDep, useHead in listPackages(part):
if packageFilter notin name:
continue
inc r.total
var test = makeSupTest(url, "", cat)
let buildPath = packagesDir / name
if not existsDir(buildPath):
if hasDep:
let installName = if url.len != 0: url else: name
var message: string
if not actionRetry(maxRetry = 3, backoffDuration = 1.0,
(proc(): bool = nimbleInstall(installName, message))):
if useHead:
let (installCmdLine, installOutput, installStatus) = execCmdEx2("git", ["clone", url, buildPath])
if installStatus != QuitSuccess:
let message = "git clone failed:\n$ " & installCmdLine & "\n" & installOutput
r.addResult(test, targetC, "", message, reInstallFailed)
continue
let (installCmdLine, installOutput, installStatus) = execCmdEx2("git", ["clone", url, buildPath])
if installStatus != QuitSuccess:
let message = "git clone failed:\n$ " & installCmdLine & "\n" & installOutput
r.addResult(test, targetC, "", message, reInstallFailed)
continue
if hasDep:
var message: string
if not actionRetry(maxRetry = 3, backoffDuration = 1.0,
proc: bool =
let (outp, status) = execCmdEx("nimble install -y", workingDir = buildPath)
if status != 0:
message = "'$1' failed:\n$2" % [cmd, outp]
false
else: true
):
r.addResult(test, targetC, "", message, reInstallFailed)
continue
else:
let (installCmdLine, installOutput, installStatus) = execCmdEx2("nimble", ["develop", name, "-y"])
if installStatus != QuitSuccess:
let message = "nimble develop failed:\n$ " & installCmdLine & "\n" & installOutput
r.addResult(test, targetC, "", message, reInstallFailed)
continue
let cmdArgs = parseCmdLine(cmd)

View File

@@ -1,17 +1,17 @@
template pkg1(name: string; hasDeps = false; cmd = "nimble test"; url = ""): untyped =
packages1.add((name, cmd, hasDeps, url))
template pkg1(name: string; hasDeps = false; cmd = "nimble test"; url = "", useHead = true): untyped =
packages1.add((name, cmd, hasDeps, url, useHead))
template pkg2(name: string; hasDeps = false; cmd = "nimble test"; url = ""): untyped =
packages2.add((name, cmd, hasDeps, url))
template pkg2(name: string; hasDeps = false; cmd = "nimble test"; url = "", useHead = true): untyped =
packages2.add((name, cmd, hasDeps, url, useHead))
var packages1*: seq[tuple[name, cmd: string; hasDeps: bool; url: string]] = @[]
var packages2*: seq[tuple[name, cmd: string; hasDeps: bool; url: string]] = @[]
var packages1*: seq[tuple[name, cmd: string; hasDeps: bool; url: string, useHead: bool]] = @[]
var packages2*: seq[tuple[name, cmd: string; hasDeps: bool; url: string, useHead: bool]] = @[]
# packages A-M
pkg1 "alea", true
pkg1 "argparse"
pkg1 "arraymancer", true, "nim c tests/tests_cpu.nim"
# pkg1 "arraymancer", true, "nim c tests/tests_cpu.nim"
pkg1 "ast_pattern_matching", false, "nim c -r --oldgensym:on tests/test1.nim"
pkg1 "asyncmysql", true
pkg1 "awk", true
@@ -49,7 +49,7 @@ pkg1 "gnuplot"
pkg1 "hts", false, "nim c -o:htss src/hts.nim"
# pkg1 "httpauth", true
pkg1 "illwill", false, "nimble examples"
pkg1 "inim", true # pending https://github.com/inim-repl/INim/issues/74
pkg1 "inim", true
pkg1 "itertools", false, "nim doc src/itertools.nim"
pkg1 "iterutils"
pkg1 "jstin"
@@ -90,7 +90,6 @@ pkg2 "nimsvg"
pkg2 "nimwc", true, "nim c nimwc.nim"
# pkg2 "nimx", true, "nim c --threads:on test/main.nim"
# pkg2 "nitter", true, "nim c src/nitter.nim", "https://github.com/zedeus/nitter"
# pending https://github.com/timotheecour/Nim/issues/167 or new git tag for nitter
pkg2 "norm", true, "nim c -r tests/tsqliterows.nim"
pkg2 "npeg", false, "nimble testarc"
pkg2 "numericalnim", true, "nim c -r tests/test_integrate.nim"