From c0ecb426131ebc2c3d11c085d749f55884f6fea6 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 2 Dec 2022 13:17:27 +0100 Subject: [PATCH] normalise nimble, update ci, unittest2 (#158) --- .github/workflows/ci.yml | 21 +++++++-------------- json_rpc.nimble | 26 +++++++++++++++++++++++--- json_rpc/clients/httpclient.nim | 2 +- json_rpc/servers/httpserver.nim | 1 - json_rpc/servers/websocketserver.nim | 4 ++-- tests/testethcalls.nim | 2 +- tests/testhook.nim | 2 +- tests/testhttp.nim | 3 +-- tests/testhttps.nim | 2 +- tests/testproxy.nim | 2 +- tests/testrpcmacro.nim | 2 +- tests/testserverclient.nim | 2 +- 12 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f64d56f..c7734d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,10 @@ on: pull_request: workflow_dispatch: +concurrency: # Cancel stale PR builds (but not push builds) + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + jobs: build: strategy: @@ -43,10 +47,10 @@ jobs: name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})' runs-on: ${{ matrix.builder }} - continue-on-error: ${{ matrix.branch == 'version-1-6' || matrix.branch == 'devel' }} + continue-on-error: ${{ matrix.branch == 'devel' }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install build dependencies (Linux i386) if: runner.os == 'Linux' && matrix.target.cpu == 'i386' @@ -68,13 +72,6 @@ jobs: chmod 755 external/bin/gcc external/bin/g++ echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH - - name: 'Install dependencies (macOS)' - if: runner.os == 'macOS' && matrix.branch == 'devel' - run: | - brew install openssl@1.1 - ln -s $(brew --prefix)/opt/openssl/lib/libcrypto.1.1.dylib /usr/local/lib/ - ln -s $(brew --prefix)/opt/openssl/lib/libssl.1.1.dylib /usr/local/lib/ - - name: MSYS2 (Windows i386) if: runner.os == 'Windows' && matrix.target.cpu == 'i386' uses: msys2/setup-msys2@v2 @@ -108,7 +105,6 @@ jobs: if: > steps.windows-dlls-cache.outputs.cache-hit != 'true' && runner.os == 'Windows' - shell: bash run: | mkdir -p external curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip @@ -117,9 +113,8 @@ jobs: - name: Path to cached dependencies (Windows) if: > runner.os == 'Windows' - shell: bash run: | - echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH + echo "${{ github.workspace }}/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH - name: Derive environment variables run: | @@ -149,7 +144,6 @@ jobs: echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV - name: Build Nim and associated tools - shell: bash run: | curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ matrix.branch }} \ @@ -158,7 +152,6 @@ jobs: echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH - name: Run tests - shell: bash run: | nim --version nimble --version diff --git a/json_rpc.nimble b/json_rpc.nimble index 73d36d0..3d73cd0 100644 --- a/json_rpc.nimble +++ b/json_rpc.nimble @@ -1,3 +1,5 @@ +mode = ScriptMode.Verbose + packageName = "json_rpc" version = "0.0.2" author = "Status Research & Development GmbH" @@ -14,7 +16,26 @@ requires "nim >= 1.2.0", "httputils", "chronicles", "websock", - "json_serialization" + "json_serialization", + "unittest2" + +let nimc = getEnv("NIMC", "nim") # Which nim compiler to use +let lang = getEnv("NIMLANG", "c") # Which backend (c/cpp/js) +let flags = getEnv("NIMFLAGS", "") # Extra flags for the compiler +let verbose = getEnv("V", "") notin ["", "0"] + +let styleCheckStyle = if (NimMajor, NimMinor) < (1, 6): "hint" else: "error" +let cfg = + " --styleCheck:usages --styleCheck:" & styleCheckStyle & + (if verbose: "" else: " --verbosity:0 --hints:off") & + " --skipParentCfg --skipUserCfg --outdir:build --nimcache:build/nimcache -f" & + " --threads:on -d:chronicles_log_level=ERROR" + +proc build(args, path: string) = + exec nimc & " " & lang & " " & cfg & " " & flags & " " & args & " " & path + +proc run(args, path: string) = + build args & " -r", path proc buildBinary(name: string, srcDir = "./", params = "", cmdParams = "") = if not dirExists "build": @@ -28,5 +49,4 @@ proc buildBinary(name: string, srcDir = "./", params = "", cmdParams = "") = " " & cmdParams task test, "run tests": - buildBinary "all", "tests/", - params = "" + run "", "tests/all" diff --git a/json_rpc/clients/httpclient.nim b/json_rpc/clients/httpclient.nim index 1378fc1..a37fa98 100644 --- a/json_rpc/clients/httpclient.nim +++ b/json_rpc/clients/httpclient.nim @@ -1,5 +1,5 @@ import - std/[strutils, tables, uri], + std/[tables, uri], stew/[byteutils, results], chronos/apps/http/httpclient as chronosHttpClient, chronicles, httputils, json_serialization/std/net, diff --git a/json_rpc/servers/httpserver.nim b/json_rpc/servers/httpserver.nim index 0f7fe9f..c68a92d 100644 --- a/json_rpc/servers/httpserver.nim +++ b/json_rpc/servers/httpserver.nim @@ -1,6 +1,5 @@ import stew/byteutils, - std/[strutils], chronicles, httputils, chronos, chronos/apps/http/[httpserver, shttpserver], ".."/[errors, server] diff --git a/json_rpc/servers/websocketserver.nim b/json_rpc/servers/websocketserver.nim index 886090f..f14540a 100644 --- a/json_rpc/servers/websocketserver.nim +++ b/json_rpc/servers/websocketserver.nim @@ -1,8 +1,8 @@ import - chronicles, httputils, chronos, websock/[websock, types], + chronicles, chronos, websock/[websock, types], websock/extensions/compression/deflate, stew/byteutils, json_serialization/std/net, - ".."/[errors, server] + ".."/[server] export server, net diff --git a/tests/testethcalls.nim b/tests/testethcalls.nim index 38791c5..14e198b 100644 --- a/tests/testethcalls.nim +++ b/tests/testethcalls.nim @@ -1,5 +1,5 @@ import - unittest, tables, + unittest2, tables, stint, ethtypes, ethprocs, stintjson, chronicles, ../json_rpc/[rpcclient, rpcserver], ./helpers diff --git a/tests/testhook.nim b/tests/testhook.nim index 9ec25c4..ddb9d57 100644 --- a/tests/testhook.nim +++ b/tests/testhook.nim @@ -1,5 +1,5 @@ import - unittest, + unittest2, websock/websock, ../json_rpc/[rpcclient, rpcserver] diff --git a/tests/testhttp.nim b/tests/testhttp.nim index 2c11dd5..973276b 100644 --- a/tests/testhttp.nim +++ b/tests/testhttp.nim @@ -1,5 +1,4 @@ -import unittest, strutils -import httputils +import unittest2 import ../json_rpc/[rpcserver, rpcclient] const TestsCount = 100 diff --git a/tests/testhttps.nim b/tests/testhttps.nim index 633c224..d2d1f83 100644 --- a/tests/testhttps.nim +++ b/tests/testhttps.nim @@ -1,4 +1,4 @@ -import unittest, strutils +import unittest2, strutils import httputils import ../json_rpc/[rpcsecureserver, rpcclient] import chronos/[streams/tlsstream, apps/http/httpcommon] diff --git a/tests/testproxy.nim b/tests/testproxy.nim index bac116d..0568930 100644 --- a/tests/testproxy.nim +++ b/tests/testproxy.nim @@ -1,5 +1,5 @@ import - unittest, chronicles, + unittest2, chronicles, ../json_rpc/[rpcclient, rpcserver, rpcproxy] let srvAddress = initTAddress("127.0.0.1", Port(8545)) diff --git a/tests/testrpcmacro.nim b/tests/testrpcmacro.nim index f0a6c8d..b3a45c8 100644 --- a/tests/testrpcmacro.nim +++ b/tests/testrpcmacro.nim @@ -1,4 +1,4 @@ -import unittest, chronicles, options +import unittest2, chronicles, options import ../json_rpc/rpcserver, ./helpers type diff --git a/tests/testserverclient.nim b/tests/testserverclient.nim index 033c06b..c71fb82 100644 --- a/tests/testserverclient.nim +++ b/tests/testserverclient.nim @@ -1,5 +1,5 @@ import - unittest, chronicles, + unittest2, chronicles, ../json_rpc/[rpcclient, rpcserver] # Create RPC on server