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