CI: run tests with libgcrypt.
[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           - mips
20
21     container:
22       image: debian:buster
23       options: --privileged
24
25     steps:
26       - name: Checkout code
27         uses: actions/checkout@v1
28
29       - name: Install deps
30         run: HOST=${{ matrix.arch }} sh .ci/deps.sh
31
32       - name: Prepare the system
33         run: |
34           sh .ci/test/prepare.sh
35           rm -f /dev/net/tun
36
37       - name: Run tests with default settings
38         run: sudo -u build CI=1 HOST=${{ matrix.arch }} sh .ci/test/run.sh default
39
40       - name: Run tests without legacy protocol
41         run: sudo -u build CI=1 HOST=${{ matrix.arch }} sh .ci/test/run.sh nolegacy
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_${{ env.ARTIFACT }}
50           path: /tmp/logs/tests.*.tar.gz
51         if: always()
52
53   static-analysis:
54     runs-on: ubuntu-latest
55     timeout-minutes: 10
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           pip3 install --user compiledb
69         env:
70           CLANG: 11
71           SHELLCHECK: 0.7.2
72           SHFMT: 3.3.0
73
74       - name: Install deps
75         run: sudo sh .ci/deps.sh
76
77       - name: Configure and compile
78         run: |
79           autoreconf -fsi
80           ./configure $(sh .ci/conf.sh)
81
82       - name: Run clang-tidy
83         run: sh .ci/tidy/run.sh
84         if: always()
85
86       - name: Check code formatting
87         run: "! astyle -r --options=.astylerc --dry-run --formatted '*.c' '*.h' | grep '^Formatted'"
88         if: always()
89
90       - name: Check scripts formatting
91         run: find -type f -regextype egrep -regex '.+\.(sh|sh\.in|test)$' -exec ~/shfmt -d -i 2 -s '{}' +
92         if: always()
93
94       - name: Run static analysis on scripts
95         run: find -type f -regextype egrep -regex '.+\.sh(\.in)?$' -exec shellcheck -x '{}' +
96         if: always()
97
98       - name: Run static analysis on tests
99         run: find -type f -name '*.test' -execdir shellcheck -x '{}' +
100         if: always()
101
102       - name: Check warnings (gcc)
103         run: bash .ci/warn/run.sh
104         env:
105           CC: gcc
106         if: always()
107
108       - name: Check warnings (clang)
109         run: bash .ci/warn/run.sh
110         env:
111           CC: clang
112         if: always()
113
114   sanitizer:
115     runs-on: ubuntu-latest
116     timeout-minutes: 20
117     strategy:
118       fail-fast: false
119       matrix:
120         sanitizer:
121           - address
122           - thread
123           - undefined
124     env:
125       SANITIZER: "${{ matrix.sanitizer }}"
126
127     steps:
128       - name: Checkout code
129         uses: actions/checkout@v1
130
131       - name: Install deps
132         run: sudo sh .ci/deps.sh
133
134       - name: Configure and compile
135         shell: bash
136         run: bash .ci/sanitizers/build.sh
137         env:
138           CC: clang-12
139
140       - name: Run tests
141         run: bash .ci/sanitizers/run.sh
142
143       - name: Archive test results
144         run: sudo tar -c -z -f test-results.tar.gz test/ sanitizer/
145         if: always()
146
147       - name: Upload test results
148         uses: actions/upload-artifact@v2
149         with:
150           name: tests_sanitizer_${{ matrix.sanitizer }}
151           path: test-results.tar.gz
152         if: always()
153
154   linux:
155     runs-on: ubuntu-latest
156     timeout-minutes: 20
157     strategy:
158       fail-fast: false
159       matrix:
160         os:
161           - alpine
162           - centos:7 # aka RHEL 7
163           - almalinux:8 # aka RHEL 8
164           - fedora
165           - debian:buster
166           - debian:bullseye
167           - debian:testing
168           - ubuntu # current LTS
169           - ubuntu:rolling # latest
170     container:
171       image: ${{ matrix.os }}
172       options: --privileged
173       env:
174         CI: 1
175     steps:
176       - name: Checkout code
177         uses: actions/checkout@v1
178
179       - name: Install deps
180         run: sh .ci/deps.sh
181
182       - name: Assign name for test results artifact
183         run: echo ARTIFACT="$(echo '${{ matrix.os }}' | sed 's|[:/]|_|g')" >>"$GITHUB_ENV"
184
185       - name: Create a non-privileged user
186         run: sh .ci/test/prepare.sh
187
188       - name: Run tests with default settings
189         run: sudo -u build CI=1 sh .ci/test/run.sh default
190
191       - name: Run tests without legacy protocol
192         run: sudo -u build CI=1 sh .ci/test/run.sh nolegacy
193
194       - name: Run tests with libgcrypt
195         run: sudo -u build CI=1 sh .ci/test/run.sh gcrypt
196
197       - name: Upload test results
198         uses: actions/upload-artifact@v2
199         with:
200           name: tests_${{ env.ARTIFACT }}
201           path: /tmp/logs/tests.*.tar.gz
202         if: always()
203
204       - name: Build package
205         run: sh .ci/package/build.sh
206         if: github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-')
207
208       - name: Upload package
209         uses: actions/upload-artifact@v2
210         with:
211           name: pkg-${{ env.ARTIFACT }}
212           path: |
213             *.deb
214             ~/rpmbuild/RPMS/*/*.rpm
215
216   pkg-publish:
217     if: always() && (github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-'))
218     runs-on: ubuntu-latest
219     needs:
220       - linux
221       - windows
222
223     steps:
224       - name: Create artifact directory
225         run: mkdir -p /tmp/artifacts
226
227       - name: Download packages
228         uses: actions/download-artifact@v2
229         with:
230           path: /tmp/artifacts
231
232       - name: Publish packages (dev)
233         uses: marvinpinto/action-automatic-releases@latest
234         with:
235           repo_token: ${{ secrets.GITHUB_TOKEN }}
236           automatic_release_tag: latest
237           title: Development release
238           prerelease: true
239           files: /tmp/artifacts/**/*.(deb|rpm|exe)
240         if: startsWith(github.ref, 'refs/heads/')
241
242       - name: Publish packages (release)
243         uses: softprops/action-gh-release@v1
244         with:
245           files: |
246             /tmp/artifacts/**/*.deb
247             /tmp/artifacts/**/*.rpm
248             /tmp/artifacts/**/*.exe
249         if: startsWith(github.ref, 'refs/tags/')
250
251   macos:
252     runs-on: macos-latest
253     timeout-minutes: 20
254
255     steps:
256       - name: Checkout code
257         uses: actions/checkout@v1
258
259       - name: Install build deps
260         run: sh .ci/deps.sh
261
262       - name: Run tests with default settings
263         run: sh .ci/test/run.sh default
264
265       - name: Run clang-tidy
266         run: |
267           export PATH="$PATH:$(brew --prefix llvm)/bin:$HOME/Library/Python/3.9/bin"
268           sh .ci/tidy/run.sh
269
270       - name: Run tests without legacy protocol
271         run: sh .ci/test/run.sh nolegacy
272
273       - name: Run tests with libgcrypt
274         run: sh .ci/test/run.sh gcrypt
275
276       - name: Upload test results
277         uses: actions/upload-artifact@v2
278         with:
279           name: tests_macos
280           path: /tmp/logs/tests.*.tar.gz
281         if: always()
282
283   windows:
284     runs-on: windows-latest
285     timeout-minutes: 30
286
287     steps:
288       - name: Install msys2
289         uses: msys2/setup-msys2@v2
290         with:
291           update: true
292           # https://packages.msys2.org/package/
293           install: >-
294             base-devel
295             mingw-w64-x86_64-gcc
296             mingw-w64-x86_64-openssl
297             mingw-w64-x86_64-libgcrypt
298             mingw-w64-x86_64-zlib
299             mingw-w64-x86_64-lzo2
300             mingw-w64-x86_64-lz4
301             mingw-w64-x86_64-ncurses
302             mingw-w64-x86_64-miniupnpc
303             mingw-w64-x86_64-nsis
304             git
305             netcat
306             procps
307
308       - name: Checkout code
309         uses: actions/checkout@v1
310
311       - name: Run tests with default settings
312         shell: msys2 {0}
313         run: sh .ci/test/run.sh default
314
315       - name: Create installer
316         shell: msys2 {0}
317         run: sh .ci/package/build.sh
318         if: github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-')
319
320       - name: Upload package
321         uses: actions/upload-artifact@v2
322         with:
323           name: pkg-windows
324           path: .ci/package/win/tinc-*.exe
325
326       - name: Run tests without legacy protocol
327         shell: msys2 {0}
328         run: sh .ci/test/run.sh nolegacy
329
330       - name: Run tests with libgcrypt
331         shell: msys2 {0}
332         run: sh .ci/test/run.sh gcrypt
333
334       - name: Upload test results
335         uses: actions/upload-artifact@v2
336         with:
337           name: tests_windows
338           path: /tmp/logs/tests.*.tar.gz
339         if: always()