Add timeouts to CI jobs.
[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
111     steps:
112       - name: Install deps (Alpine)
113         run: >
114           apk add git binutils make autoconf automake gcc linux-headers libtool
115           diffutils texinfo procps openssl-dev zlib-dev lzo-dev ncurses-dev
116           readline-dev musl-dev lz4-dev socat
117         if: startsWith(matrix.os, 'alpine')
118
119       - name: Install deps (Debian and Ubuntu)
120         shell: bash
121         run: |
122           apt-get update
123           apt-get install -y git binutils make autoconf automake gcc diffutils \
124             texinfo netcat procps socat zlib1g-dev lib{ssl,lzo2,lz4,ncurses,readline}-dev
125         env:
126           DEBIAN_FRONTEND: noninteractive
127         if: startsWith(matrix.os, 'debian') || startsWith(matrix.os, 'ubuntu')
128
129       - name: Install deps (RHEL)
130         shell: bash
131         run: |
132           if type dnf 2>/dev/null; then
133             dnf install -y 'dnf-command(config-manager)'
134             dnf config-manager --enable powertools
135           fi
136           yum install -y epel-release
137           yum install -y git binutils make autoconf automake gcc diffutils \
138             texinfo netcat procps socat {lzo,zlib,lz4,ncurses,readline}-devel
139           yum install -y openssl11-devel || yum install -y openssl-devel
140         if: startsWith(matrix.os, 'centos') || startsWith(matrix.os, 'alma')
141
142       - name: Install deps (SUSE)
143         shell: bash
144         run: >
145           zypper install -y tar git binutils make autoconf automake gcc procps
146           makeinfo diffutils gzip socat {openssl,zlib,lzo,liblz4,ncurses,readline}-devel
147         if: startsWith(matrix.os, 'opensuse')
148
149       - name: Checkout code
150         uses: actions/checkout@v2
151         with:
152           fetch-depth: 0
153
154       - name: Assign name for test results artifact
155         run: echo TEST_ARTIFACT="$(echo '${{ matrix.os }}' | sed 's|[:/]|_|g')" >>"$GITHUB_ENV"
156
157       - name: Run tests with default settings
158         run: sh .github/workflows/test/run.sh default
159
160       - name: Run tests without legacy protocol
161         run: sh .github/workflows/test/run.sh nolegacy
162
163       - name: Upload test results
164         uses: actions/upload-artifact@v2
165         with:
166           name: tests_${{ env.TEST_ARTIFACT }}
167           path: /tmp/tests.*.tar.gz
168         if: always()
169
170   deb-build:
171     if: startsWith(github.ref, 'refs/tags/release-')
172     needs: linux
173
174     strategy:
175       matrix:
176         os: [ubuntu-18.04, ubuntu-20.04]
177
178     runs-on: ${{ matrix.os }}
179     timeout-minutes: 5
180
181     steps:
182       - name: Checkout code
183         uses: actions/checkout@v2
184         with:
185           fetch-depth: 0
186
187       - name: Install build deps
188         run: >
189           sudo apt-get install -y --no-install-{recommends,suggests}
190           devscripts
191           git-buildpackage
192           dh-make
193           texinfo
194           libssl-dev
195           zlib1g-dev
196           liblzo2-dev
197           libncurses-dev
198           libreadline-dev
199           libminiupnpc-dev
200
201       - name: Configure project
202         run: autoreconf -fsi
203
204       - name: Prepare debian directory
205         run: bash .github/workflows/deb/prepare.sh
206         env:
207           JOB_DISTRIBUTION: ${{ matrix.os }}
208
209       - name: Build deb package
210         run: |
211           dpkg-buildpackage -d -us -uc
212           mv ../*.deb .
213
214       - name: Upload packages
215         uses: actions/upload-artifact@v2
216         with:
217           name: deb-${{ matrix.os }}
218           path: "*.deb"
219
220   deb-publish:
221     needs: deb-build
222
223     strategy:
224       matrix:
225         os: [ubuntu-18.04, ubuntu-20.04]
226
227     runs-on: ${{ matrix.os }}
228     timeout-minutes: 5
229
230     steps:
231       - name: Download built packages
232         uses: actions/download-artifact@v2
233         with:
234           name: deb-${{ matrix.os }}
235
236       - name: Install package
237         run: sudo apt-get install -y ./*.deb
238
239       - name: Prepare tinc configs
240         run: |
241           set -eu
242           sudo mkdir -p /etc/tinc/test/hosts
243           sudo tinc -b -n test generate-ed25519-keys
244           echo "Name test" | sudo tee /etc/tinc/test/tinc.conf
245
246       - name: Enable and start tincd
247         run: |
248           sudo systemctl start tinc@test
249           sudo tinc -n test dump reachable nodes
250
251       - name: Publish deb package
252         uses: softprops/action-gh-release@v1
253         with:
254           files: "*.deb"
255         env:
256           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
257
258   macos:
259     runs-on: macos-latest
260     timeout-minutes: 10
261
262     strategy:
263       fail-fast: false
264       matrix:
265         legacy_protocol: ["", --disable-legacy-protocol]
266
267     steps:
268       - name: Checkout code
269         uses: actions/checkout@v2
270         with:
271           fetch-depth: 0
272
273       - name: Install build deps
274         run: brew install coreutils netcat automake lzo lz4 miniupnpc
275
276       - name: Configure project
277         run: |
278           autoreconf -fsi
279           ./configure --with-openssl=/usr/local/opt/openssl@1.1 --enable-{tunemu,miniupnpc} ${{ matrix.legacy_protocol }}
280
281       - name: Compile project
282         run: make -j$(sysctl -n hw.ncpu)
283
284       - name: Run tests
285         run: make check-recursive VERBOSE=1
286
287       - name: Archive test results
288         run: sudo tar -c -z -f test-results.tar.gz test/
289         if: always()
290
291       - name: Upload test results
292         uses: actions/upload-artifact@v2
293         with:
294           name: tests_${{ runner.os }}_${{ matrix.legacy_protocol }}
295           path: test-results.tar.gz
296         if: always()
297
298   windows:
299     runs-on: windows-latest
300     timeout-minutes: 20
301
302     strategy:
303       fail-fast: false
304       matrix:
305         legacy_protocol: ["", --disable-legacy-protocol]
306
307     steps:
308       - name: Checkout code
309         uses: actions/checkout@v2
310         with:
311           fetch-depth: 0
312
313       - name: Install msys2
314         uses: msys2/setup-msys2@v2
315         with:
316           update: true
317           # https://packages.msys2.org/package/
318           install: >-
319             base-devel
320             mingw-w64-x86_64-gcc
321             mingw-w64-x86_64-openssl
322             mingw-w64-x86_64-zlib
323             mingw-w64-x86_64-lzo2
324             mingw-w64-x86_64-lz4
325             mingw-w64-x86_64-ncurses
326             mingw-w64-x86_64-miniupnpc
327             git
328             netcat
329             procps
330
331       - name: Configure project
332         shell: msys2 {0}
333         run: |
334           autoreconf -fsi
335           ./configure --enable-miniupnpc --disable-readline --with-curses-include=/mingw64/include/ncurses ${{ matrix.legacy_protocol }}
336
337       - name: Compile project
338         shell: msys2 {0}
339         run: make -j$(nproc)
340
341       - name: Run tests
342         shell: msys2 {0}
343         run: make check-recursive VERBOSE=1
344
345       - name: Archive test results
346         shell: msys2 {0}
347         run: tar -c -z -f test-results.tar.gz test/
348         if: always()
349
350       - name: Upload test results
351         uses: actions/upload-artifact@v2
352         with:
353           name: tests_${{ runner.os }}_${{ matrix.legacy_protocol }}
354           path: test-results.tar.gz
355         if: always()