|
| 1 | +name: Desktop macOS Preview |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: desktop-macos-preview-${{ github.event.pull_request.number }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build macOS Apple Silicon preview |
| 18 | + if: >- |
| 19 | + github.event.pull_request.head.repo.full_name == github.repository && |
| 20 | + contains(github.event.pull_request.labels.*.name, 'preview:mac') && |
| 21 | + (github.event.action != 'labeled' || github.event.label.name == 'preview:mac') |
| 22 | + runs-on: blacksmith-12vcpu-macos-26 |
| 23 | + timeout-minutes: 30 |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v6 |
| 27 | + with: |
| 28 | + ref: ${{ github.event.pull_request.head.sha }} |
| 29 | + sparse-checkout: | |
| 30 | + /* |
| 31 | + !/.repos/ |
| 32 | + sparse-checkout-cone-mode: false |
| 33 | + |
| 34 | + - name: Setup Vite+ |
| 35 | + uses: voidzero-dev/setup-vp@v1 |
| 36 | + with: |
| 37 | + node-version-file: package.json |
| 38 | + cache: true |
| 39 | + run-install: false |
| 40 | + |
| 41 | + - name: Install desktop dependencies |
| 42 | + run: vp install --filter=@t3tools/desktop... --filter=t3... --filter=@t3tools/scripts... |
| 43 | + |
| 44 | + - name: Cache resource monitor |
| 45 | + id: resource_monitor_cache |
| 46 | + uses: actions/cache@v6 |
| 47 | + with: |
| 48 | + path: native/resource-monitor/target/aarch64-apple-darwin/release/t3-resource-monitor |
| 49 | + key: resource-monitor-aarch64-apple-darwin-${{ hashFiles('native/resource-monitor/Cargo.lock', 'native/resource-monitor/Cargo.toml', 'native/resource-monitor/src/**') }} |
| 50 | + |
| 51 | + - name: Setup Rust |
| 52 | + if: steps.resource_monitor_cache.outputs.cache-hit != 'true' |
| 53 | + uses: dtolnay/rust-toolchain@stable |
| 54 | + with: |
| 55 | + targets: aarch64-apple-darwin |
| 56 | + |
| 57 | + - id: version |
| 58 | + name: Set preview version and public configuration |
| 59 | + shell: bash |
| 60 | + env: |
| 61 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 62 | + run: | |
| 63 | + set -euo pipefail |
| 64 | +
|
| 65 | + base_version="$(node -p "require('./apps/desktop/package.json').version")" |
| 66 | + preview_version="${base_version}-pr.${PR_NUMBER}.${GITHUB_RUN_NUMBER}" |
| 67 | + node scripts/update-release-package-versions.ts "$preview_version" |
| 68 | + cp .env.example .env |
| 69 | +
|
| 70 | + echo "version=$preview_version" >> "$GITHUB_OUTPUT" |
| 71 | +
|
| 72 | + - name: Build signed macOS DMG |
| 73 | + shell: bash |
| 74 | + env: |
| 75 | + T3CODE_DESKTOP_REUSE_RESOURCE_MONITOR: ${{ steps.resource_monitor_cache.outputs.cache-hit == 'true' }} |
| 76 | + CSC_LINK: ${{ secrets.CSC_LINK }} |
| 77 | + CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} |
| 78 | + APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }} |
| 79 | + APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }} |
| 80 | + APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }} |
| 81 | + APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }} |
| 82 | + MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }} |
| 83 | + PREVIEW_VERSION: ${{ steps.version.outputs.version }} |
| 84 | + run: | |
| 85 | + set -euo pipefail |
| 86 | +
|
| 87 | + required=( |
| 88 | + CSC_LINK |
| 89 | + CSC_KEY_PASSWORD |
| 90 | + APPLE_API_KEY |
| 91 | + APPLE_API_KEY_ID |
| 92 | + APPLE_API_ISSUER |
| 93 | + APPLE_TEAM_ID |
| 94 | + MACOS_PROVISIONING_PROFILE |
| 95 | + ) |
| 96 | + missing=() |
| 97 | + for name in "${required[@]}"; do |
| 98 | + if [[ -z "${!name:-}" ]]; then |
| 99 | + missing+=("$name") |
| 100 | + fi |
| 101 | + done |
| 102 | + if (( ${#missing[@]} > 0 )); then |
| 103 | + printf 'Missing required macOS signing configuration: %s\n' "${missing[*]}" >&2 |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +
|
| 107 | + key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8" |
| 108 | + printf '%s' "$APPLE_API_KEY" > "$key_path" |
| 109 | + export APPLE_API_KEY="$key_path" |
| 110 | +
|
| 111 | + profile_path="$RUNNER_TEMP/t3code.provisionprofile" |
| 112 | + printf '%s' "$MACOS_PROVISIONING_PROFILE" | base64 -D > "$profile_path" |
| 113 | + security cms -D -i "$profile_path" >/dev/null |
| 114 | + export T3CODE_APPLE_TEAM_ID="$APPLE_TEAM_ID" |
| 115 | + export T3CODE_MACOS_PROVISIONING_PROFILE="$profile_path" |
| 116 | +
|
| 117 | + vp run dist:desktop:artifact \ |
| 118 | + --platform mac \ |
| 119 | + --target dmg \ |
| 120 | + --arch arm64 \ |
| 121 | + --build-version "$PREVIEW_VERSION" \ |
| 122 | + --signed \ |
| 123 | + --verbose |
| 124 | +
|
| 125 | + - id: upload |
| 126 | + name: Upload macOS DMG |
| 127 | + uses: actions/upload-artifact@v7 |
| 128 | + with: |
| 129 | + path: release/*.dmg |
| 130 | + if-no-files-found: error |
| 131 | + archive: false |
| 132 | + overwrite: true |
| 133 | + retention-days: 7 |
| 134 | + |
| 135 | + - name: Comment download link |
| 136 | + uses: actions/github-script@v8 |
| 137 | + env: |
| 138 | + ARTIFACT_URL: ${{ steps.upload.outputs.artifact-url }} |
| 139 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 140 | + PREVIEW_VERSION: ${{ steps.version.outputs.version }} |
| 141 | + with: |
| 142 | + script: | |
| 143 | + const marker = "<!-- desktop-macos-preview -->"; |
| 144 | + const body = [ |
| 145 | + marker, |
| 146 | + "### macOS preview", |
| 147 | + "", |
| 148 | + `[Download Apple Silicon DMG](${process.env.ARTIFACT_URL})`, |
| 149 | + "", |
| 150 | + `Version: ${process.env.PREVIEW_VERSION}`, |
| 151 | + `Commit: ${process.env.HEAD_SHA.slice(0, 7)}`, |
| 152 | + "", |
| 153 | + "The download requires GitHub access and expires after 7 days.", |
| 154 | + ].join("\n"); |
| 155 | +
|
| 156 | + const { data: comments } = await github.rest.issues.listComments({ |
| 157 | + owner: context.repo.owner, |
| 158 | + repo: context.repo.repo, |
| 159 | + issue_number: context.payload.pull_request.number, |
| 160 | + per_page: 100, |
| 161 | + }); |
| 162 | + const existing = comments.find((comment) => comment.body?.includes(marker)); |
| 163 | +
|
| 164 | + if (existing) { |
| 165 | + await github.rest.issues.updateComment({ |
| 166 | + owner: context.repo.owner, |
| 167 | + repo: context.repo.repo, |
| 168 | + comment_id: existing.id, |
| 169 | + body, |
| 170 | + }); |
| 171 | + } else { |
| 172 | + await github.rest.issues.createComment({ |
| 173 | + owner: context.repo.owner, |
| 174 | + repo: context.repo.repo, |
| 175 | + issue_number: context.payload.pull_request.number, |
| 176 | + body, |
| 177 | + }); |
| 178 | + } |
0 commit comments