Skip to content

Commit

Permalink
refactor nimbleci into separate standalone module, and also run `nimb…
Browse files Browse the repository at this point in the history
…le build` for each pkg
  • Loading branch information
timotheecour committed Jan 10, 2019
1 parent e813412 commit 6a5e7d3
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 126 deletions.
128 changes: 2 additions & 126 deletions koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import
os, strutils, parseopt, osproc, streams

import tools / kochdocs
import tools / nimbleci

const VersionAsString = system.NimVersion
const env_NIM_COMPILE_TO_CPP = "NIM_COMPILE_TO_CPP"
Expand Down Expand Up @@ -76,14 +77,6 @@ Web options:
build the official docs, use UA-48159761-1
"""

template withDir(dir, body) =
let old = getCurrentDir()
try:
setCurrentDir(dir)
body
finally:
setCurrentdir(old)

let origDir = getCurrentDir()
setCurrentDir(getAppDir())

Expand Down Expand Up @@ -434,126 +427,9 @@ proc xtemp(cmd: string) =
finally:
copyExe(d / "bin" / "nim_backup".exe, d / "bin" / "nim".exe)


type Outcome = enum
kInvalid,
kCompileFail,
kCloneFail,
kTestFail,
kSucces,

type TestResult = ref object
# we can add further test fields here (eg running time, mem usage etc)
pkg: string
outcome: Outcome

proc execEcho(cmd: string): bool =
echo "running:", cmd
let status = execShellCmd(cmd)
if status != 0:
echo "failed: cmd: ", cmd, " status:", status
result = status == 0

proc runCIPackage(data: var TestResult) =
let pkg = data.pkg
echo "runCIPackage:", pkg
let pkgInstall = "nimbleRoot"
let pkgClone = "nimbleRoot"

data.outcome = kInvalid
let cmd = "nimble install --nimbleDir:$# -y $# " % [pkgInstall, pkg]
if not execEcho(cmd):
echo "FAILURE: runCIPackage:", pkg
data.outcome = kCompileFail
return

withDir pkgClone:
let cmd = "nimble develop -y $#" % [pkg]
if not execEcho(cmd):
data.outcome = kCloneFail
return

withDir pkgClone / pkg:
# note: see caveat https://github.com/nim-lang/nimble/issues/558
# where `nimble test` suceeds even if no tests are defined.
let cmd = "nimble test"
if not execEcho(cmd):
# data.numTestFail.inc
data.outcome = kTestFail
return

data.outcome = kSucces

proc runCIPackages(cmd: string) =
doAssert cmd.len == 0, cmd # avoid silently ignoring
echo "runCIPackages:", cmd

var data: TestResult
let pkgs0 = """
# add more packages here; lines starting with `#` are skipped
#TODO: jester@#head or jester? etc
jester
cligen
# CT failures
libffi
glob
nimongo
nimx
karax
freeimage
regex
nimpy
zero_functional
arraymancer
inim
c2nim
sdl1
iterutils
gnuplot
nimpb
lazy
choosenim
"""

var pkgs: seq[string]
for a in pkgs0.splitLines:
var a = a.strip
if a.len == 0: continue
if a.startsWith '#': continue
pkgs.add a

echo (pkgs: pkgs)

var tests: seq[TestResult]
type Stats = array[Outcome, int]
var stats: Stats
proc toStr(a: Stats): string =
result = $(
kCompileFail:a[kCompileFail],
kCloneFail:a[kCloneFail],
kTestFail:a[kTestFail],
kSucces:a[kSucces],
)

for i,pkg in pkgs:
var data = TestResult(pkg:pkg)
runCIPackage(data)
tests.add data
stats[data.outcome].inc
if data.outcome != kSucces:
echo "FAILURE:CI"
echo (count:i, n: pkgs.len, stats:stats.toStr, pkg: pkg, outcome: data.outcome)

var failures: seq[string]
for a in tests:
if a.outcome != kSucces:
failures.add a.pkg
echo (finalStats:stats.toStr, failures:failures)
# consider sending a notification, gather stats on failed packages
runCIPackages()

proc runCI(cmd: string) =
doAssert cmd.len == 0, cmd # avoid silently ignoring
Expand Down
125 changes: 125 additions & 0 deletions tools/nimbleci.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#[
nimble wide CI
]#

import os, strutils

template withDir*(dir, body) =
let old = getCurrentDir()
try:
setCurrentDir(dir)
body
finally:
setCurrentdir(old)

proc execEcho(cmd: string): bool =
echo "running:", cmd
let status = execShellCmd(cmd)
if status != 0:
echo "failed: cmd: ", cmd, " status:", status
result = status == 0

type TestResult = ref object
# we can add further test fields here (eg running time, mem usage etc)
pkg: string
installOK: bool
developOK: bool
buildOK: bool
testOK: bool

proc runCIPackage(data: var TestResult) =
let pkg = data.pkg
echo "runCIPackage:", pkg
let pkgInstall = "nimbleRoot"
let pkgClone = "nimbleRoot"

let cmd = "nimble install --nimbleDir:$# -y $# " % [pkgInstall, pkg]
if not execEcho(cmd):
echo "FAILURE: runCIPackage:", pkg
return
data.installOK = true

withDir pkgClone:
if not execEcho("nimble develop -y $#" % [pkg]):
return
data.developOK = true

withDir pkgClone / pkg:
data.buildOK = execEcho "nimble build"
# note: see caveat https://github.com/nim-lang/nimble/issues/558
# where `nimble test` suceeds even if no tests are defined.
data.testOK = execEcho "nimble test"

proc runCIPackages*() =
echo "runCIPackages"

var data: TestResult
let pkgs0 = """
# add more packages here; lines starting with `#` are skipped
#TODO: jester@#head or jester? etc
jester
cligen
# CT failures
libffi
glob
nimongo
nimx
karax
freeimage
regex
nimpy
zero_functional
arraymancer
inim
c2nim
sdl1
iterutils
gnuplot
nimpb
lazy
choosenim
"""

var pkgs: seq[string]
for a in pkgs0.splitLines:
var a = a.strip
if a.len == 0: continue
if a.startsWith '#': continue
pkgs.add a

echo (pkgs: pkgs)

var tests: seq[TestResult]
type Stats = object
num: int
installOK: int
developOK: int
buildOK: int
testOK: int

var stats: Stats
proc toStr(a: Stats): string =
result = $a # consider human formatting if needed

for i,pkg in pkgs:
var data = TestResult(pkg:pkg)
runCIPackage(data)
tests.add data
stats.num.inc
stats.installOK+=data.installOK.ord
if not data.testOK: echo "FAILURE:CI"
echo (count:i, n: pkgs.len, stats:stats.toStr, pkg: pkg, testOK: data.testOK)

var failures: seq[string]
for a in tests:
if not a.testOK:
failures.add a.pkg
echo (finalStats:stats.toStr, failures:failures)
# consider sending a notification, gather stats on failed packages

when isMainModule:
runCIPackages()

0 comments on commit 6a5e7d3

Please sign in to comment.