125b99b5d1f535509aadec14ecdae9288dc00b38
[quassel.git] / .github / workflows / main.yml
1 # Workflow that builds Quassel on various Linux distros, and creates packages for both Windows and macOS.
2 # For tagged pushes, a draft release is automatically created, using the tag message as release description
3 # and attaching Windows and macOS builds, as well as the source archive.
4 name: Quassel CI
5
6 on: [ push, pull_request ]
7
8 defaults:
9   run:
10     shell: bash
11
12 jobs:
13
14 # ------------------------------------------------------------------------------------------------------------------------------------------
15   build-linux:
16     name: Linux
17     runs-on: ubuntu-latest
18     container: quassel/quassel-build-env:${{ matrix.dist }}
19     strategy:
20       fail-fast: false
21       matrix:
22         dist: [ debian-stable, debian-testing, ubuntu-xenial, ubuntu-bionic, ubuntu-focal, ubuntu-groovy ]
23         cxx: [ 'g++', 'clang++' ]
24         with-kde: [ -DWITH_KDE=ON ]
25         extra-options: [ -DWITH_WEBENGINE=ON ]
26         include:
27           # Baseline, test more combinations
28           - dist: ubuntu-xenial
29             with-kde: -DWITH_KDE=OFF
30             extra-options: -DWITH_WEBKIT=ON
31           - dist: ubuntu-xenial
32             with-kde: -DWITH_KDE=ON
33             extra-options: -DWITH_WEBKIT=ON
34         exclude:
35           # QtWebEngine is not available on Xenial
36           - dist: ubuntu-xenial
37             extra-options: -DWITH_WEBENGINE=ON
38     env:
39         CCACHE_BASEDIR: ${{ github.workspace }}
40         CCACHE_DIR: ${{ github.workspace }}/ccache
41         CCACHE_MAXSIZE: 100M
42         CXX: ${{ matrix.cxx }}
43
44     steps:
45     - name: Check out source code
46       uses: actions/checkout@v2
47
48     - name: Get timestamp
49       id: get-timestamp
50       run: echo "::set-output name=timestamp::$(date -u "+%F-%R")"
51
52     - name: Setup ccache
53       uses: actions/cache@v2
54       with:
55         path: ${{ github.workspace }}/ccache
56         key: ${{ matrix.dist }}-ccache-${{ steps.get-timestamp.outputs.timestamp }}
57         restore-keys: |
58              ${{ matrix.dist }}-ccache-
59
60     - name: Zero ccache stats
61       run: ccache -z
62
63     - name: Configure
64       run: |
65         mkdir build
66         cd build && cmake $GITHUB_WORKSPACE \
67                           -GNinja \
68                           -DCMAKE_BUILD_TYPE=Release \
69                           -DBUILD_TESTING=ON \
70                           -DFATAL_WARNINGS=ON \
71                           ${{ matrix.with-kde }} \
72                           ${{ matrix.extra-options }}
73
74     - name: Build
75       run: cd build && ninja
76
77     - name: Run tests
78       run: cd build && ctest
79
80     - name: Install
81       run: cd build && DESTDIR=$GITHUB_WORKSPACE/image ninja install
82
83     - name: Print ccache stats
84       run: ccache -s
85
86 # ------------------------------------------------------------------------------------------------------------------------------------------
87   build-macos:
88     name: macOS
89     runs-on: macos-latest
90     env:
91       CCACHE_BASEDIR: ${{ github.workspace }}
92       CCACHE_DIR: ${{ github.workspace }}/ccache
93       CCACHE_MAXSIZE: 100M
94
95     steps:
96     - name: Check out source code
97       uses: actions/checkout@v2
98       with:
99         fetch-depth: 0  # so git-describe works
100
101     - name: Fetch tag information
102       if: startsWith(github.ref, 'refs/tags/')
103       run: git fetch -f origin $GITHUB_REF:$GITHUB_REF
104
105     - name: Install dependencies
106       # Skip "brew update" as it can trigger 50+ minutes of updating.
107       # GitHub Actions intentionally disables the default auto-update on their
108       # macOS CI images (and macOS CI images usually update once a week).
109       #
110       # See https://github.com/actions/virtual-environments/issues/2173
111       # > We've set no auto-update intentionally here [...]
112       # And https://github.com/microsoft/appcenter/issues/293
113       #
114       # If Homebrew begins failing in the future due to out-of-date versions,
115       # it can be re-enabled here as follows...
116       # run: brew update && [below command]
117       run: brew install boost ccache ninja qca qt5
118
119     - name: Get timestamp
120       id: get-timestamp
121       run: echo "::set-output name=timestamp::$(date -u "+%F-%R")"
122
123     - name: Setup ccache
124       uses: actions/cache@v2
125       with:
126         path: ${{ github.workspace }}/ccache
127         key: macos-ccache-${{ steps.get-timestamp.outputs.timestamp }}
128         restore-keys: |
129              macos-ccache-
130
131     - name: Zero ccache stats
132       run: ccache -z
133
134     - name: Configure
135       run: |
136         mkdir build
137         cd build && cmake $GITHUB_WORKSPACE \
138                           -GNinja \
139                           -DCMAKE_PREFIX_PATH=/usr/local/opt/qt/lib/cmake \
140                           -DCMAKE_BUILD_TYPE=Release \
141                           -DBUILD_TESTING=ON \
142                           -DFATAL_WARNINGS=OFF \
143                           -DDEPLOY=ON \
144                           -DENABLE_SHARED=OFF
145
146     - name: Build
147       run: |
148         # Deploy scripts require qmake in the path
149         export PATH=$PATH:/usr/local/opt/qt5/bin
150         cd build && ninja
151
152     - name: Run tests
153       run: cd build && ctest
154
155     - name: Install
156       run: cd build && DESTDIR=$GITHUB_WORKSPACE/image ninja install
157
158     - name: Print ccache stats
159       run: ccache -s
160
161     - name: Upload artifacts
162       uses: actions/upload-artifact@v2
163       with:
164         name: macOS
165         path: ${{ github.workspace }}/build/*.dmg
166
167 # ------------------------------------------------------------------------------------------------------------------------------------------
168   build-windows:
169     name: Windows
170     runs-on: windows-latest
171     env:
172       WORKSPACE: ${{ github.workspace }}
173       CRAFT: /C/CraftMaster/windows-msvc2019_64-cl/craft/bin/craft.py
174
175     steps:
176     - name: Check out source code
177       uses: actions/checkout@v2
178       with:
179         fetch-depth: 0  # so git-describe works
180
181     - name: Fetch tag information
182       if: startsWith(github.ref, 'refs/tags/')
183       run: git fetch -f origin $GITHUB_REF:$GITHUB_REF
184
185     - name: Clone CraftMaster
186       run: git clone --depth=1 https://invent.kde.org/kde/craftmaster.git /C/CraftMaster/CraftMaster
187
188     - name: Configure CraftMaster
189       run: python /C/CraftMaster/CraftMaster/CraftMaster.py --config $WORKSPACE/.craftsettings.ini --variables "WORKSPACE=$WORKSPACE"
190
191     - name: Add Quassel blueprint
192       run: python $CRAFT --add-blueprint-repository https://github.com/quassel/craft-blueprints-quassel.git
193
194     - name: Install NSIS
195       run: python $CRAFT dev-utils/nsis
196
197     - name: Install dependencies
198       run: python $CRAFT --install-deps quassel/quassel
199
200     - name: Build
201       run: python $CRAFT --no-cache --src-dir $WORKSPACE quassel/quassel
202
203     - name: Run tests
204       run: python $CRAFT --no-cache --src-dir $WORKSPACE --test quassel/quassel
205
206     - name: Package
207       run: python $CRAFT --no-cache --src-dir $WORKSPACE --package quassel/quassel
208
209     - name: Upload artifacts
210       uses: actions/upload-artifact@v2
211       with:
212         name: Windows
213         path: ${{ github.workspace }}/packages/*
214
215 # ------------------------------------------------------------------------------------------------------------------------------------------
216   post-build:
217     name: Post-Build
218     runs-on: ubuntu-latest
219     needs: [ build-linux, build-macos, build-windows ]
220     env:
221       GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
222
223     steps:
224     - name: Check out source code
225       uses: actions/checkout@v2
226
227     - name: Fetch tag information
228       if: startsWith(github.ref, 'refs/tags/')
229       run: git fetch -f origin $GITHUB_REF:$GITHUB_REF
230
231     - name: Download artifacts
232       uses: actions/download-artifact@v2
233       with:
234         path: artifacts
235
236     - name: List artifacts
237       run: ls -lhR artifacts
238
239     - name: Check artifacts
240       run: |
241         # Sanity check: We should have exactly 5 files matching the given patterns
242         [[ 5 -eq $(find artifacts/ \( -type f -name 'Quassel*.dmg' -o -name 'quassel*.exe' -o -name 'quassel*.7z' \) -printf '.' | wc -c) ]]
243
244     - name: Create release notes
245       if: startsWith(github.ref, 'refs/tags/')
246       run: |
247         # Use the tag's annotation as release notes
248         TAGNAME=$(git rev-parse --abbrev-ref $GITHUB_REF)
249         MESSAGE=$(git tag -l --format='%(contents)' $TAGNAME | perl -ne 'print if not /-----BEGIN PGP SIGNATURE-----/../-----END PGP SIGNATURE-----/')
250         echo -e "Quassel $TAGNAME\n\n$MESSAGE" > release_notes.txt
251
252     - name: Prepare source archive
253       if: startsWith(github.ref, 'refs/tags/')
254       run: |
255         mkdir assets
256         TAGNAME=$(git rev-parse --abbrev-ref $GITHUB_REF)
257         git archive --format=tar --prefix=quassel-$TAGNAME/ $TAGNAME | xz > assets/quassel-$TAGNAME.tar.xz
258
259     - name: Prepare packages for release
260       if: startsWith(github.ref, 'refs/tags/')
261       run: |
262         TAGNAME=$(git rev-parse --abbrev-ref $GITHUB_REF)
263         for type in Client Core Mono; do
264           mv artifacts/macOS/Quassel$type*.dmg assets/Quassel$type-macOS-$TAGNAME.dmg
265         done
266         mv artifacts/Windows/quassel-*.exe assets/quassel-windows-setup-$TAGNAME.exe
267         mv artifacts/Windows/quassel-*.7z assets/quassel-windows-$TAGNAME.7z
268
269     - name: Create checksums for release assets
270       if: startsWith(github.ref, 'refs/tags/')
271       run: find assets/ -type f -execdir sh -c 'sha256sum "$1" > "$1.sha256sum"' _ {} \;
272
273     - name: Create draft release
274       if: startsWith(github.ref, 'refs/tags/')
275       run: |
276         # The stock upload-release-asset action can only handle single files
277         # Instead, use the hub utility so we can upload all assets at once
278         assets=()
279         for asset in assets/*; do assets+=("-a" "$asset"); done
280         hub release create -d "${assets[@]}" -F release_notes.txt `git rev-parse --abbrev-ref $GITHUB_REF`