Skip to content

Commit 2c1dbce

Browse files
authored
Common workflow and update Autobahn test runner (#175)
Instead of installing all python dependencies and setting up autobahn ourself which tends to break regularly, now switch to recommended installation using docker image provided by autobahn author.
1 parent 6dc10ab commit 2c1dbce

File tree

8 files changed

+226
-216
lines changed

8 files changed

+226
-216
lines changed

.github/workflows/ci.yml

Lines changed: 72 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: CI
2+
23
on:
34
push:
45
branches:
@@ -14,159 +15,17 @@ on:
1415

1516
jobs:
1617
build:
17-
strategy:
18-
fail-fast: false
19-
matrix:
20-
target:
21-
- os: linux
22-
cpu: amd64
23-
- os: linux
24-
cpu: i386
25-
- os: macos
26-
cpu: arm64
27-
- os: windows
28-
cpu: amd64
29-
branch: [version-2-0, version-2-2, devel]
30-
include:
31-
- target:
32-
os: linux
33-
builder: ubuntu-latest
34-
shell: bash
35-
- target:
36-
os: macos
37-
cpu: arm64
38-
builder: macos-latest
39-
shell: bash
40-
- target:
41-
os: windows
42-
builder: windows-latest
43-
shell: msys2 {0}
44-
45-
defaults:
46-
run:
47-
shell: ${{ matrix.shell }}
48-
49-
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})'
50-
runs-on: ${{ matrix.builder }}
51-
continue-on-error: ${{ matrix.branch == 'devel' }}
52-
steps:
53-
- name: Checkout
54-
uses: actions/checkout@v4
55-
with:
56-
submodules: true
57-
58-
- name: Install build dependencies (Linux i386)
59-
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
60-
run: |
61-
sudo dpkg --add-architecture i386
62-
sudo apt-get update -qq
63-
sudo DEBIAN_FRONTEND='noninteractive' apt-get install \
64-
--no-install-recommends -yq gcc-multilib g++-multilib \
65-
libssl-dev:i386
66-
mkdir -p external/bin
67-
cat << EOF > external/bin/gcc
68-
#!/bin/bash
69-
exec $(which gcc) -m32 "\$@"
70-
EOF
71-
cat << EOF > external/bin/g++
72-
#!/bin/bash
73-
exec $(which g++) -m32 "\$@"
74-
EOF
75-
chmod 755 external/bin/gcc external/bin/g++
76-
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
77-
78-
- name: MSYS2 (Windows i386)
79-
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
80-
uses: msys2/setup-msys2@v2
81-
with:
82-
path-type: inherit
83-
msystem: MINGW32
84-
install: >-
85-
base-devel
86-
git
87-
mingw-w64-i686-toolchain
88-
89-
- name: MSYS2 (Windows amd64)
90-
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
91-
uses: msys2/setup-msys2@v2
92-
with:
93-
path-type: inherit
94-
install: >-
95-
base-devel
96-
git
97-
mingw-w64-x86_64-toolchain
98-
99-
- name: Restore Nim DLLs dependencies (Windows) from cache
100-
if: runner.os == 'Windows'
101-
id: windows-dlls-cache
102-
uses: actions/cache@v4
103-
with:
104-
path: external/dlls-${{ matrix.target.cpu }}
105-
key: 'dlls-${{ matrix.target.cpu }}'
106-
107-
- name: Install DLLs dependencies (Windows)
108-
if: >
109-
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
110-
runner.os == 'Windows'
111-
run: |
112-
DLLPATH=external/dlls-${{ matrix.target.cpu }}
113-
mkdir -p external
114-
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
115-
7z x -y external/windeps.zip -o"$DLLPATH"
116-
117-
- name: Path to cached dependencies (Windows)
118-
if: >
119-
runner.os == 'Windows'
120-
run: |
121-
echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
122-
123-
- name: Derive environment variables
124-
run: |
125-
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
126-
PLATFORM=x64
127-
elif [[ '${{ matrix.target.cpu }}' == 'arm64' ]]; then
128-
PLATFORM=arm64
129-
else
130-
PLATFORM=x86
131-
fi
132-
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
133-
134-
ncpu=
135-
MAKE_CMD="make"
136-
case '${{ runner.os }}' in
137-
'Linux')
138-
ncpu=$(nproc)
139-
;;
140-
'macOS')
141-
ncpu=$(sysctl -n hw.ncpu)
142-
;;
143-
'Windows')
144-
ncpu=$NUMBER_OF_PROCESSORS
145-
MAKE_CMD="mingw32-make"
146-
;;
147-
esac
148-
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
149-
echo "ncpu=$ncpu" >> $GITHUB_ENV
150-
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV
151-
152-
- name: Build Nim and Nimble
153-
run: |
154-
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
155-
env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ matrix.branch }} \
156-
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
157-
bash build_nim.sh nim csources dist/nimble NimBinaries
158-
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
159-
160-
- name: Run tests
161-
run: |
162-
nim --version
163-
nimble --version
164-
nimble install -y --depsOnly
165-
nimble test
166-
env NIMFLAGS="--mm:refc" nimble test
18+
uses: status-im/nimbus-common-workflow/.github/workflows/common.yml@main
19+
with:
20+
nim-versions: '["version-2-0", "version-2-2", "devel"]'
21+
test-command: |
22+
nim --version
23+
nimble --version
24+
nimble install -y --depsOnly
25+
nimble test
26+
env NIMFLAGS="--mm:refc" nimble test
16727
16828
autobahn-test:
169-
if: github.event_name == 'push' # || github.event_name == 'pull_request'
17029
name: "Autobahn test suite"
17130
runs-on: ubuntu-latest
17231

@@ -175,7 +34,7 @@ jobs:
17534
max-parallel: 20
17635
matrix:
17736
websock: [ws, wsc, wss, wssc]
178-
branch: [version-1-6, version-2-0, devel]
37+
branch: [version-2-0, version-2-2, devel]
17938

18039
defaults:
18140
run:
@@ -184,82 +43,60 @@ jobs:
18443
steps:
18544
- name: Checkout
18645
uses: actions/checkout@v4
46+
47+
- name: Get latest nimbus-build-system commit hash
48+
id: versions
49+
run: |
50+
nbsHash=$(git ls-remote "https://github.com/status-im/nimbus-build-system" "${2:-HEAD}" | cut -f 1 )
51+
echo "nimbus_build_system=$nbsHash" >> $GITHUB_OUTPUT
52+
53+
- name: Restore prebuilt Nim from cache
54+
uses: actions/cache@v4
18755
with:
188-
submodules: true
56+
path: NimBinCache
57+
key: 'nim-${{ matrix.branch }}-${{ steps.versions.outputs.nimbus_build_system }}'
18958

19059
- name: Build Nim and Nimble
19160
run: |
19261
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
19362
env MAKE="make -j$(nproc)" NIM_COMMIT=${{ matrix.branch }} \
19463
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
195-
bash build_nim.sh nim csources dist/nimble NimBinaries
64+
bash build_nim.sh nim csources dist/nimble NimBinCache
19665
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
19766
198-
- name: Setup Python version
199-
uses: actions/setup-python@v5
67+
- name: Get docker image cache key
68+
id: cache_key
69+
run: |
70+
dockerHash=$(docker buildx imagetools inspect crossbario/autobahn-testsuite | grep "Digest" | cut -d':' -f 3)
71+
echo "cache_key=$dockerHash" >> $GITHUB_OUTPUT
72+
73+
- name: Cache Docker image
74+
id: cache-docker-image
75+
uses: actions/cache@v4
20076
with:
201-
python-version: pypy-2.7
77+
path: /var/lib/docker # Or the specific path where your image is stored
78+
key: ${{ runner.os }}-docker-image-${{ steps.cache_key.outputs.cache_key }}
79+
80+
- name: Pull Docker image if not cached
81+
if: steps.cache-docker-image.outputs.cache-hit != 'true'
82+
run: docker pull crossbario/autobahn-testsuite:latest
20283

203-
- name: Setup Autobahn.
84+
- name: Setup dependencies
20485
run: |
205-
sudo apt-get install -y python2.7-dev
206-
pip install virtualenv
207-
pip install markdown2
208-
virtualenv --python=/usr/bin/python2.7 autobahn
209-
source autobahn/bin/activate
210-
pip install autobahntestsuite txaio==2.1.0 autobahn[twisted,accelerate]==0.10.9 jinja2==2.6 markupsafe==0.19 Werkzeug==0.9.6 klein==0.2.3 pyopenssl service_identity==14.0.0 unittest2==1.1.0 wsaccel==0.6.2
211-
pip freeze
212-
nimble install -y --depsOnly
86+
nimble install -y --depsOnly
21387
21488
- name: Generate index.html
215-
if: matrix.websock == 'ws'
89+
# Run this step only once for all matrix combinations
90+
if: matrix.websock == 'ws' && matrix.branch == 'devel'
21691
run: |
21792
mkdir autobahn/reports
21893
sed -i "s/COMMIT_SHA_SHORT/${GITHUB_SHA::7}/g" autobahn/index.md
21994
sed -i "s/COMMIT_SHA/$GITHUB_SHA/g" autobahn/index.md
220-
markdown2 autobahn/index.md > autobahn/reports/index.html
95+
cp -a autobahn/index.md autobahn/reports/index.md
22196
222-
- name: Run Autobahn test suite.
97+
- name: Run Autobahn test suite
22398
run: |
224-
source autobahn/bin/activate
225-
case '${{ matrix.websock }}' in
226-
ws)
227-
nim c -d:release examples/server.nim
228-
examples/server &
229-
server=$!
230-
231-
cd autobahn
232-
wstest --mode fuzzingclient --spec fuzzingclient.json
233-
;;
234-
wsc)
235-
nim c -d:tls -d:release -o:examples/tls_server examples/server.nim
236-
examples/tls_server &
237-
server=$!
238-
239-
cd autobahn
240-
wstest --mode fuzzingclient --spec fuzzingclient_tls.json
241-
;;
242-
wss)
243-
cd autobahn
244-
wstest --webport=0 --mode fuzzingserver --spec fuzzingserver.json &
245-
server=$!
246-
247-
cd ..
248-
nim c -d:release examples/autobahn_client
249-
examples/autobahn_client
250-
;;
251-
wssc)
252-
cd autobahn
253-
wstest --webport=0 --mode fuzzingserver --spec fuzzingserver_tls.json &
254-
server=$!
255-
256-
cd ..
257-
nim c -d:tls -d:release -o:examples/autobahn_tlsclient examples/autobahn_client
258-
examples/autobahn_tlsclient
259-
;;
260-
esac
261-
262-
kill $server
99+
bash scripts/${{ matrix.websock }}.sh ${{ matrix.branch }}
263100
264101
- name: Upload Autobahn result
265102
uses: actions/upload-artifact@v4
@@ -281,9 +118,11 @@ jobs:
281118
pattern: autobahn-artifact-*
282119

283120
deploy-test:
284-
name: "Deplay Autobahn results"
121+
name: "Deploy Autobahn results"
285122
needs: merge-autobahn-artifact
286123
runs-on: ubuntu-latest
124+
permissions:
125+
contents: write
287126

288127
defaults:
289128
run:
@@ -296,8 +135,31 @@ jobs:
296135
name: autobahn-report
297136
path: ./autobahn_reports
298137

299-
- name: Deploy autobahn report.
138+
- name: Setup Python version
139+
uses: actions/setup-python@v5
140+
with:
141+
python-version: pypy-3.10
142+
143+
- name: Setup dependencies
144+
run: |
145+
pip install markdown2
146+
147+
- name: Setup dependencies
148+
run: |
149+
cat autobahn_reports/*.txt >> autobahn_reports/index.md
150+
markdown2 autobahn_reports/index.md > autobahn_reports/index.html
151+
152+
- name: Deploy autobahn report
300153
uses: peaceiris/actions-gh-pages@v4
301154
with:
302155
personal_token: ${{ secrets.GITHUB_TOKEN }}
303156
publish_dir: ./autobahn_reports
157+
158+
- name: Delete artefacts
159+
uses: geekyeggo/delete-artifact@v5
160+
with:
161+
failOnError: false
162+
name: |
163+
autobahn-report
164+
autobahn-artifact-*
165+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
nimcache
33
nimble.develop
44
nimble.paths
5+
reports/

autobahn/fuzzingserver_tls.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"url": "wss://127.0.0.1:9002",
3-
"key": "tls/server.key",
4-
"cert": "tls/server.crt",
3+
"key": "/config/tls/server.key",
4+
"cert": "/config/tls/server.crt",
55

66
"options": {"failByDrop": false},
77
"outdir": "./reports/client_tls",

autobahn/index.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22

33
Generated by commit [COMMIT_SHA_SHORT](https://github.com/status-im/nim-websock/commit/COMMIT_SHA).
44

5-
* [ws server summary report](server/index.html)
6-
* [wss server summary report](server_tls/index.html)
7-
* [ws client summary report](client/index.html)
8-
* [wss client summary report](client_tls/index.html)

0 commit comments

Comments
 (0)