db6781048cc7d30e7295968710ea64a72cfc2a68
[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: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: 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:buster
163           - debian:bullseye
164           - debian:testing
165           - ubuntu # current LTS
166           - ubuntu:rolling # latest
167     container:
168       image: ${{ matrix.os }}
169       options: --privileged
170       env:
171         CI: 1
172     steps:
173       - name: Checkout code
174         uses: actions/checkout@v1
175
176       - name: Install deps
177         run: sh .ci/deps.sh
178
179       - name: Assign name for test results artifact
180         run: echo ARTIFACT="$(echo '${{ matrix.os }}' | sed 's|[:/]|_|g')" >>"$GITHUB_ENV"
181
182       - name: Create a non-privileged user
183         run: sh .ci/test/prepare.sh
184
185       - name: Run tests with default settings
186         run: sudo -u build CI=1 sh .ci/test/run.sh default
187
188       - name: Run tests without legacy protocol
189         run: sudo -u build CI=1 sh .ci/test/run.sh nolegacy
190
191       - name: Upload test results
192         uses: actions/upload-artifact@v2
193         with:
194           name: tests_${{ env.ARTIFACT }}
195           path: /tmp/logs/tests.*.tar.gz
196         if: always()
197
198       - name: Build package
199         run: sh .ci/package/build.sh
200         if: github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-')
201
202       - name: Upload package
203         uses: actions/upload-artifact@v2
204         with:
205           name: pkg-${{ env.ARTIFACT }}
206           path: |
207             *.deb
208             ~/rpmbuild/RPMS/*/*.rpm
209
210   pkg-publish:
211     if: always() && (github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-'))
212     runs-on: ubuntu-latest
213     needs:
214       - linux
215       - windows
216
217     steps:
218       - name: Create artifact directory
219         run: mkdir -p /tmp/artifacts
220
221       - name: Download packages
222         uses: actions/download-artifact@v2
223         with:
224           path: /tmp/artifacts
225
226       - name: Publish packages (dev)
227         uses: marvinpinto/action-automatic-releases@latest
228         with:
229           repo_token: ${{ secrets.GITHUB_TOKEN }}
230           automatic_release_tag: latest
231           title: Development release
232           prerelease: true
233           files: /tmp/artifacts/**/*.(deb|rpm|exe)
234         if: startsWith(github.ref, 'refs/heads/')
235
236       - name: Publish packages (release)
237         uses: softprops/action-gh-release@v1
238         with:
239           files: |
240             /tmp/artifacts/**/*.deb
241             /tmp/artifacts/**/*.rpm
242             /tmp/artifacts/**/*.exe
243         if: startsWith(github.ref, 'refs/tags/')
244
245   macos:
246     runs-on: macos-latest
247     timeout-minutes: 15
248
249     steps:
250       - name: Checkout code
251         uses: actions/checkout@v1
252
253       - name: Install build deps
254         run: sh .ci/deps.sh
255
256       - name: Run tests with default settings
257         run: sh .ci/test/run.sh default
258
259       - name: Run clang-tidy
260         run: |
261           export PATH="$PATH:$(brew --prefix llvm)/bin:$HOME/Library/Python/3.9/bin"
262           sh .ci/tidy/run.sh
263
264       - name: Run tests without legacy protocol
265         run: sh .ci/test/run.sh nolegacy
266
267       - name: Upload test results
268         uses: actions/upload-artifact@v2
269         with:
270           name: tests_macos
271           path: /tmp/logs/tests.*.tar.gz
272         if: always()
273
274   windows:
275     runs-on: windows-latest
276     timeout-minutes: 20
277
278     steps:
279       - name: Install msys2
280         uses: msys2/setup-msys2@v2
281         with:
282           update: true
283           # https://packages.msys2.org/package/
284           install: >-
285             base-devel
286             mingw-w64-x86_64-gcc
287             mingw-w64-x86_64-openssl
288             mingw-w64-x86_64-zlib
289             mingw-w64-x86_64-lzo2
290             mingw-w64-x86_64-lz4
291             mingw-w64-x86_64-ncurses
292             mingw-w64-x86_64-miniupnpc
293             mingw-w64-x86_64-nsis
294             git
295             netcat
296             procps
297
298       - name: Checkout code
299         uses: actions/checkout@v1
300
301       - name: Run tests with default settings
302         shell: msys2 {0}
303         run: sh .ci/test/run.sh default
304
305       - name: Create installer
306         shell: msys2 {0}
307         run: sh .ci/package/build.sh
308         if: github.ref == 'refs/heads/1.1' || startsWith(github.ref, 'refs/tags/release-')
309
310       - name: Upload package
311         uses: actions/upload-artifact@v2
312         with:
313           name: pkg-windows
314           path: .ci/package/win/tinc-*.exe
315
316       - name: Run tests without legacy protocol
317         shell: msys2 {0}
318         run: sh .ci/test/run.sh nolegacy
319
320       - name: Upload test results
321         uses: actions/upload-artifact@v2
322         with:
323           name: tests_windows
324           path: /tmp/logs/tests.*.tar.gz
325         if: always()