Skip to content

Commit 0f82cf2

Browse files
CI: test with multiple Nim versions (#46)
* CI: test with multiple Nim versions
1 parent 0b5466f commit 0f82cf2

File tree

3 files changed

+89
-94
lines changed

3 files changed

+89
-94
lines changed

.github/workflows/ci.yml

Lines changed: 78 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
1-
name: nim-web3 CI
2-
on: [push, pull_request]
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
workflow_dispatch:
38

49
jobs:
510
build:
611
strategy:
712
fail-fast: false
8-
max-parallel: 20
913
matrix:
10-
branch: [master]
1114
target:
1215
- os: linux
1316
cpu: amd64
14-
TEST_LANG: c
1517
- os: linux
1618
cpu: i386
17-
TEST_LANG: c
1819
- os: macos
1920
cpu: amd64
20-
TEST_LANG: c
2121
- os: windows
2222
cpu: amd64
23-
TEST_LANG: c
24-
- os: windows
25-
cpu: i386
26-
TEST_LANG: c
23+
#- os: windows
24+
#cpu: i386
25+
branch: [version-1-2, version-1-4, version-1-6, devel]
2726
include:
2827
- target:
2928
os: linux
3029
builder: ubuntu-18.04
30+
shell: bash
3131
- target:
3232
os: macos
3333
builder: macos-10.15
34+
shell: bash
3435
- target:
3536
os: windows
3637
builder: windows-2019
38+
shell: msys2 {0}
3739

38-
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ matrix.target.TEST_LANG }} (${{ matrix.branch }})'
40+
defaults:
41+
run:
42+
shell: ${{ matrix.shell }}
43+
44+
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})'
3945
runs-on: ${{ matrix.builder }}
4046
steps:
41-
- name: Checkout nim-web3
47+
- name: Checkout
4248
uses: actions/checkout@v2
43-
with:
44-
path: nim-web3
45-
submodules: false
4649

4750
- name: Install build dependencies (Linux i386)
4851
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
@@ -64,95 +67,91 @@ jobs:
6467
chmod 755 external/bin/gcc external/bin/g++
6568
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
6669
67-
- name: Restore MinGW-W64 (Windows) from cache
68-
if: runner.os == 'Windows'
69-
id: windows-mingw-cache
70-
uses: actions/cache@v2
70+
- name: MSYS2 (Windows i386)
71+
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
72+
uses: msys2/setup-msys2@v2
73+
with:
74+
path-type: inherit
75+
msystem: MINGW32
76+
install: >-
77+
base-devel
78+
git
79+
mingw-w64-i686-toolchain
80+
81+
- name: MSYS2 (Windows amd64)
82+
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
83+
uses: msys2/setup-msys2@v2
7184
with:
72-
path: external/mingw-${{ matrix.target.cpu }}
73-
key: 'mingw-${{ matrix.target.cpu }}'
85+
path-type: inherit
86+
install: >-
87+
base-devel
88+
git
89+
mingw-w64-x86_64-toolchain
7490
7591
- name: Restore Nim DLLs dependencies (Windows) from cache
7692
if: runner.os == 'Windows'
7793
id: windows-dlls-cache
7894
uses: actions/cache@v2
7995
with:
80-
path: external/dlls-${{ matrix.target.cpu }}
81-
key: 'dlls-${{ matrix.target.cpu }}'
82-
83-
- name: Install MinGW64 dependency (Windows)
84-
if: >
85-
steps.windows-mingw-cache.outputs.cache-hit != 'true' &&
86-
runner.os == 'Windows'
87-
shell: bash
88-
run: |
89-
mkdir -p external
90-
MINGW_BASE="https://github.com/brechtsanders/winlibs_mingw/releases/download/11.2.0-12.0.1-9.0.0-r1"
91-
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
92-
MINGW_URL="$MINGW_BASE/winlibs-x86_64-posix-seh-gcc-11.2.0-mingw-w64-9.0.0-r1.7z"
93-
ARCH=64
94-
else
95-
MINGW_URL="$MINGW_BASE/winlibs-i686-posix-dwarf-gcc-11.2.0-mingw-w64-9.0.0-r1.7z"
96-
ARCH=32
97-
fi
98-
curl -L "$MINGW_URL" -o "external/mingw-${{ matrix.target.cpu }}.7z"
99-
7z x -y "external/mingw-${{ matrix.target.cpu }}.7z" -oexternal/
100-
mv external/mingw$ARCH external/mingw-${{ matrix.target.cpu }}
96+
path: external/dlls
97+
key: 'dlls'
10198

102-
- name: Install DLLs dependencies (Windows)
99+
- name: Install DLL dependencies (Windows)
103100
if: >
104101
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
105102
runner.os == 'Windows'
106-
shell: bash
107103
run: |
108-
mkdir -p external
104+
mkdir external
109105
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
110-
7z x -y external/windeps.zip -oexternal/dlls-${{ matrix.target.cpu }}
106+
7z x external/windeps.zip -oexternal/dlls
111107
112108
- name: Path to cached dependencies (Windows)
113109
if: >
114110
runner.os == 'Windows'
115-
shell: bash
116111
run: |
117-
echo '${{ github.workspace }}'"/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH
118-
echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
112+
echo '${{ github.workspace }}'"/external/dlls" >> $GITHUB_PATH
119113
120-
- name: Get latest nimbus-build-system commit hash
121-
id: versions
122-
shell: bash
114+
- name: Derive environment variables
123115
run: |
124-
getHash() {
125-
git ls-remote "https://github.com/$1" "${2:-HEAD}" | cut -f 1
126-
}
127-
nbsHash=$(getHash status-im/nimbus-build-system)
128-
echo "::set-output name=nimbus_build_system::$nbsHash"
129-
130-
- name: Restore prebuilt Nim from cache
131-
id: nim-cache
132-
uses: actions/cache@v2
133-
with:
134-
path: NimBinaries
135-
key: 'NimBinaries-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ steps.versions.outputs.nimbus_build_system }}'
136-
137-
- name: Build Nim and associated tools
138-
shell: bash
139-
run: |
140-
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
141116
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
142117
PLATFORM=x64
143118
else
144119
PLATFORM=x86
145120
fi
146-
if [[ '${{ matrix.target.os }}' == 'windows' ]]; then
121+
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
122+
123+
ncpu=
124+
MAKE_CMD="make"
125+
case '${{ runner.os }}' in
126+
'Linux')
127+
ncpu=$(nproc)
128+
;;
129+
'macOS')
130+
ncpu=$(sysctl -n hw.ncpu)
131+
;;
132+
'Windows')
133+
ncpu=$NUMBER_OF_PROCESSORS
147134
MAKE_CMD="mingw32-make"
148-
else
149-
MAKE_CMD="make"
150-
fi
151-
env MAKE="$MAKE_CMD -j2" ARCH_OVERRIDE=$PLATFORM CC=gcc bash build_nim.sh nim csources dist/nimble NimBinaries
135+
;;
136+
esac
137+
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
138+
echo "ncpu=$ncpu" >> $GITHUB_ENV
139+
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV
140+
141+
- name: Build Nim and Nimble
142+
run: |
143+
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
144+
env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ matrix.branch }} \
145+
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
146+
bash build_nim.sh nim csources dist/nimble NimBinaries
152147
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
153148
154-
- name: Run nim-web3 tests
155-
shell: bash
156-
working-directory: nim-web3
149+
- name: Run tests
157150
run: |
158-
env TEST_LANG="${{ matrix.target.TEST_LANG }}" ./ci-test.sh
151+
if [[ "${{ matrix.target.os }}" == "windows" ]]; then
152+
# https://github.com/status-im/nimbus-eth2/issues/3121
153+
export NIMFLAGS="-d:nimRawSetjmp"
154+
fi
155+
nim --version
156+
nimble --version
157+
./ci-test.sh

ci-test.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ set -ex
44
npm install hardhat
55
touch hardhat.config.js
66
nohup npx hardhat node &
7-
nimble install -y
7+
nimble install -y --depsOnly
88

99
# Wait until ganache responds
1010
while ! curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}' localhost:8545 2>/dev/null
1111
do
12-
true
12+
sleep 1
1313
done
14-
env TEST_LANG="$TEST_LANG" nimble test
14+
if [[ -n "${TEST_LANG}" ]]; then
15+
export TEST_LANG
16+
fi
17+
nimble test

web3.nimble

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@ requires "stew"
1818
requires "stint"
1919

2020
### Helper functions
21-
proc getLang(): string =
22-
var lang = "c"
23-
if existsEnv"TEST_LANG":
24-
lang = getEnv"TEST_LANG"
25-
lang
26-
27-
proc test(name: string, defaultLang = getLang()) =
28-
# TODO, don't forget to change defaultLang to `cpp` if the project requires C++
21+
proc test(args, path: string) =
2922
if not dirExists "build":
3023
mkDir "build"
31-
--run
32-
switch("out", ("./build/" & name))
33-
setCommand defaultLang, "tests/" & name & ".nim"
24+
exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & " " & args &
25+
" --outdir:build -r --hints:off --warnings:off --skipParentCfg " & path
26+
3427

3528
### tasks
3629
task test, "Run all tests":
37-
test "all_tests"
30+
test "", "tests/all_tests.nim"

0 commit comments

Comments
 (0)