-
-
Notifications
You must be signed in to change notification settings - Fork 15
330 lines (290 loc) · 14.1 KB
/
Copy pathpr-build.yml
File metadata and controls
330 lines (290 loc) · 14.1 KB
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
323
324
325
326
327
328
329
330
name: PR Build
# Triggered by commenting "/build" or "/build-quick" on a pull request.
# Builds a signed DMG (notarized if /build) from the PR branch and posts
# a download link as a comment on the PR.
on:
issue_comment:
types: [created]
permissions:
contents: read
pull-requests: write
actions: read
concurrency:
# One build per PR — re-commenting /build cancels any in-progress build
group: pr-build-${{ github.event.issue.number }}
cancel-in-progress: true
jobs:
pr-build:
name: Build PR
# Only run when:
# 1. The comment is on a pull request (not a plain issue)
# 2. The comment body is exactly "/build" (trimmed)
if: >-
github.event.issue.pull_request &&
(contains(github.event.comment.body, '/build') || contains(github.event.comment.body, '/build-quick'))
runs-on: macos-15
timeout-minutes: 45
steps:
# ── Setup ─────────────────────────────────────────────────────────────
- name: React to comment
uses: actions/github-script@v7
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
- name: Get PR branch info
id: pr
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
core.setOutput('ref', pr.data.head.ref);
core.setOutput('sha', pr.data.head.sha);
core.setOutput('short_sha', pr.data.head.sha.substring(0, 7));
core.setOutput('pr_number', context.issue.number);
core.setOutput('pr_title', pr.data.title);
- name: Determine build type
id: build_type
run: |
if [[ "${{ github.event.comment.body }}" == *"/build-quick"* ]]; then
echo "QUICK=true" >> "$GITHUB_OUTPUT"
echo "BUILD_DESCRIPTION=Build signed DMG (skipping notarization)" >> "$GITHUB_OUTPUT"
echo "DIST_FLAGS=--skip-notarize" >> "$GITHUB_OUTPUT"
else
echo "QUICK=false" >> "$GITHUB_OUTPUT"
echo "BUILD_DESCRIPTION=Build signed & notarized DMG" >> "$GITHUB_OUTPUT"
echo "DIST_FLAGS=" >> "$GITHUB_OUTPUT"
fi
- name: Post "build started" comment
uses: actions/github-script@v7
with:
script: |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const description = "${{ steps.build_type.outputs.BUILD_DESCRIPTION }}";
const timeEstimate = "${{ steps.build_type.outputs.QUICK }}" === "true" ? "3–5 minutes" : "10–20 minutes";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `⏳ **PR Build started** for \`${{ steps.pr.outputs.short_sha }}\`\n\n${description}... this usually takes ${timeEstimate}.\n\n[Watch the build →](${runUrl})`
});
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: ${{ steps.pr.outputs.ref }}
- name: Cache SPM dependencies
uses: actions/cache@v5
with:
path: .build
key: spm-${{ runner.os }}-${{ hashFiles('Package.resolved') }}
restore-keys: |
spm-${{ runner.os }}-
- name: Select Xcode 26
run: ./scripts/select-xcode-26.sh
# ── Test ──────────────────────────────────────────────────────────────
- name: Run tests
run: swift test
- name: Initialize Xcode tools
run: sudo xcodebuild -runFirstLaunch
# ── Code Signing Setup ──────────────────────────────────────────────────
- name: Import Developer ID certificate
env:
DEVELOPER_ID_CERT_P12: ${{ secrets.DEVELOPER_ID_CERT_P12 }}
DEVELOPER_ID_CERT_PASSWORD: ${{ secrets.DEVELOPER_ID_CERT_PASSWORD }}
run: |
KEYCHAIN_PATH="$RUNNER_TEMP/build.keychain"
KEYCHAIN_PASSWORD="$(openssl rand -hex 16)"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
echo "$DEVELOPER_ID_CERT_P12" | base64 --decode > "$RUNNER_TEMP/cert.p12"
security import "$RUNNER_TEMP/cert.p12" \
-k "$KEYCHAIN_PATH" \
-P "$DEVELOPER_ID_CERT_PASSWORD" \
-T /usr/bin/codesign \
-T /usr/bin/security
security set-key-partition-list \
-S apple-tool:,apple:,codesign: \
-s -k "$KEYCHAIN_PASSWORD" \
"$KEYCHAIN_PATH"
security list-keychains -d user -s "$KEYCHAIN_PATH" $(security list-keychains -d user | xargs)
echo "KEYCHAIN_PATH=$KEYCHAIN_PATH" >> "$GITHUB_ENV"
echo "KEYCHAIN_PASSWORD=$KEYCHAIN_PASSWORD" >> "$GITHUB_ENV"
IDENTITY=$(security find-identity -v -p codesigning "$KEYCHAIN_PATH" \
| grep "Developer ID Application" | head -1 | sed 's/.*"\(.*\)"/\1/')
if [ -z "$IDENTITY" ]; then
echo "❌ Developer ID certificate not found after import"
exit 1
fi
echo "✅ Imported: $IDENTITY"
echo "CODE_SIGN_IDENTITY=$IDENTITY" >> "$GITHUB_ENV"
- name: Store notarization credentials
if: steps.build_type.outputs.QUICK != 'true'
env:
NOTARIZE_APPLE_ID: ${{ secrets.NOTARIZE_APPLE_ID }}
NOTARIZE_TEAM_ID: ${{ secrets.NOTARIZE_TEAM_ID }}
NOTARIZE_PASSWORD: ${{ secrets.NOTARIZE_PASSWORD }}
run: |
xcrun notarytool store-credentials "AC_PASSWORD" \
--apple-id "$NOTARIZE_APPLE_ID" \
--team-id "$NOTARIZE_TEAM_ID" \
--password "$NOTARIZE_PASSWORD"
# ── Build & Package ─────────────────────────────────────────────────────
- name: Set PR build version
run: |
# Tag the build so it's identifiable (e.g., 0.6.2-pr.106+abc1234)
BASE_VERSION="${APP_VERSION:-}"
if [ -z "$BASE_VERSION" ]; then
BASE_VERSION="$(grep '^APP_VERSION=' scripts/build.sh | sed 's/.*:-\(.*\)}.*/\1/' | head -1 || true)"
fi
if [ -z "$BASE_VERSION" ]; then
echo "❌ Unable to determine base app version from scripts/build.sh" >&2
exit 1
fi
PR_VERSION="${BASE_VERSION}-pr.${{ steps.pr.outputs.pr_number }}+${{ steps.pr.outputs.short_sha }}"
echo "APP_VERSION=$PR_VERSION" >> "$GITHUB_ENV"
echo "📦 Build version: $PR_VERSION"
- name: Build signed DMG
run: ./scripts/dist.sh ${{ steps.build_type.outputs.DIST_FLAGS }}
- name: Verify code signature
run: codesign -v --deep --strict VocaMac.app
- name: Verify SPM resource bundles are correctly staged
# Mirrors the validation in release.yml and nightly.yml so PR builds
# catch bundle-layout regressions (the #119 class of bug) before they
# reach a release. xcodebuild's Bundle.module accessor resolves to
# Contents/Resources/, and bundles must NOT live at the .app root
# (codesign will reject that layout).
run: |
echo "🔍 Checking SPM resource bundle layout..."
FAIL=0
# Bundles must NOT be at the .app root (codesign rejects that).
if ls VocaMac.app/*.bundle 1>/dev/null 2>&1; then
echo "❌ Found .bundle at app root — will break codesign!"
ls VocaMac.app/*.bundle
FAIL=1
fi
FOUND_ANY=false
for bundle in VocaMac.app/Contents/Resources/*.bundle; do
[ -d "$bundle" ] || continue
FOUND_ANY=true
name="$(basename "$bundle")"
echo "✅ $name — present in Contents/Resources/"
done
if [ "$FOUND_ANY" = false ]; then
echo "❌ No .bundle directories found in Contents/Resources/!"
FAIL=1
fi
# Verify the critical WhisperKit tokenizer fallback resources.
# xcodebuild bundles have the structure: <bundle>/Contents/Resources/<file>
HUB="VocaMac.app/Contents/Resources/swift-transformers_Hub.bundle"
if [ ! -d "$HUB" ]; then
echo "❌ swift-transformers_Hub.bundle missing!"
FAIL=1
else
for f in gpt2_tokenizer_config.json t5_tokenizer_config.json; do
if find "$HUB" -name "$f" -print -quit | grep -q .; then
echo "✅ $f present in swift-transformers_Hub.bundle"
else
echo "❌ Missing $f in swift-transformers_Hub.bundle"
FAIL=1
fi
done
fi
# Verify the binary uses the xcodebuild accessor (contains resourceURL)
if strings VocaMac.app/Contents/MacOS/VocaMac | grep -q 'resourceURL'; then
echo "✅ Binary uses xcodebuild Bundle.module accessor"
else
echo "❌ Binary does NOT contain resourceURL — wrong accessor!"
echo " Ensure build.sh uses xcodebuild, not swift build."
FAIL=1
fi
if [ "$FAIL" -ne 0 ]; then
echo ""
echo "Bundle layout validation failed. See above for details."
exit 1
fi
echo ""
echo "✅ All bundle checks passed."
- name: Gather artifacts
id: artifacts
run: |
DMG_FILE=$(ls dist/VocaMac-*.dmg | head -1)
DMG_NAME=$(basename "$DMG_FILE")
DMG_SIZE=$(du -h "$DMG_FILE" | cut -f1)
DMG_SHA=$(shasum -a 256 "$DMG_FILE" | awk '{print $1}')
echo "dmg_path=$DMG_FILE" >> "$GITHUB_OUTPUT"
echo "dmg_name=$DMG_NAME" >> "$GITHUB_OUTPUT"
echo "dmg_size=$DMG_SIZE" >> "$GITHUB_OUTPUT"
echo "dmg_sha=$DMG_SHA" >> "$GITHUB_OUTPUT"
# ── Upload & Notify ─────────────────────────────────────────────────────
- name: Upload DMG artifact
uses: actions/upload-artifact@v7
id: upload
with:
name: ${{ steps.artifacts.outputs.dmg_name }}
path: ${{ steps.artifacts.outputs.dmg_path }}
retention-days: 14
- name: Post download comment on PR
uses: actions/github-script@v7
with:
script: |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const artifactUrl = `${runUrl}/artifacts/${{ steps.upload.outputs.artifact-id }}`;
const isQuick = "${{ steps.build_type.outputs.QUICK }}" === "true";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: [
`✅ **PR Build ready!**`,
``,
`| | |`,
`|---|---|`,
`| **DMG** | [\`${{ steps.artifacts.outputs.dmg_name }}\`](${artifactUrl}) |`,
`| **Size** | ${{ steps.artifacts.outputs.dmg_size }} |`,
`| **Branch** | \`${{ steps.pr.outputs.ref }}\` |`,
`| **Commit** | \`${{ steps.pr.outputs.short_sha }}\` |`,
`| **Signed** | ✅ Developer ID |`,
`| **Notarized** | ${isQuick ? '⏭️ Skipped' : '✅ Apple'} |`,
``,
`### 📥 Install`,
`1. Click the DMG link above to download`,
`2. Open the DMG and drag VocaMac to Applications (replace existing)`,
`3. Open VocaMac — ${isQuick ? 'Right-click → Open once to bypass Gatekeeper' : 'No Gatekeeper warnings'}, no permission resets`,
``,
`<details><summary>SHA-256 checksum</summary>`,
``,
`\`\`\``,
`${{ steps.artifacts.outputs.dmg_sha }} ${{ steps.artifacts.outputs.dmg_name }}`,
`\`\`\``,
`</details>`,
``,
`> 💡 Comment \`/build\` or \`/build-quick\` to rebuild.`
].join('\n')
});
# ── Cleanup ─────────────────────────────────────────────────────────────
- name: Delete temporary keychain
if: always()
run: |
security delete-keychain "$KEYCHAIN_PATH" 2>/dev/null || true
# ── Failure notification ────────────────────────────────────────────────
- name: Post failure comment
if: failure()
uses: actions/github-script@v7
with:
script: |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `❌ **PR Build failed** for \`${{ steps.pr.outputs.short_sha }}\`\n\n[View build logs →](${runUrl})\n\n> 💡 Fix the issue and comment \`/build\` to retry.`
});