GitHub CI: enable AddressSanitizer.
[tinc] / .github / workflows / test.yml
1 name: Test
2
3 on:
4   push:
5   pull_request:
6     types:
7       - opened
8       - synchronize
9
10 jobs:
11   code-style:
12     runs-on: ubuntu-latest
13     steps:
14       - name: Checkout code
15         uses: actions/checkout@v2
16
17       - name: Install code formatting tools
18         run: |
19           sudo apt-get install -y astyle
20           curl -OL 'https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-v0.7.2.linux.x86_64.tar.xz'
21           tar -C ~ --strip-components=1 --wildcards -xf ./shellcheck-*.tar.xz 'shellcheck-*/shellcheck'
22           curl -o ~/shfmt -L 'https://github.com/mvdan/sh/releases/download/v3.3.0/shfmt_v3.3.0_linux_amd64'
23           chmod 755 ~/shfmt ~/shellcheck
24
25       - name: Check code formatting
26         run: "! astyle -r --options=.astylerc --dry-run --formatted '*.c' '*.h' | grep '^Formatted'"
27
28       - name: Check scripts formatting
29         run: find -type f -regextype egrep -regex '.+\.(sh|sh\.in|test)$' -exec ~/shfmt -d -i 2 -s '{}' +
30         if: always()
31
32       - name: Run static analysis on scripts
33         run: find -type f -regextype egrep -regex '.+\.sh(\.in)?$' -exec shellcheck -x '{}' +
34         if: always()
35
36       - name: Prepare test library and run static analysis on tests
37         run: |
38           autoreconf -fsi
39           ./configure --disable-{lzo,readline,zlib,curses}
40           find -type f -name '*.test' -execdir shellcheck -x '{}' +
41         if: always()
42
43   sanitizer:
44     runs-on: ubuntu-latest
45     strategy:
46       fail-fast: false
47       matrix:
48         sanitizer:
49           - address
50           - thread
51           - undefined
52     env:
53       SANITIZER: "${{ matrix.sanitizer }}"
54
55     steps:
56       - name: Checkout code
57         uses: actions/checkout@v2
58         with:
59           fetch-depth: 0
60
61       - name: Install deps
62         shell: bash
63         run: >
64           sudo apt-get install -y
65           git binutils make autoconf automake diffutils texinfo netcat
66           zlib1g-dev lib{ssl,lzo2,ncurses,readline,vdeplug,miniupnpc}-dev
67
68       - name: Configure and compile
69         shell: bash
70         run: bash .github/workflows/sanitizers/build.sh
71         env:
72           CC: clang-12
73
74       - name: Run tests
75         run: bash .github/workflows/sanitizers/run.sh
76
77       - name: Archive test results
78         run: sudo tar -c -z -f test-results.tar.gz test/ sanitizer/
79         if: always()
80
81       - name: Upload test results
82         uses: actions/upload-artifact@v2
83         with:
84           name: tests_sanitizer_${{ matrix.sanitizer }}
85           path: test-results.tar.gz
86         if: always()
87
88   linux:
89     runs-on: ubuntu-latest
90     strategy:
91       fail-fast: false
92       matrix:
93         os:
94           - alpine:3.13
95           - centos:7 # aka RHEL 7
96           - almalinux:8 # aka RHEL 8
97           - debian:oldstable
98           - debian:stable
99           - debian:testing
100           - debian:unstable
101           - ubuntu:18.04 # previous LTS
102           - ubuntu:20.04 # current LTS
103           - opensuse/leap # aka SLES
104     container:
105       image: ${{ matrix.os }}
106       options: --privileged
107
108     steps:
109       - name: Install deps (Alpine)
110         run: >
111           apk add git binutils make autoconf automake gcc linux-headers libtool
112           diffutils texinfo procps openssl-dev zlib-dev lzo-dev ncurses-dev
113           readline-dev musl-dev lz4-dev socat
114         if: startsWith(matrix.os, 'alpine')
115
116       - name: Install deps (Debian and Ubuntu)
117         shell: bash
118         run: |
119           apt-get update
120           apt-get install -y git binutils make autoconf automake gcc diffutils \
121             texinfo netcat procps socat zlib1g-dev lib{ssl,lzo2,lz4,ncurses,readline}-dev
122         env:
123           DEBIAN_FRONTEND: noninteractive
124         if: startsWith(matrix.os, 'debian') || startsWith(matrix.os, 'ubuntu')
125
126       - name: Install deps (RHEL)
127         shell: bash
128         run: |
129           if type dnf 2>/dev/null; then
130             dnf install -y 'dnf-command(config-manager)'
131             dnf config-manager --enable powertools
132           fi
133           yum install -y epel-release
134           yum install -y git binutils make autoconf automake gcc diffutils \
135             texinfo netcat procps socat {lzo,zlib,lz4,ncurses,readline}-devel
136           yum install -y openssl11-devel || yum install -y openssl-devel
137         if: startsWith(matrix.os, 'centos') || startsWith(matrix.os, 'alma')
138
139       - name: Install deps (SUSE)
140         shell: bash
141         run: >
142           zypper install -y tar git binutils make autoconf automake gcc procps
143           makeinfo diffutils gzip socat {openssl,zlib,lzo,liblz4,ncurses,readline}-devel
144         if: startsWith(matrix.os, 'opensuse')
145
146       - name: Checkout code
147         uses: actions/checkout@v2
148         with:
149           fetch-depth: 0
150
151       - name: Assign name for test results artifact
152         run: echo TEST_ARTIFACT="$(echo '${{ matrix.os }}' | sed 's|[:/]|_|g')" >>"$GITHUB_ENV"
153
154       - name: Run tests with default settings
155         run: sh .github/workflows/test/run.sh default
156
157       - name: Run tests without legacy protocol
158         run: sh .github/workflows/test/run.sh nolegacy
159
160       - name: Upload test results
161         uses: actions/upload-artifact@v2
162         with:
163           name: tests_${{ env.TEST_ARTIFACT }}
164           path: /tmp/tests.*.tar.gz
165         if: always()
166
167   deb-build:
168     if: startsWith(github.ref, 'refs/tags/release-')
169     needs: linux
170
171     strategy:
172       matrix:
173         os: [ubuntu-18.04, ubuntu-20.04]
174
175     runs-on: ${{ matrix.os }}
176
177     steps:
178       - name: Checkout code
179         uses: actions/checkout@v2
180         with:
181           fetch-depth: 0
182
183       - name: Install build deps
184         run: >
185           sudo apt-get install -y --no-install-{recommends,suggests}
186           devscripts
187           git-buildpackage
188           dh-make
189           texinfo
190           libssl-dev
191           zlib1g-dev
192           liblzo2-dev
193           libncurses-dev
194           libreadline-dev
195           libminiupnpc-dev
196
197       - name: Configure project
198         run: autoreconf -fsi
199
200       - name: Prepare debian directory
201         run: bash .github/workflows/deb/prepare.sh
202         env:
203           JOB_DISTRIBUTION: ${{ matrix.os }}
204
205       - name: Build deb package
206         run: |
207           dpkg-buildpackage -d -us -uc
208           mv ../*.deb .
209
210       - name: Upload packages
211         uses: actions/upload-artifact@v2
212         with:
213           name: deb-${{ matrix.os }}
214           path: "*.deb"
215
216   deb-publish:
217     needs: deb-build
218
219     strategy:
220       matrix:
221         os: [ubuntu-18.04, ubuntu-20.04]
222
223     runs-on: ${{ matrix.os }}
224
225     steps:
226       - name: Download built packages
227         uses: actions/download-artifact@v2
228         with:
229           name: deb-${{ matrix.os }}
230
231       - name: Install package
232         run: sudo apt-get install -y ./*.deb
233
234       - name: Prepare tinc configs
235         run: |
236           set -eu
237           sudo mkdir -p /etc/tinc/test/hosts
238           sudo tinc -b -n test generate-ed25519-keys
239           echo "Name test" | sudo tee /etc/tinc/test/tinc.conf
240
241       - name: Enable and start tincd
242         run: |
243           sudo systemctl start tinc@test
244           sudo tinc -n test dump reachable nodes
245
246       - name: Publish deb package
247         uses: softprops/action-gh-release@v1
248         with:
249           files: "*.deb"
250         env:
251           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
252
253   macos:
254     runs-on: macos-latest
255
256     strategy:
257       fail-fast: false
258       matrix:
259         legacy_protocol: ["", --disable-legacy-protocol]
260
261     steps:
262       - name: Checkout code
263         uses: actions/checkout@v2
264         with:
265           fetch-depth: 0
266
267       - name: Install build deps
268         run: brew install coreutils netcat automake lzo lz4 miniupnpc
269
270       - name: Configure project
271         run: |
272           autoreconf -fsi
273           ./configure --with-openssl=/usr/local/opt/openssl@1.1 --enable-{tunemu,miniupnpc} ${{ matrix.legacy_protocol }}
274
275       - name: Compile project
276         run: make -j$(sysctl -n hw.ncpu)
277
278       - name: Run tests
279         run: make check-recursive VERBOSE=1
280
281       - name: Archive test results
282         run: sudo tar -c -z -f test-results.tar.gz test/
283         if: always()
284
285       - name: Upload test results
286         uses: actions/upload-artifact@v2
287         with:
288           name: tests_${{ runner.os }}_${{ matrix.legacy_protocol }}
289           path: test-results.tar.gz
290         if: always()
291
292   windows:
293     runs-on: windows-latest
294
295     strategy:
296       fail-fast: false
297       matrix:
298         legacy_protocol: ["", --disable-legacy-protocol]
299
300     steps:
301       - name: Checkout code
302         uses: actions/checkout@v2
303         with:
304           fetch-depth: 0
305
306       - name: Install msys2
307         uses: msys2/setup-msys2@v2
308         with:
309           update: true
310           # https://packages.msys2.org/package/
311           install: >-
312             base-devel
313             mingw-w64-x86_64-gcc
314             mingw-w64-x86_64-openssl
315             mingw-w64-x86_64-zlib
316             mingw-w64-x86_64-lzo2
317             mingw-w64-x86_64-lz4
318             mingw-w64-x86_64-ncurses
319             mingw-w64-x86_64-miniupnpc
320             git
321             netcat
322             procps
323
324       - name: Configure project
325         shell: msys2 {0}
326         run: |
327           autoreconf -fsi
328           ./configure --enable-miniupnpc --disable-readline --with-curses-include=/mingw64/include/ncurses ${{ matrix.legacy_protocol }}
329
330       - name: Compile project
331         shell: msys2 {0}
332         run: make -j$(nproc)
333
334       - name: Run tests
335         shell: msys2 {0}
336         run: make check-recursive VERBOSE=1
337
338       - name: Archive test results
339         shell: msys2 {0}
340         run: tar -c -z -f test-results.tar.gz test/
341         if: always()
342
343       - name: Upload test results
344         uses: actions/upload-artifact@v2
345         with:
346           name: tests_${{ runner.os }}_${{ matrix.legacy_protocol }}
347           path: test-results.tar.gz
348         if: always()