summary refs log tree commit diff stats
path: root/testament/categories.nim
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2020-10-24 17:02:42 +0200
committerGitHub <noreply@github.com>2020-10-24 17:02:42 +0200
commite18fc698ed4fba3fc0e33e8116d3739d2161e618 (patch)
tree6a13759fe513ad4190dda445314b1f7abdc386f1 /testament/categories.nim
parentd4022ebe53062a7e1be5fd55637a3cce39b93a12 (diff)
downloadNim-e18fc698ed4fba3fc0e33e8116d3739d2161e618.tar.gz
Try to fix CI failures (#15701)
* Use cligens release version

* Rework important_packages main loop

* Fix

* Fix

* Create pkgs dir

* Don't use nimble develop
since it doesn't work for binary only packages, and always install head

* Use git to get the latest release/tag instead

* Tackle the root cause

* Reduce diff

* Cleanup
Diffstat (limited to 'testament/categories.nim')
-rw-r--r--testament/categories.nim75
1 files changed, 33 insertions, 42 deletions
diff --git a/testament/categories.nim b/testament/categories.nim
index 760c3c5be..07d35f6fb 100644
--- a/testament/categories.nim
+++ b/testament/categories.nim
@@ -452,15 +452,15 @@ type
     ppOne
     ppTwo
 
-iterator listPackages(part: PkgPart): tuple[name, url, cmd: string, hasDeps: bool, useHead: bool] =
+iterator listPackages(part: PkgPart): tuple[name, cmd, url: string, 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, useHead in importantList.items:
+  for n, cmd, url, useHead in importantList.items:
     if url.len != 0:
-      yield (n, url, cmd, hasDeps, useHead)
+      yield (n, cmd, url, useHead)
     else:
       var found = false
       for package in packageList.items:
@@ -468,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, useHead)
+          yield (name, cmd, pUrl, useHead)
           break
       if not found:
         raise newException(ValueError, "Cannot find package '$#'." % n)
@@ -479,16 +479,6 @@ 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."
@@ -499,47 +489,48 @@ proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string, p
 
   let packageFileTest = makeSupTest("PackageFileParsed", "", cat)
   let packagesDir = "pkgstemp"
+  createDir(packagesDir)
   var errors = 0
   try:
-    for name, url, cmd, hasDep, useHead in listPackages(part):
+    for name, cmd, url, useHead in listPackages(part):
       if packageFilter notin name:
         continue
       inc r.total
-      var test = makeSupTest(url, "", cat)
+      var test = makeSupTest(name, "", cat)
       let buildPath = packagesDir / name
+
       if not dirExists(buildPath):
-        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)
+        let (cloneCmd, cloneOutput, cloneStatus) = execCmdEx2("git", ["clone", url, buildPath])
+        if cloneStatus != QuitSuccess:
+          r.addResult(test, targetC, "", cloneCmd & "\n" & cloneOutput, reInstallFailed)
+          continue
+
+        if not useHead:
+          let (fetchCmd, fetchOutput, fetchStatus) = execCmdEx2("git", ["fetch", "--tags"], workingDir = buildPath)
+          if fetchStatus != QuitSuccess:
+            r.addResult(test, targetC, "", fetchCmd & "\n" & fetchOutput, 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)
+          let (describeCmd, describeOutput, describeStatus) = execCmdEx2("git", ["describe", "--tags", "--abbrev=0"], workingDir = buildPath)
+          if describeStatus != QuitSuccess:
+            r.addResult(test, targetC, "", describeCmd & "\n" & describeOutput, reInstallFailed)
             continue
 
+          let (checkoutCmd, checkoutOutput, checkoutStatus) = execCmdEx2("git", ["checkout", describeOutput.strip], workingDir = buildPath)
+          if checkoutStatus != QuitSuccess:
+            r.addResult(test, targetC, "", checkoutCmd & "\n" & checkoutOutput, reInstallFailed)
+            continue
+
+        let (installDepsCmd, installDepsOutput, installDepsStatus) = execCmdEx2("nimble", ["install", "--depsOnly", "-y"], workingDir = buildPath)
+        if installDepsStatus != QuitSuccess:
+          r.addResult(test, targetC, "", "installing dependencies failed:\n$ " & installDepsCmd & "\n" & installDepsOutput, reInstallFailed)
+          continue
+
       let cmdArgs = parseCmdLine(cmd)
 
-      let (buildCmdLine, buildOutput, buildStatus) = execCmdEx2(cmdArgs[0], cmdArgs[1..^1], workingDir=buildPath)
-      if buildStatus != QuitSuccess:
-        let message = "package test failed\n$ " & buildCmdLine & "\n" & buildOutput
-        r.addResult(test, targetC, "", message, reBuildFailed)
+      let (buildCmd, buildOutput, status) = execCmdEx2(cmdArgs[0], cmdArgs[1..^1], workingDir = buildPath)
+      if status != QuitSuccess:
+        r.addResult(test, targetC, "", "package test failed\n$ " & buildCmd & "\n" & buildOutput, reBuildFailed)
       else:
         inc r.passed
         r.addResult(test, targetC, "", "", reSuccess)