aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/build.yml
blob: 4e52af4e3d0a5fbbbd142ab1745225417bff44ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
name: Build

on:
  workflow_call:
    inputs:
      build_type:
        description: Type of build (Debug, Release, RelWithDebInfo, MinSizeRel)
        type: string
        default: Debug

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:

          - os: ubuntu-20.04

          - os: ubuntu-20.04
            appimage: true

          - os: windows-2022
            name: "Windows-i686"
            msystem: mingw32

          - os: windows-2022
            name: "Windows-x86_64"
            msystem: mingw64

          - os: macos-12
            macosx_deployment_target: 10.13

    runs-on: ${{ matrix.os }}

    env:
      MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macosx_deployment_target }}
      INSTALL_DIR: "install"
      INSTALL_PORTABLE_DIR: "install-portable"
      INSTALL_APPIMAGE_DIR: "install-appdir"
      BUILD_DIR: "build"
      CCACHE_VAR: ""

    steps:
      ##
      # PREPARE
      ##
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: 'true'

      - name: 'Setup MSYS2'
        if: runner.os == 'Windows'
        uses: msys2/setup-msys2@v2
        with:
          msystem: ${{ matrix.msystem }}
          update: true
          install: >-
            git
          pacboy: >-
            toolchain:p
            cmake:p
            extra-cmake-modules:p
            ninja:p
            qt5:p
            ccache:p
            nsis:p

      - name: Setup ccache
        if: runner.os != 'Windows' && inputs.build_type == 'Debug'
        uses: hendrikmuhs/ccache-action@v1.2.1
        with:
          key: ${{ matrix.os }}-${{ matrix.appimage }}

      - name: Setup ccache (Windows)
        if: runner.os == 'Windows' && inputs.build_type == 'Debug'
        shell: msys2 {0}
        run: |
          ccache --set-config=cache_dir='${{ github.workspace }}\.ccache'
          ccache --set-config=max_size='500M'
          ccache --set-config=compression=true
          ccache -p  # Show config
          ccache -z  # Zero stats

      - name: Use ccache on Debug builds only
        if: inputs.build_type == 'Debug'
        shell: bash
        run: |
          echo "CCACHE_VAR=ccache" >> $GITHUB_ENV

      - name: Retrieve ccache cache (Windows)
        if: runner.os == 'Windows' && inputs.build_type == 'Debug'
        uses: actions/cache@v3.0.2
        with:
          path: '${{ github.workspace }}\.ccache'
          key: ${{ matrix.os }}-${{ matrix.msystem }}
          restore-keys: |
              ${{ matrix.os }}-${{ matrix.msystem }}

      - name: Set short version
        shell: bash
        run: |
          ver_short=`git rev-parse --short HEAD`
          echo "VERSION=$ver_short" >> $GITHUB_ENV

      - name: Install Qt (macOS)
        if: runner.os == 'macOS'
        run: |
         brew update
         brew install qt@5 ninja extra-cmake-modules

      - name: Update Qt (AppImage)
        if: runner.os == 'Linux' && matrix.appimage == true
        run: |
         sudo add-apt-repository ppa:savoury1/qt-5-15
         sudo add-apt-repository ppa:savoury1/kde-5-80
         sudo add-apt-repository ppa:savoury1/gpg
         sudo add-apt-repository ppa:savoury1/ffmpeg4

      - name: Install Qt (Linux)
        if: runner.os == 'Linux'
        run: |
          sudo apt-get -y update
          sudo apt-get -y install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools libqt5core5a libqt5network5 libqt5gui5 ninja-build qt5-image-formats-plugins extra-cmake-modules

      - name: Prepare AppImage (Linux)
        if: runner.os == 'Linux' && matrix.appimage == true
        run: |
          wget "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
          wget "https://github.com/linuxdeploy/linuxdeploy-plugin-appimage/releases/download/continuous/linuxdeploy-plugin-appimage-x86_64.AppImage"
          wget "https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage"

          ${{ github.workspace }}/.github/scripts/prepare_JREs.sh

      ##
      # CONFIGURE
      ##

      - name: Configure CMake (macOS)
        if: runner.os == 'macOS'
        run: |
          cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DQt5_DIR=/usr/local/opt/qt@5 -DCMAKE_PREFIX_PATH=/usr/local/opt/qt@5 -DLauncher_BUILD_PLATFORM=macOS -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -G Ninja

      - name: Configure CMake (Windows)
        if: runner.os == 'Windows'
        shell: msys2 {0}
        run: |
          cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=${{ matrix.name }} -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -G Ninja

      - name: Configure CMake (Linux)
        if: runner.os == 'Linux'
        run: |
          cmake -S . -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} -DENABLE_LTO=ON -DLauncher_BUILD_PLATFORM=Linux -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CCACHE_VAR }} -G Ninja

      ##
      # BUILD
      ##

      - name: Build
        if: runner.os != 'Windows'
        run: |
          cmake --build ${{ env.BUILD_DIR }}

      - name: Build (Windows)
        if: runner.os == 'Windows'
        shell: msys2 {0}
        run: |
          cmake --build ${{ env.BUILD_DIR }}

      ##
      # TEST
      ##

      - name: Test
        if: runner.os != 'Windows'
        run: |
          ctest --test-dir build --output-on-failure

      - name: Test (Windows)
        if: runner.os == 'Windows'
        shell: msys2 {0}
        run: |
          ctest --test-dir build --output-on-failure

      ##
      # PACKAGE BUILDS
      ##

      - name: Package (macOS)
        if: runner.os == 'macOS'
        run: |
          cmake --install ${{ env.BUILD_DIR }}

          cd ${{ env.INSTALL_DIR }}
          chmod +x "PolyMC.app/Contents/MacOS/polymc"
          sudo codesign --sign - --deep --force --entitlements "../program_info/App.entitlements" --options runtime "PolyMC.app/Contents/MacOS/polymc"
          tar -czf ../PolyMC.tar.gz *

      - name: Package (Windows)
        if: runner.os == 'Windows'
        shell: msys2 {0}
        run: |
          cmake --install ${{ env.BUILD_DIR }}

          cd ${{ env.INSTALL_DIR }}
          if [ "${{ matrix.msystem }}" == "mingw32" ]; then
            cp /mingw32/bin/libcrypto-1_1.dll /mingw32/bin/libssl-1_1.dll ./
          elif [ "${{ matrix.msystem }}" == "mingw64" ]; then
            cp /mingw64/bin/libcrypto-1_1-x64.dll /mingw64/bin/libssl-1_1-x64.dll ./
          fi

      - name: Package (Windows, portable)
        if: runner.os == 'Windows'
        shell: msys2 {0}
        run: |
          cp -r ${{ env.INSTALL_DIR }} ${{ env.INSTALL_PORTABLE_DIR }}  # cmake install on Windows is slow, let's just copy instead
          cmake --install ${{ env.BUILD_DIR }} --prefix ${{ env.INSTALL_PORTABLE_DIR }} --component portable

      - name: Package (Windows, installer)
        if: runner.os == 'Windows'
        shell: msys2 {0}
        run: |
          cd ${{ env.INSTALL_DIR }}
          makensis -NOCD "${{ github.workspace }}/${{ env.BUILD_DIR }}/program_info/win_install.nsi"

      - name: Package (Linux)
        if: runner.os == 'Linux' && matrix.appimage != true
        run: |
          cmake --install ${{ env.BUILD_DIR }} --prefix ${{ env.INSTALL_DIR }}

          cd ${{ env.INSTALL_DIR }}
          tar --owner root --group root -czf ../PolyMC.tar.gz *

      - name: Package (Linux, portable)
        if: runner.os == 'Linux' && matrix.appimage != true
        run: |
          cmake --install ${{ env.BUILD_DIR }} --prefix ${{ env.INSTALL_PORTABLE_DIR }}
          cmake --install ${{ env.BUILD_DIR }} --prefix ${{ env.INSTALL_PORTABLE_DIR }} --component portable

          cd ${{ env.INSTALL_PORTABLE_DIR }}
          tar -czf ../PolyMC-portable.tar.gz *

      - name: Package AppImage (Linux)
        if: runner.os == 'Linux' && matrix.appimage == true
        shell: bash
        run: |
          cmake --install ${{ env.BUILD_DIR }} --prefix ${{ env.INSTALL_APPIMAGE_DIR }}/usr

          export OUTPUT="PolyMC-${{ runner.os }}-${{ env.VERSION }}-${{ inputs.build_type }}-x86_64.AppImage"

          chmod +x linuxdeploy-*.AppImage

          mkdir -p ${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib/jvm/java-{8,17}-openjdk

          cp -r ${{ github.workspace }}/JREs/jre8/* ${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib/jvm/java-8-openjdk

          cp -r ${{ github.workspace }}/JREs/jre17/* ${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib/jvm/java-17-openjdk

          LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib"
          LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib/jvm/java-8-openjdk/lib/amd64/server"
          LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib/jvm/java-8-openjdk/lib/amd64"
          LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib/jvm/java-17-openjdk/lib/server"
          LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${{ env.INSTALL_APPIMAGE_DIR }}/usr/lib/jvm/java-17-openjdk/lib"
          export LD_LIBRARY_PATH

          ./linuxdeploy-x86_64.AppImage --appdir ${{ env.INSTALL_APPIMAGE_DIR }} --output appimage --plugin qt -i ${{ env.INSTALL_APPIMAGE_DIR }}/usr/share/icons/hicolor/scalable/apps/org.polymc.PolyMC.svg

      ##
      # UPLOAD BUILDS
      ##

      - name: Upload binary tarball (macOS)
        if: runner.os == 'macOS'
        uses: actions/upload-artifact@v3
        with:
          name: PolyMC-${{ runner.os }}-${{ env.VERSION }}-${{ inputs.build_type }}
          path: PolyMC.tar.gz

      - name: Upload binary zip (Windows)
        if: runner.os == 'Windows'
        uses: actions/upload-artifact@v3
        with:
          name: PolyMC-${{ matrix.name }}-${{ env.VERSION }}-${{ inputs.build_type }}
          path: ${{ env.INSTALL_DIR }}/**

      - name: Upload binary zip (Windows, portable)
        if: runner.os == 'Windows'
        uses: actions/upload-artifact@v3
        with:
          name: PolyMC-${{ matrix.name }}-Portable-${{ env.VERSION }}-${{ inputs.build_type }}
          path: ${{ env.INSTALL_PORTABLE_DIR }}/**

      - name: Upload installer (Windows)
        if: runner.os == 'Windows'
        uses: actions/upload-artifact@v3
        with:
          name: PolyMC-${{ matrix.name }}-Setup-${{ env.VERSION }}-${{ inputs.build_type }}
          path: PolyMC-Setup.exe

      - name: Upload binary tarball (Linux)
        if: runner.os == 'Linux' && matrix.appimage != true
        uses: actions/upload-artifact@v3
        with:
          name: PolyMC-${{ runner.os }}-${{ env.VERSION }}-${{ inputs.build_type }}
          path: PolyMC.tar.gz

      - name: Upload binary tarball (Linux, portable)
        if: runner.os == 'Linux' && matrix.appimage != true
        uses: actions/upload-artifact@v3
        with:
          name: PolyMC-${{ runner.os }}-Portable-${{ env.VERSION }}-${{ inputs.build_type }}
          path: PolyMC-portable.tar.gz

      - name: Upload AppImage (Linux)
        if: runner.os == 'Linux' && matrix.appimage == true
        uses: actions/upload-artifact@v3
        with:
          name: PolyMC-${{ runner.os }}-${{ env.VERSION }}-${{ inputs.build_type }}-x86_64.AppImage
          path: PolyMC-${{ runner.os }}-${{ env.VERSION }}-${{ inputs.build_type }}-x86_64.AppImage