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