|
| 1 | +name: Release macOS |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: Release tag to create and publish, for example v0.1.0 |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + target_ref: |
| 11 | + description: Branch or commit SHA to release |
| 12 | + required: false |
| 13 | + default: main |
| 14 | + type: string |
| 15 | + prerelease: |
| 16 | + description: Mark the GitHub Release as a prerelease |
| 17 | + required: false |
| 18 | + default: false |
| 19 | + type: boolean |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: write |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: release-macos-${{ github.event.inputs.tag }} |
| 26 | + cancel-in-progress: false |
| 27 | + |
| 28 | +jobs: |
| 29 | + release: |
| 30 | + name: Build, sign, notarize, and publish macOS release |
| 31 | + runs-on: macos-latest |
| 32 | + environment: release-macos |
| 33 | + env: |
| 34 | + GH_TOKEN: ${{ github.token }} |
| 35 | + _VCPKG_: ${{ github.workspace }}/vcpkg |
| 36 | + VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg/bincache |
| 37 | + VCPKG_BINARY_SOURCES: clear;x-gha,readwrite |
| 38 | + APP_NAME: PlatypusGui |
| 39 | + DMG_NAME: Platypus-macos-universal.dmg |
| 40 | + |
| 41 | + steps: |
| 42 | + - uses: actions/github-script@v7 |
| 43 | + with: |
| 44 | + script: | |
| 45 | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); |
| 46 | + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); |
| 47 | +
|
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + ref: ${{ github.event.inputs.target_ref }} |
| 52 | + fetch-depth: 0 |
| 53 | + submodules: true |
| 54 | + |
| 55 | + - name: Validate release tag |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + set -euo pipefail |
| 59 | + TAG="${{ github.event.inputs.tag }}" |
| 60 | + if [[ ! "$TAG" =~ ^v[0-9]+(\.[0-9]+)*([.-][A-Za-z0-9._-]+)?$ ]]; then |
| 61 | + echo "Release tag must look like v0.1.0 or v0.1.0-rc1" >&2 |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Check for existing release |
| 66 | + shell: bash |
| 67 | + run: | |
| 68 | + set -euo pipefail |
| 69 | + TAG="${{ github.event.inputs.tag }}" |
| 70 | + if gh release view "$TAG" >/dev/null 2>&1; then |
| 71 | + echo "Release $TAG already exists" >&2 |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
| 75 | + - name: Create tag if needed |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + TAG="${{ github.event.inputs.tag }}" |
| 80 | + TARGET_REF="${{ github.event.inputs.target_ref }}" |
| 81 | + if ! git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then |
| 82 | + git tag "$TAG" "$TARGET_REF" |
| 83 | + git push origin "refs/tags/$TAG" |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Prepare vcpkg cache directory |
| 87 | + shell: bash |
| 88 | + run: mkdir -p "$VCPKG_DEFAULT_BINARY_CACHE" |
| 89 | + |
| 90 | + - name: Get CMake |
| 91 | + uses: lukka/get-cmake@latest |
| 92 | + |
| 93 | + - name: Get Ninja |
| 94 | + uses: seanmiddleditch/gha-setup-ninja@master |
| 95 | + |
| 96 | + - name: Restore from cache and setup vcpkg |
| 97 | + uses: lukka/run-vcpkg@v11 |
| 98 | + with: |
| 99 | + vcpkgJsonGlob: vcpkg.json |
| 100 | + |
| 101 | + - name: Import Apple signing certificate |
| 102 | + shell: bash |
| 103 | + env: |
| 104 | + MACOS_CERT_P12_BASE64: ${{ secrets.MACOS_CERT_P12_BASE64 }} |
| 105 | + MACOS_CERT_P12_PASSWORD: ${{ secrets.MACOS_CERT_P12_PASSWORD }} |
| 106 | + run: | |
| 107 | + set -euo pipefail |
| 108 | + CERT_PATH="$RUNNER_TEMP/dev_app.p12" |
| 109 | + KEYCHAIN_PATH="$RUNNER_TEMP/platypus-build.keychain-db" |
| 110 | + KEYCHAIN_PASSWORD="$(uuidgen)" |
| 111 | +
|
| 112 | + echo "$MACOS_CERT_P12_BASE64" | base64 --decode > "$CERT_PATH" |
| 113 | +
|
| 114 | + security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 115 | + security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH" |
| 116 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 117 | + security import "$CERT_PATH" -k "$KEYCHAIN_PATH" -P "$MACOS_CERT_P12_PASSWORD" -T /usr/bin/codesign -T /usr/bin/security |
| 118 | + security list-keychains -d user -s "$KEYCHAIN_PATH" $(security list-keychains -d user | tr -d '"') |
| 119 | + security default-keychain -d user -s "$KEYCHAIN_PATH" |
| 120 | + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" |
| 121 | +
|
| 122 | + { |
| 123 | + echo "KEYCHAIN_PATH=$KEYCHAIN_PATH" |
| 124 | + echo "KEYCHAIN_PASSWORD=$KEYCHAIN_PASSWORD" |
| 125 | + } >> "$GITHUB_ENV" |
| 126 | +
|
| 127 | + - name: Materialize App Store Connect API key |
| 128 | + shell: bash |
| 129 | + env: |
| 130 | + APPSTORE_CONNECT_API_KEY_BASE64: ${{ secrets.APPSTORE_CONNECT_API_KEY_BASE64 }} |
| 131 | + run: | |
| 132 | + set -euo pipefail |
| 133 | + API_KEY_PATH="$RUNNER_TEMP/AuthKey_${{ secrets.APPSTORE_CONNECT_API_KEY_ID }}.p8" |
| 134 | + echo "$APPSTORE_CONNECT_API_KEY_BASE64" | base64 --decode > "$API_KEY_PATH" |
| 135 | + echo "APPSTORE_CONNECT_API_KEY_PATH=$API_KEY_PATH" >> "$GITHUB_ENV" |
| 136 | +
|
| 137 | + - name: Configure CMake |
| 138 | + shell: bash |
| 139 | + run: | |
| 140 | + set -euo pipefail |
| 141 | + PACKAGE_VERSION="${{ github.event.inputs.tag }}" |
| 142 | + PACKAGE_VERSION="${PACKAGE_VERSION#v}" |
| 143 | + cmake -B build -S . -G Ninja \ |
| 144 | + -DCMAKE_BUILD_TYPE=Release \ |
| 145 | + -DBUILD_APPLE_APP=ON \ |
| 146 | + -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \ |
| 147 | + -DVCPKG_OSX_ARCHITECTURES="x86_64;arm64" \ |
| 148 | + -DPLATYPUS_PACKAGE_VERSION_OVERRIDE="$PACKAGE_VERSION" \ |
| 149 | + -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" |
| 150 | +
|
| 151 | + - name: Build PlatypusGui |
| 152 | + shell: bash |
| 153 | + run: cmake --build build --config Release --target PlatypusGui |
| 154 | + |
| 155 | + - name: Verify universal binary |
| 156 | + shell: bash |
| 157 | + run: | |
| 158 | + set -euo pipefail |
| 159 | + APP_BIN="build/PlatypusGui.app/Contents/MacOS/PlatypusGui" |
| 160 | + APP_ARCHS="$(lipo -archs "$APP_BIN")" |
| 161 | + echo "App architectures: $APP_ARCHS" |
| 162 | + [[ "$APP_ARCHS" == *"x86_64"* ]] || { echo "Missing x86_64 slice" >&2; exit 1; } |
| 163 | + [[ "$APP_ARCHS" == *"arm64"* ]] || { echo "Missing arm64 slice" >&2; exit 1; } |
| 164 | +
|
| 165 | + - name: Locate macdeployqt |
| 166 | + shell: bash |
| 167 | + run: | |
| 168 | + set -euo pipefail |
| 169 | + MACDEPLOYQT_BIN="$(find "$GITHUB_WORKSPACE/vcpkg_installed" -type f -name macdeployqt | head -n 1 || true)" |
| 170 | + if [[ -z "$MACDEPLOYQT_BIN" ]]; then |
| 171 | + MACDEPLOYQT_BIN="$(command -v macdeployqt || true)" |
| 172 | + fi |
| 173 | + if [[ -z "$MACDEPLOYQT_BIN" ]]; then |
| 174 | + echo "Unable to locate macdeployqt" >&2 |
| 175 | + exit 1 |
| 176 | + fi |
| 177 | + echo "MACDEPLOYQT_BIN=$MACDEPLOYQT_BIN" >> "$GITHUB_ENV" |
| 178 | +
|
| 179 | + - name: Sign app bundle |
| 180 | + shell: bash |
| 181 | + run: | |
| 182 | + set -euo pipefail |
| 183 | + bash scripts/mac_sign_app.sh \ |
| 184 | + --app build/PlatypusGui.app \ |
| 185 | + --identity "${{ vars.APPLE_SIGNING_IDENTITY }}" \ |
| 186 | + --macdeployqt "$MACDEPLOYQT_BIN" |
| 187 | +
|
| 188 | + - name: Create DMG payload |
| 189 | + shell: bash |
| 190 | + run: | |
| 191 | + set -euo pipefail |
| 192 | + STAGING_DIR="$RUNNER_TEMP/dmg-root" |
| 193 | + rm -rf "$STAGING_DIR" |
| 194 | + mkdir -p "$STAGING_DIR" |
| 195 | + cp -R build/PlatypusGui.app "$STAGING_DIR/" |
| 196 | + ln -s /Applications "$STAGING_DIR/Applications" |
| 197 | + hdiutil create \ |
| 198 | + -volname "Platypus" \ |
| 199 | + -srcfolder "$STAGING_DIR" \ |
| 200 | + -ov \ |
| 201 | + -format UDZO \ |
| 202 | + "build/$DMG_NAME" |
| 203 | +
|
| 204 | + - name: Notarize DMG |
| 205 | + shell: bash |
| 206 | + run: | |
| 207 | + set -euo pipefail |
| 208 | + xcrun notarytool submit "build/$DMG_NAME" \ |
| 209 | + --key "$APPSTORE_CONNECT_API_KEY_PATH" \ |
| 210 | + --key-id "${{ secrets.APPSTORE_CONNECT_API_KEY_ID }}" \ |
| 211 | + --issuer "${{ secrets.APPSTORE_CONNECT_API_ISSUER_ID }}" \ |
| 212 | + --wait |
| 213 | +
|
| 214 | + - name: Staple DMG |
| 215 | + shell: bash |
| 216 | + run: | |
| 217 | + set -euo pipefail |
| 218 | + xcrun stapler staple "build/$DMG_NAME" |
| 219 | + spctl -a -t open --context context:primary-signature -v "build/$DMG_NAME" |
| 220 | +
|
| 221 | + - name: Generate checksums |
| 222 | + shell: bash |
| 223 | + run: | |
| 224 | + set -euo pipefail |
| 225 | + ( |
| 226 | + cd build |
| 227 | + shasum -a 256 "$DMG_NAME" > SHA256SUMS.txt |
| 228 | + ) |
| 229 | +
|
| 230 | + - name: Publish GitHub Release |
| 231 | + shell: bash |
| 232 | + run: | |
| 233 | + set -euo pipefail |
| 234 | + TAG="${{ github.event.inputs.tag }}" |
| 235 | + RELEASE_ARGS=() |
| 236 | + if [[ "${{ github.event.inputs.prerelease }}" == "true" ]]; then |
| 237 | + RELEASE_ARGS+=(--prerelease) |
| 238 | + fi |
| 239 | + gh release create "$TAG" \ |
| 240 | + "build/$DMG_NAME" \ |
| 241 | + "build/SHA256SUMS.txt" \ |
| 242 | + --target "${{ github.event.inputs.target_ref }}" \ |
| 243 | + --title "$TAG" \ |
| 244 | + --generate-notes \ |
| 245 | + "${RELEASE_ARGS[@]}" |
| 246 | +
|
| 247 | + - name: Upload workflow artifacts |
| 248 | + uses: actions/upload-artifact@v4 |
| 249 | + with: |
| 250 | + name: macos-release-artifacts |
| 251 | + path: | |
| 252 | + build/PlatypusGui.app |
| 253 | + build/${{ env.DMG_NAME }} |
| 254 | + build/SHA256SUMS.txt |
| 255 | +
|
| 256 | + - name: Cleanup temporary keychain |
| 257 | + if: always() |
| 258 | + shell: bash |
| 259 | + run: | |
| 260 | + set +e |
| 261 | + if [[ -n "${KEYCHAIN_PATH:-}" ]]; then |
| 262 | + security delete-keychain "$KEYCHAIN_PATH" |
| 263 | + fi |
0 commit comments