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