f9b39eb2822a001d1159f75e6f7149efc1406b08
[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   cross:
12     runs-on: ubuntu-latest
13     timeout-minutes: 30
14     strategy:
15       fail-fast: false
16       matrix:
17         arch:
18           - armhf
19           - mipsel
20           - mingw
21
22     container:
23       image: debian:bullseye
24       options: --privileged
25
26     steps:
27       - name: Checkout code
28         uses: actions/checkout@v1
29
30       - name: Install deps
31         run: HOST=${{ matrix.arch }} sh .ci/deps.sh
32
33       - name: Prepare the system
34         run: HOST=${{ matrix.arch }} sh .ci/test/prepare.sh
35
36       - name: Run tests with default settings
37         run: sudo -u build CI=1 HOST=${{ matrix.arch }} sh .ci/test/run.sh default
38
39       - name: Run tests without legacy protocol
40         run: sudo -u build CI=1 HOST=${{ matrix.arch }} sh .ci/test/run.sh nolegacy
41         if: always()
42
43       - name: Run tests with libgcrypt
44         run: sudo -u build CI=1 HOST=${{ matrix.arch }} sh .ci/test/run.sh gcrypt
45
46       - name: Upload test results
47         uses: actions/upload-artifact@v2
48         with:
49           name: tests_cross_${{ matrix.arch }}
50           path: /tmp/logs/tests.*.tar.gz
51         if: always()
52
53   static-analysis:
54     runs-on: ubuntu-latest
55     timeout-minutes: 30
56     steps:
57       - name: Checkout code
58         uses: actions/checkout@v1
59
60       - name: Install tools
61         run: |
62           sudo apt-get install -y astyle clang-tidy-$CLANG
63           sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$CLANG 100
64           curl -OL "https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK/shellcheck-v${SHELLCHECK}.linux.x86_64.tar.xz"
65           tar -C ~ --strip-components=1 --wildcards -xf ./shellcheck-*.tar.xz 'shellcheck-*/shellcheck'
66           curl -o ~/shfmt -L "https://github.com/mvdan/sh/releases/download/v$SHFMT/shfmt_v${SHFMT}_linux_amd64"
67           chmod 755 ~/shfmt ~/shellcheck
68           python3 -m venv /tmp/venv
69           . /tmp/venv/bin/activate
70           pip3 install black pylint mypy
71         env:
72           CLANG: 11
73           SHELLCHECK: 0.7.2
74           SHFMT: 3.3.0
75
76       - name: Install deps
77         run: sudo SKIP_OPENSSL3=1 sh .ci/deps.sh
78
79       - name: Lint/typecheck/check formatting on C/shell/Python code
80         run: |
81           . /tmp/venv/bin/activate
82           PATH=$PATH:$HOME ./lint.py
83         if: always()
84
85       - name: Run clang-tidy
86         run: sh .ci/tidy/run.sh
87         if: always()
88
89       - name: Check warnings (gcc)
90         run: bash .ci/warn/run.sh
91         env:
92           CC: gcc-10
93         if: always()
94
95       - name: Check warnings (clang)
96         run: bash .ci/warn/run.sh
97         env:
98           CC: clang-12
99         if: always()
100
101   sanitizer:
102     runs-on: ubuntu-latest
103     timeout-minutes: 30
104     strategy:
105       fail-fast: false
106       matrix:
107         sanitizer:
108           - address
109           - thread
110           - undefined
111     env:
112       SANITIZER: "${{ matrix.sanitizer }}"
113
114     steps:
115       - name: Checkout code
116         uses: actions/checkout@v1
117
118       - name: Install deps
119         run: sudo sh .ci/deps.sh
120
121       - name: Run tests with OpenSSL 3
122         run: bash .ci/sanitizers/run.sh openssl3
123
124       - name: Sanitize tests with default settings
125         run: bash .ci/sanitizers/run.sh default
126
127       - name: Sanitize tests without legacy protocol
128         run: bash .ci/sanitizers/run.sh nolegacy
129         if: always()
130
131       - name: Upload test results
132         uses: actions/upload-artifact@v2
133         with:
134           name: tests_sanitizer_${{ matrix.sanitizer }}
135           path: /tmp/logs/tests.*.tar.gz
136         if: always()
137
138   linux:
139     runs-on: ubuntu-latest
140     timeout-minutes: 30
141     strategy:
142       fail-fast: false
143       matrix:
144         os:
145           - alpine
146           - centos:7 # aka RHEL 7
147           - almalinux:8 # aka RHEL 8
148           - fedora
149           - debian:buster
150           - debian:bullseye
151           - debian:testing
152           - ubuntu # current LTS
153           - ubuntu:rolling # latest
154     container:
155       image: ${{ matrix.os }}
156       options: --privileged
157       env:
158         CI: 1
159     steps:
160       - name: Checkout code
161         uses: actions/checkout@v1
162
163       - name: Install deps
164         run: sh .ci/deps.sh
165
166       - name: Assign name for test results artifact
167         run: echo ARTIFACT="$(echo '${{ matrix.os }}' | sed 's|[:/]|_|g')" >>"$GITHUB_ENV"
168
169       - name: Create a non-privileged user
170         run: sh .ci/test/prepare.sh
171
172       - name: Run tests with OpenSSL 3
173         run: sudo -u build CI=1 sh .ci/test/run.sh openssl3
174
175       - name: Run tests with default settings
176         run: sudo -u build CI=1 sh .ci/test/run.sh default
177
178       - name: Run tests without legacy protocol
179         run: sudo -u build CI=1 sh .ci/test/run.sh nolegacy
180         if: always()
181
182       - name: Run tests with libgcrypt
183         run: sudo -u build CI=1 sh .ci/test/run.sh gcrypt
184
185       - name: Upload test results
186         uses: actions/upload-artifact@v2
187         with:
188           name: tests_${{ env.ARTIFACT }}
189           path: /tmp/logs/tests.*.tar.gz
190         if: always()
191
192       - name: Build package
193         run: sh .ci/package/build.sh
194         if: github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-')
195
196       - name: Upload package
197         uses: actions/upload-artifact@v2
198         with:
199           name: pkg-${{ env.ARTIFACT }}
200           path: |
201             *.deb
202             ~/rpmbuild/RPMS/*/*.rpm
203
204   pkg-publish:
205     if: always() && (github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-'))
206     runs-on: ubuntu-latest
207     needs:
208       - linux
209       - mingw
210
211     steps:
212       - name: Create artifact directory
213         run: mkdir -p /tmp/artifacts
214
215       - name: Download packages
216         uses: actions/download-artifact@v2
217         with:
218           path: /tmp/artifacts
219
220       - name: Publish packages (dev)
221         uses: marvinpinto/action-automatic-releases@latest
222         with:
223           repo_token: ${{ secrets.GITHUB_TOKEN }}
224           automatic_release_tag: latest
225           title: Development release
226           prerelease: true
227           files: /tmp/artifacts/**/*.(deb|rpm|exe)
228         if: startsWith(github.ref, 'refs/heads/')
229
230       - name: Publish packages (release)
231         uses: softprops/action-gh-release@v1
232         with:
233           files: |
234             /tmp/artifacts/**/*.deb
235             /tmp/artifacts/**/*.rpm
236             /tmp/artifacts/**/*.exe
237         if: startsWith(github.ref, 'refs/tags/')
238
239   macos:
240     runs-on: macos-latest
241     timeout-minutes: 20
242
243     steps:
244       - name: Checkout code
245         uses: actions/checkout@v1
246
247       - name: Install build deps
248         run: sh .ci/deps.sh
249
250       - name: Run tests with default settings
251         run: sh .ci/test/run.sh default
252
253       - name: Run tests without legacy protocol
254         run: sh .ci/test/run.sh nolegacy
255         if: always()
256
257       - name: Run tests with libgcrypt
258         run: sh .ci/test/run.sh gcrypt
259
260       - name: Upload test results
261         uses: actions/upload-artifact@v2
262         with:
263           name: tests_macos
264           path: /tmp/logs/tests.*.tar.gz
265         if: always()
266
267   mingw:
268     runs-on: windows-latest
269     timeout-minutes: 30
270
271     steps:
272       - name: Install msys2
273         uses: msys2/setup-msys2@v2
274         with:
275           update: true
276           # https://packages.msys2.org/package/
277           install: >-
278             base-devel
279             mingw-w64-x86_64-meson
280             mingw-w64-x86_64-pkgconf
281             mingw-w64-x86_64-gcc
282             mingw-w64-x86_64-openssl
283             mingw-w64-x86_64-libgcrypt
284             mingw-w64-x86_64-zlib
285             mingw-w64-x86_64-lzo2
286             mingw-w64-x86_64-lz4
287             mingw-w64-x86_64-ncurses
288             mingw-w64-x86_64-miniupnpc
289             mingw-w64-x86_64-nsis
290             git
291             openbsd-netcat
292             procps
293
294       - name: Checkout code
295         uses: actions/checkout@v1
296
297       - name: Run tests with default settings
298         shell: msys2 {0}
299         run: sh .ci/test/run.sh default
300
301       - name: Create installer
302         shell: msys2 {0}
303         run: sh .ci/package/build.sh
304         if: github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-')
305
306       - name: Upload package
307         uses: actions/upload-artifact@v2
308         with:
309           name: pkg-windows
310           path: .ci/package/win/tinc-*.exe
311
312       - name: Run tests without legacy protocol
313         shell: msys2 {0}
314         run: sh .ci/test/run.sh nolegacy
315         if: always()
316
317       - name: Run tests with libgcrypt
318         shell: msys2 {0}
319         run: sh .ci/test/run.sh gcrypt
320
321       - name: Upload test results
322         uses: actions/upload-artifact@v2
323         with:
324           name: tests_windows
325           path: /tmp/logs/tests.*.tar.gz
326         if: always()
327
328   msvc:
329     runs-on: windows-latest
330     timeout-minutes: 30
331
332     strategy:
333       fail-fast: false
334       matrix:
335         target:
336           - { build: amd64, host: amd64, test: test }
337           - { build: amd64, host: x86, test: test }
338           - { build: amd64, host: arm64, test: notest }
339
340     env:
341       HOST_ARCH: ${{ matrix.target.host }}
342       BUILD_ARCH: ${{ matrix.target.build }}
343
344     steps:
345       - name: Install meson
346         run: pip3 install meson
347
348       - name: Checkout code
349         uses: actions/checkout@v1
350
351       - name: Activate dev environment
352         uses: ilammy/msvc-dev-cmd@v1
353         with:
354           arch: ${{ matrix.target.build == matrix.target.host && matrix.target.host || format('{0}_{1}', matrix.target.build, matrix.target.host) }}
355
356       - name: Build (nolegacy)
357         run: .ci\windows\build.cmd nolegacy
358
359       - name: Test (nolegacy)
360         run: .ci\windows\test.cmd nolegacy
361         if: always() && matrix.target.test == 'test'
362
363       - name: Build (OpenSSL)
364         run: .ci\windows\build.cmd openssl
365         if: always()
366
367       - name: Test (OpenSSL)
368         run: .ci\windows\test.cmd openssl
369         if: always() && matrix.target.test == 'test'