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