CI: test with multiple Nim versions (#24)

* CI: test with multiple Nim versions

and add a real test
This commit is contained in:
Ștefan Talpalaru 2021-12-12 00:01:56 +01:00 committed by GitHub
parent 9ca2e9fe87
commit b39f3d2975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 119 additions and 84 deletions

View File

@ -1,13 +1,16 @@
name: CI
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
jobs:
build:
strategy:
fail-fast: false
max-parallel: 20
matrix:
test_lang: [c, cpp]
target:
- os: linux
cpu: amd64
@ -17,27 +20,35 @@ jobs:
cpu: amd64
- os: windows
cpu: amd64
- os: windows
cpu: i386
#- os: windows
#cpu: i386
branch: [version-1-2, version-1-4, version-1-6, devel]
include:
- target:
os: linux
builder: ubuntu-18.04
shell: bash
- target:
os: macos
builder: macos-10.15
shell: bash
- target:
os: windows
builder: windows-2019
shell: msys2 {0}
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ matrix.test_lang }}'
defaults:
run:
shell: ${{ matrix.shell }}
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' }}
steps:
- name: Checkout nim-bearssl
- name: Checkout
uses: actions/checkout@v2
with:
path: nim-bearssl
submodules: false
submodules: true
- name: Install build dependencies (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
@ -59,13 +70,26 @@ jobs:
chmod 755 external/bin/gcc external/bin/g++
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
- name: Restore MinGW-W64 (Windows) from cache
if: runner.os == 'Windows'
id: windows-mingw-cache
uses: actions/cache@v2
- name: MSYS2 (Windows i386)
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
uses: msys2/setup-msys2@v2
with:
path: external/mingw-${{ matrix.target.cpu }}
key: 'mingw-${{ matrix.target.cpu }}'
path-type: inherit
msystem: MINGW32
install: >-
base-devel
git
mingw-w64-i686-toolchain
- name: MSYS2 (Windows amd64)
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: >-
base-devel
git
mingw-w64-x86_64-toolchain
- name: Restore Nim DLLs dependencies (Windows) from cache
if: runner.os == 'Windows'
@ -75,24 +99,6 @@ jobs:
path: external/dlls-${{ matrix.target.cpu }}
key: 'dlls-${{ matrix.target.cpu }}'
- name: Install MinGW64 dependency (Windows)
if: >
steps.windows-mingw-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows'
shell: bash
run: |
mkdir -p external
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win64/Personal Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z"
ARCH=64
else
MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/mingw-builds/8.1.0/threads-posix/dwarf/i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z"
ARCH=32
fi
curl -L "$MINGW_URL" -o "external/mingw-${{ matrix.target.cpu }}.7z"
7z x -y "external/mingw-${{ matrix.target.cpu }}.7z" -oexternal/
mv external/mingw$ARCH external/mingw-${{ matrix.target.cpu }}
- name: Install DLLs dependencies (Windows)
if: >
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
@ -111,44 +117,51 @@ jobs:
echo '${{ github.workspace }}'"/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH
echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
- name: Get latest nimbus-build-system commit hash
id: versions
shell: bash
- name: Derive environment variables
run: |
getHash() {
git ls-remote "https://github.com/$1" "${2:-HEAD}" | cut -f 1
}
nbsHash=$(getHash status-im/nimbus-build-system)
echo "::set-output name=nimbus_build_system::$nbsHash"
- name: Restore prebuilt Nim from cache
id: nim-cache
uses: actions/cache@v2
with:
path: NimBinaries
key: 'NimBinaries-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ steps.versions.outputs.nimbus_build_system }}'
- 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
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
PLATFORM=x64
else
PLATFORM=x86
fi
if [[ '${{ matrix.target.os }}' == 'windows' ]]; then
MAKE_CMD="mingw32-make"
else
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
ncpu=
MAKE_CMD="make"
fi
env MAKE="$MAKE_CMD -j2" ARCH_OVERRIDE=$PLATFORM CC=gcc bash build_nim.sh nim csources dist/nimble NimBinaries
case '${{ runner.os }}' in
'Linux')
ncpu=$(nproc)
;;
'macOS')
ncpu=$(sysctl -n hw.ncpu)
;;
'Windows')
ncpu=$NUMBER_OF_PROCESSORS
MAKE_CMD="mingw32-make"
;;
esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=$ncpu" >> $GITHUB_ENV
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 }} \
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
bash build_nim.sh nim csources dist/nimble NimBinaries
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
- name: Run nim-bearssl tests
- name: Run tests
shell: bash
working-directory: nim-bearssl
run: |
git submodule update --init --recursive
if [[ "${{ matrix.target.os }}" == "windows" ]]; then
# https://github.com/status-im/nimbus-eth2/issues/3121
export NIMFLAGS="-d:nimRawSetjmp"
fi
nim --version
nimble --version
nimble install -y --depsOnly
env TEST_LANG="${{ matrix.test_lang }}" nimble test
env TEST_LANG="c" nimble test
env TEST_LANG="cpp" nimble test

View File

@ -1,3 +1,5 @@
import os, strutils
# Package
version = "0.1.5"
author = "Status Research & Development GmbH"
@ -6,20 +8,20 @@ license = "MIT or Apache License 2.0"
mode = ScriptMode.Verbose
# Dependencies
requires "nim >= 1.2.0"
requires "nim >= 1.2.0",
"unittest2"
### Helper functions
proc test(env, path: string) =
# Compilation language is controlled by TEST_LANG
var lang = "c"
if existsEnv"TEST_LANG":
lang = getEnv"TEST_LANG"
exec "nim " & lang & " " & env &
" -r --hints:off --skipParentCfg --styleCheck:usages --styleCheck:error " & path
exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & " " & env &
" -rf --hints:off --skipParentCfg --styleCheck:usages --styleCheck:error " & path
task test, "Run tests":
exec "nim -v"
test "-d:debug", "tests/test1"
test "-d:release", "tests/test1"
test "--gc:arc -d:release", "tests/test1"
for path in listFiles(thisDir() / "tests"):
if path.split(".")[^1] != "nim":
continue
test "-d:debug", path
test "-d:release", path
test "--gc:arc -d:release", path
rmFile(path[0..^5].toExe())

31
tests/hashing.nim Normal file
View File

@ -0,0 +1,31 @@
import std/[strutils, sequtils],
unittest2,
../bearssl
suite "Hashing":
test "MD5":
let
input = ["",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"]
output = ["d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a"]
for i in 0 ..< input.len:
var
ctx = Md5Context()
res: array[md5SIZE, uint8]
md5Init(addr ctx)
md5Update(addr ctx, input[i].cstring, input[i].len)
md5Out(addr ctx, addr res[0])
check res.foldl(a & b.toHex(), "").toLower() == output[i]

View File

@ -1,11 +0,0 @@
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`
# etc. files (better names are recommended, just make sure the name starts with
# the letter 't').
#
# To run these tests, simply execute `nimble test`.
import unittest
import ../bearssl
test "dummy":
check true