Codechange: change DestinationID into class with conversion helpers
[openttd-github.git] / .github / workflows / release-macos.yml
blobdb063ab8c4fd332eecc4da4c68d060ff6105a88a
1 name: Release (MacOS)
3 on:
4   workflow_call:
5     inputs:
6       survey_key:
7         required: false
8         type: string
9         default: ""
11 jobs:
12   macos:
13     name: MacOS
15     runs-on: macos-latest
16     env:
17       MACOSX_DEPLOYMENT_TARGET: 10.13
19     steps:
20     - name: Setup Xcode version
21       uses: maxim-lobanov/setup-xcode@v1
22       with:
23         xcode-version: latest-stable
25     - name: Download source
26       uses: actions/download-artifact@v4
27       with:
28         name: internal-source
30     - name: Unpack source
31       run: |
32         tar -xf source.tar.gz --strip-components=1
34     - name: Install Rust toolchain
35       uses: dtolnay/rust-toolchain@stable
37     - name: Enable Rust cache
38       uses: Swatinem/rust-cache@v2
40     - name: Setup vcpkg caching
41       uses: actions/github-script@v7
42       with:
43         script: |
44           core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
45           core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
46           core.exportVariable('VCPKG_BINARY_SOURCES', 'clear;x-gha,readwrite')
48     - name: Install vcpkg
49       run: |
50         git clone https://github.com/microsoft/vcpkg ${{ runner.temp }}/vcpkg
51         ${{ runner.temp }}/vcpkg/bootstrap-vcpkg.sh -disableMetrics
53     - name: Install dependencies
54       env:
55         HOMEBREW_NO_AUTO_UPDATE: 1
56         HOMEBREW_NO_INSTALL_CLEANUP: 1
57       run: |
58         echo "::group::Install brew dependencies"
59         brew install \
60           pandoc \
61           # EOF
62         echo "::endgroup::"
64         echo "::group::Install breakpad dependencies"
65         cargo install --locked dump_syms
66         echo "::endgroup::"
68     - name: Install GCC problem matcher
69       uses: ammaraskar/gcc-problem-matcher@master
71     - name: Build tools
72       run: |
73         mkdir build-host
74         cd build-host
76         echo "::group::CMake"
77         cmake ${GITHUB_WORKSPACE} \
78           -DCMAKE_BUILD_TYPE=RelWithDebInfo \
79           -DOPTION_TOOLS_ONLY=ON \
80           # EOF
81         echo "::endgroup::"
83         echo "::group::Build tools"
84         echo "Running on $(sysctl -n hw.logicalcpu) cores"
85         cmake --build . -j $(sysctl -n hw.logicalcpu) --target tools
86         echo "::endgroup::"
88     - name: Import code signing certificates
89       uses: Apple-Actions/import-codesign-certs@v3
90       with:
91         # The certificates in a PKCS12 file encoded as a base64 string
92         p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
93         # The password used to import the PKCS12 file.
94         p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
95       # If this is run on a fork, there may not be a certificate set up - continue in this case
96       continue-on-error: true
98     - name: Build arm64
99       run: |
100         mkdir build-arm64
101         cd build-arm64
103         echo "::group::CMake"
104         cmake ${GITHUB_WORKSPACE} \
105           -DCMAKE_OSX_ARCHITECTURES=arm64 \
106           -DVCPKG_TARGET_TRIPLET=arm64-osx \
107           -DCMAKE_TOOLCHAIN_FILE=${{ runner.temp }}/vcpkg/scripts/buildsystems/vcpkg.cmake \
108           -DHOST_BINARY_DIR=${GITHUB_WORKSPACE}/build-host \
109           -DCMAKE_BUILD_TYPE=RelWithDebInfo \
110           -DOPTION_SURVEY_KEY=${{ inputs.survey_key }} \
111           # EOF
112         echo "::endgroup::"
114         echo "::group::Build"
115         echo "Running on $(sysctl -n hw.logicalcpu) cores"
116         cmake --build . -j $(sysctl -n hw.logicalcpu) --target openttd
117         echo "::endgroup::"
119     - name: Build x64
120       run: |
121         mkdir build-x64
122         cd build-x64
124         echo "::group::CMake"
125         cmake ${GITHUB_WORKSPACE} \
126           -DCMAKE_OSX_ARCHITECTURES=x86_64 \
127           -DVCPKG_TARGET_TRIPLET=x64-osx \
128           -DCMAKE_TOOLCHAIN_FILE=${{ runner.temp }}/vcpkg/scripts/buildsystems/vcpkg.cmake \
129           -DHOST_BINARY_DIR=${GITHUB_WORKSPACE}/build-host \
130           -DCMAKE_BUILD_TYPE=RelWithDebInfo \
131           -DOPTION_SURVEY_KEY=${{ inputs.survey_key }} \
132           -DCPACK_BUNDLE_APPLE_CERT_APP=${{ secrets.APPLE_DEVELOPER_CERTIFICATE_ID }} \
133           "-DCPACK_BUNDLE_APPLE_CODESIGN_PARAMETER=--deep -f --options runtime" \
134           -DAPPLE_UNIVERSAL_PACKAGE=1 \
135           # EOF
136         echo "::endgroup::"
138         echo "::group::Build"
139         echo "Running on $(sysctl -n hw.logicalcpu) cores"
140         cmake --build . -j $(sysctl -n hw.logicalcpu) --target openttd
141         echo "::endgroup::"
143     - name: Create breakpad symbols
144       run: |
145         cd build-x64
146         mkdir dSYM
147         dsymutil ./openttd -o dSYM/openttd
148         dump_syms ./dSYM/openttd --inlines --store symbols
150         cd ../build-arm64
151         mkdir dSYM
152         dsymutil ./openttd -o dSYM/openttd
153         dump_syms ./dSYM/openttd --inlines --store ../build-x64/symbols
155     - name: Create bundles
156       run: |
157         cd build-x64
159         echo "::group::Create universal binary"
160         # Combine the `openttd` binaries from each build into a single file
161         lipo -create -output openttd-universal ../build-*/openttd
162         mv openttd-universal openttd
163         echo "::endgroup::"
165         echo "::group::Run CPack"
166         cpack
167         echo "::endgroup::"
169         echo "::group::Cleanup"
170         # Remove the sha256 files CPack generates; we will do this ourself at
171         # the end of this workflow.
172         rm -f bundles/*.sha256
173         echo "::endgroup::"
175     - name: Notarize
176       env:
177         AC_USERNAME: ${{ secrets.APPLE_DEVELOPER_APP_USERNAME }}
178         AC_PASSWORD: ${{ secrets.APPLE_DEVELOPER_APP_PASSWORD }}
179         AC_TEAM_ID: ${{ secrets.APPLE_DEVELOPER_TEAM_ID }}
180       run: |
181         if [ -z "${AC_USERNAME}" ]; then
182             # We may be running on a fork that doesn't have notarization secrets set up; skip this step
183             echo No notarization secrets set up, skipping.
184             exit 0
185         fi
187         xcrun notarytool store-credentials --apple-id "${AC_USERNAME}" --password "${AC_PASSWORD}" --team-id "${AC_TEAM_ID}" openttd
188         cd build-x64
189         ../os/macosx/notarize.sh
191     - name: Build zip
192       run: |
193         cd build-x64
195         pushd _CPack_Packages/*/Bundle/openttd-*/
197         # Remove the Applications symlink from the staging folder
198         rm -f Applications
200         # Remove the original dmg built by CPack to avoid a conflict when resolving
201         # the zip_filename variable below
202         rm -f ../*.dmg
204         zip_filename=(../openttd-*)
206         # Package up the existing, notarised .app into a zip file
207         zip -r -9 ${zip_filename}.zip OpenTTD.app
209         popd
211         # Now move it into place to be uploaded
212         mv _CPack_Packages/*/Bundle/openttd-*.zip bundles/
214     - name: Store bundles
215       uses: actions/upload-artifact@v4
216       with:
217         name: openttd-macos-universal
218         path: build-x64/bundles
219         retention-days: 5
221     - name: Store symbols
222       uses: actions/upload-artifact@v4
223       with:
224         name: symbols-macos-universal
225         path: build-x64/symbols
226         retention-days: 5