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