CI: Install and use OpenSSL 1.1 on CentOS 7.
[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   code-style:
12     runs-on: ubuntu-latest
13     steps:
14       - name: Checkout code
15         uses: actions/checkout@v2
16
17       - name: Install code formatting tools
18         run: |
19           sudo apt-get install -y astyle
20           curl -OL 'https://github.com/koalaman/shellcheck/releases/download/v0.7.2/shellcheck-v0.7.2.linux.x86_64.tar.xz'
21           tar -C ~ --strip-components=1 --wildcards -xf ./shellcheck-*.tar.xz 'shellcheck-*/shellcheck'
22           curl -o ~/shfmt -L 'https://github.com/mvdan/sh/releases/download/v3.3.0/shfmt_v3.3.0_linux_amd64'
23           chmod 755 ~/shfmt ~/shellcheck
24
25       - name: Check code formatting
26         run: "! astyle -r --options=.astylerc --dry-run --formatted '*.c' '*.h' | grep '^Formatted'"
27
28       - name: Check scripts formatting
29         run: find -type f -regextype egrep -regex '.+\.(sh|sh\.in|test)$' -exec ~/shfmt -d -i 2 -s '{}' +
30         if: always()
31
32       - name: Run static analysis on scripts
33         run: find -type f -regextype egrep -regex '.+\.sh(\.in)?$' -exec shellcheck -x '{}' +
34         if: always()
35
36       - name: Prepare test library and run static analysis on tests
37         run: |
38           autoreconf -fsi
39           ./configure --disable-{lzo,readline,zlib,curses}
40           find -type f -name '*.test' -execdir shellcheck -x '{}' +
41         if: always()
42
43   sanitizer:
44     runs-on: ubuntu-latest
45     strategy:
46       fail-fast: false
47       matrix:
48         sanitizer:
49           - thread
50           - undefined
51     env:
52       SANITIZER: "${{ matrix.sanitizer }}"
53
54     steps:
55       - name: Checkout code
56         uses: actions/checkout@v2
57         with:
58           fetch-depth: 0
59
60       - name: Install deps
61         shell: bash
62         run: >
63           sudo apt-get install -y
64           git binutils make autoconf automake diffutils texinfo netcat
65           zlib1g-dev lib{ssl,lzo2,ncurses,readline,vdeplug,miniupnpc}-dev
66
67       - name: Configure and compile
68         shell: bash
69         run: bash .github/workflows/sanitizers/build.sh
70         env:
71           CC: clang-12
72
73       - name: Run tests
74         run: bash .github/workflows/sanitizers/run.sh
75
76       - name: Archive test results
77         run: sudo tar -c -z -f test-results.tar.gz test/ sanitizer/
78         if: always()
79
80       - name: Upload test results
81         uses: actions/upload-artifact@v2
82         with:
83           name: tests_sanitizer_${{ matrix.sanitizer }}
84           path: test-results.tar.gz
85         if: always()
86
87   linux:
88     runs-on: ubuntu-latest
89     strategy:
90       fail-fast: false
91       matrix:
92         os:
93           - alpine:3.13
94           - centos:7 # aka RHEL 7
95           - almalinux:8 # aka RHEL 8
96           - debian:oldstable
97           - debian:stable
98           - debian:testing
99           - debian:unstable
100           - ubuntu:18.04 # previous LTS
101           - ubuntu:20.04 # current LTS
102           - opensuse/leap # aka SLES
103     container:
104       image: ${{ matrix.os }}
105       options: --privileged
106
107     steps:
108       - name: Install deps (Alpine)
109         run: >
110           apk add git binutils make autoconf automake gcc linux-headers libtool
111           diffutils texinfo procps openssl-dev zlib-dev lzo-dev ncurses-dev
112           readline-dev musl-dev lz4-dev socat
113         if: startsWith(matrix.os, 'alpine')
114
115       - name: Install deps (Debian and Ubuntu)
116         shell: bash
117         run: |
118           apt-get update
119           apt-get install -y git binutils make autoconf automake gcc diffutils \
120             texinfo netcat procps socat zlib1g-dev lib{ssl,lzo2,lz4,ncurses,readline}-dev
121         env:
122           DEBIAN_FRONTEND: noninteractive
123         if: startsWith(matrix.os, 'debian') || startsWith(matrix.os, 'ubuntu')
124
125       - name: Install deps (RHEL)
126         shell: bash
127         run: |
128           if type dnf 2>/dev/null; then
129             dnf install -y 'dnf-command(config-manager)'
130             dnf config-manager --enable powertools
131           fi
132           yum install -y epel-release
133           yum install -y git binutils make autoconf automake gcc diffutils \
134             texinfo netcat procps socat {lzo,zlib,lz4,ncurses,readline}-devel
135           yum install openssl11-devel || yum install openssl-devel
136         if: startsWith(matrix.os, 'centos') || startsWith(matrix.os, 'alma')
137
138       - name: Install deps (SUSE)
139         shell: bash
140         run: >
141           zypper install -y tar git binutils make autoconf automake gcc procps
142           makeinfo diffutils gzip socat {openssl,zlib,lzo,liblz4,ncurses,readline}-devel
143         if: startsWith(matrix.os, 'opensuse')
144
145       - name: Checkout code
146         uses: actions/checkout@v2
147         with:
148           fetch-depth: 0
149
150       - name: Assign name for test results artifact
151         run: echo TEST_ARTIFACT="$(echo '${{ matrix.os }}' | sed 's|[:/]|_|g')" >>"$GITHUB_ENV"
152
153       - name: Run tests with default settings
154         run: sh .github/workflows/test/run.sh default
155
156       - name: Run tests without legacy protocol
157         run: sh .github/workflows/test/run.sh nolegacy
158
159       - name: Upload test results
160         uses: actions/upload-artifact@v2
161         with:
162           name: tests_${{ env.TEST_ARTIFACT }}
163           path: /tmp/tests.*.tar.gz
164         if: always()
165
166   deb-build:
167     if: startsWith(github.ref, 'refs/tags/release-')
168     needs: linux
169
170     strategy:
171       matrix:
172         os: [ubuntu-18.04, ubuntu-20.04]
173
174     runs-on: ${{ matrix.os }}
175
176     steps:
177       - name: Checkout code
178         uses: actions/checkout@v2
179         with:
180           fetch-depth: 0
181
182       - name: Install build deps
183         run: >
184           sudo apt-get install -y --no-install-{recommends,suggests}
185           devscripts
186           git-buildpackage
187           dh-make
188           texinfo
189           libssl-dev
190           zlib1g-dev
191           liblzo2-dev
192           libncurses-dev
193           libreadline-dev
194           libminiupnpc-dev
195
196       - name: Configure project
197         run: autoreconf -fsi
198
199       - name: Prepare debian directory
200         run: bash .github/workflows/deb/prepare.sh
201         env:
202           JOB_DISTRIBUTION: ${{ matrix.os }}
203
204       - name: Build deb package
205         run: |
206           dpkg-buildpackage -d -us -uc
207           mv ../*.deb .
208
209       - name: Upload packages
210         uses: actions/upload-artifact@v2
211         with:
212           name: deb-${{ matrix.os }}
213           path: "*.deb"
214
215   deb-publish:
216     needs: deb-build
217
218     strategy:
219       matrix:
220         os: [ubuntu-18.04, ubuntu-20.04]
221
222     runs-on: ${{ matrix.os }}
223
224     steps:
225       - name: Download built packages
226         uses: actions/download-artifact@v2
227         with:
228           name: deb-${{ matrix.os }}
229
230       - name: Install package
231         run: sudo apt-get install -y ./*.deb
232
233       - name: Prepare tinc configs
234         run: |
235           set -eu
236           sudo mkdir -p /etc/tinc/test/hosts
237           sudo tinc -b -n test generate-ed25519-keys
238           echo "Name test" | sudo tee /etc/tinc/test/tinc.conf
239
240       - name: Enable and start tincd
241         run: |
242           sudo systemctl start tinc@test
243           sudo tinc -n test dump reachable nodes
244
245       - name: Publish deb package
246         uses: softprops/action-gh-release@v1
247         with:
248           files: "*.deb"
249         env:
250           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
251
252   macos:
253     runs-on: macos-latest
254
255     strategy:
256       fail-fast: false
257       matrix:
258         legacy_protocol: ["", --disable-legacy-protocol]
259
260     steps:
261       - name: Checkout code
262         uses: actions/checkout@v2
263         with:
264           fetch-depth: 0
265
266       - name: Install build deps
267         run: brew install coreutils netcat automake lzo lz4 miniupnpc
268
269       - name: Configure project
270         run: |
271           autoreconf -fsi
272           ./configure --with-openssl=/usr/local/opt/openssl@1.1 --enable-{tunemu,miniupnpc} ${{ matrix.legacy_protocol }}
273
274       - name: Compile project
275         run: make -j$(sysctl -n hw.ncpu)
276
277       - name: Run tests
278         run: make check-recursive VERBOSE=1
279
280       - name: Archive test results
281         run: sudo tar -c -z -f test-results.tar.gz test/
282         if: always()
283
284       - name: Upload test results
285         uses: actions/upload-artifact@v2
286         with:
287           name: tests_${{ runner.os }}_${{ matrix.legacy_protocol }}
288           path: test-results.tar.gz
289         if: always()
290
291   windows:
292     runs-on: windows-latest
293
294     strategy:
295       fail-fast: false
296       matrix:
297         legacy_protocol: ["", --disable-legacy-protocol]
298
299     steps:
300       - name: Checkout code
301         uses: actions/checkout@v2
302         with:
303           fetch-depth: 0
304
305       - name: Install msys2
306         uses: msys2/setup-msys2@v2
307         with:
308           update: true
309           # https://packages.msys2.org/package/
310           install: >-
311             base-devel
312             mingw-w64-x86_64-gcc
313             mingw-w64-x86_64-openssl
314             mingw-w64-x86_64-zlib
315             mingw-w64-x86_64-lzo2
316             mingw-w64-x86_64-lz4
317             mingw-w64-x86_64-ncurses
318             mingw-w64-x86_64-miniupnpc
319             git
320             netcat
321             procps
322
323       - name: Configure project
324         shell: msys2 {0}
325         run: |
326           autoreconf -fsi
327           ./configure --enable-miniupnpc --disable-readline --with-curses-include=/mingw64/include/ncurses ${{ matrix.legacy_protocol }}
328
329       - name: Compile project
330         shell: msys2 {0}
331         run: make -j$(nproc)
332
333       - name: Run tests
334         shell: msys2 {0}
335         run: make check-recursive VERBOSE=1
336
337       - name: Archive test results
338         shell: msys2 {0}
339         run: tar -c -z -f test-results.tar.gz test/
340         if: always()
341
342       - name: Upload test results
343         uses: actions/upload-artifact@v2
344         with:
345           name: tests_${{ runner.os }}_${{ matrix.legacy_protocol }}
346           path: test-results.tar.gz
347         if: always()