Repository navigation
508 lines (438 loc) · 20.6 KB
/
Copy pathrelease.yml
File metadata and controls
508 lines (438 loc) · 20.6 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump from the latest release'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
prerelease:
description: 'Publish as a pre-release (excluded from appcast/latest channel)'
required: false
default: false
type: boolean
permissions:
contents: write
env:
PROJECT_NAME: TransFrame
jobs:
build:
runs-on: macos-15
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release version
id: vars
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Tag pushes intentionally follow patch-only validation; use workflow_dispatch for minor/major releases.
VERSION_BUMP: ${{ github.event.inputs.version_bump || 'patch' }}
run: |
set -euo pipefail
bump_version() {
local version="$1"
local bump="$2"
IFS=. read -r major minor patch <<< "$version"
case "$bump" in
patch)
patch=$((patch + 1))
;;
minor)
minor=$((minor + 1))
patch=0
;;
major)
major=$((major + 1))
minor=0
patch=0
;;
*)
echo "Unsupported version bump: $bump" >&2
exit 1
;;
esac
echo "${major}.${minor}.${patch}"
}
latest_tag=$(gh release list --limit 100 --exclude-drafts --exclude-pre-releases --json tagName \
--jq '[.[].tagName | select(test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))] | sort_by(split(".") | map(ltrimstr("v") | tonumber)) | last // empty')
if [[ -z "$latest_tag" || ! "$latest_tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Cannot determine latest semantic release tag. Latest tag: ${latest_tag:-<empty>}" >&2
exit 1
fi
latest_version="${latest_tag#v}"
expected_version=$(bump_version "$latest_version" "$VERSION_BUMP")
expected_tag="v${expected_version}"
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
VERSION=${GITHUB_REF#refs/tags/v}
# Minor and major releases must be created with workflow_dispatch so the requested bump is explicit.
if [[ "$TAG_NAME" != "$expected_tag" ]]; then
echo "Refusing to release $TAG_NAME. Expected next $VERSION_BUMP release after $latest_tag is $expected_tag." >&2
exit 1
fi
else
TAG_NAME="$expected_tag"
VERSION="$expected_version"
if gh release view "$TAG_NAME" >/dev/null 2>&1; then
echo "Release $TAG_NAME already exists." >&2
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists." >&2
exit 1
fi
fi
source_version=$(grep -m1 'MARKETING_VERSION' TransFrame.xcodeproj/project.pbxproj | sed 's/.*= *//;s/;//' | tr -d ' ')
package_version=$(node -p "require('./package.json').version")
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT
echo "version_bump=${VERSION_BUMP}" >> $GITHUB_OUTPUT
echo "Latest release: $latest_tag"
echo "Resolved release: $TAG_NAME"
echo "Source MARKETING_VERSION: $source_version"
echo "package.json version: $package_version"
- name: Setup Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '26.2'
- name: Auto-increment build number
env:
REPOSITORY: ${{ github.repository }}
RELEASE_VERSION: ${{ steps.vars.outputs.version }}
run: |
VERSION=${RELEASE_VERSION}
# Get current build number from latest release's appcast
APPCAST_BUILD=0
LATEST_APPCAST=$(curl -sL "https://github.com/${REPOSITORY}/releases/latest/download/appcast.xml" 2>/dev/null || echo "")
if [ -n "$LATEST_APPCAST" ]; then
APPCAST_BUILD=$(echo "$LATEST_APPCAST" | grep -o '<sparkle:version>[^<]*</sparkle:version>' | sed 's/<[^>]*>//g' | head -1)
echo "Current build number from appcast: $APPCAST_BUILD"
fi
if ! [[ "$APPCAST_BUILD" =~ ^[0-9]+$ ]]; then
echo "Ignoring invalid appcast build number: $APPCAST_BUILD"
APPCAST_BUILD=0
fi
SOURCE_BUILD=$(grep -m1 'CURRENT_PROJECT_VERSION' TransFrame.xcodeproj/project.pbxproj | sed 's/.*= *//;s/;//' | tr -d ' ')
if ! [[ "$SOURCE_BUILD" =~ ^[0-9]+$ ]]; then
echo "Invalid source build number: $SOURCE_BUILD" >&2
exit 1
fi
CURRENT_BUILD=$APPCAST_BUILD
if [ "$SOURCE_BUILD" -gt "$CURRENT_BUILD" ]; then
CURRENT_BUILD=$SOURCE_BUILD
fi
echo "Current build baseline: $CURRENT_BUILD"
# Increment build number
NEW_BUILD=$((CURRENT_BUILD + 1))
echo "New build number: $NEW_BUILD"
# Update project.pbxproj
sed -i '' "s/CURRENT_PROJECT_VERSION = [0-9]*;/CURRENT_PROJECT_VERSION = $NEW_BUILD;/g" TransFrame.xcodeproj/project.pbxproj
sed -i '' "s/MARKETING_VERSION = [^;]*;/MARKETING_VERSION = $VERSION;/g" TransFrame.xcodeproj/project.pbxproj
echo "Updated to version $VERSION (build $NEW_BUILD)"
echo "new_build=$NEW_BUILD" >> $GITHUB_OUTPUT
- name: Import Apple Certificate
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.MACOS_CERTIFICATE }}
P12_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o "$CERTIFICATE_PATH"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security import "$CERTIFICATE_PATH" -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k "$KEYCHAIN_PATH"
security list-keychains -s "$KEYCHAIN_PATH" $(security list-keychains | tr -d '"')
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
- name: Build Release
run: |
xcodebuild -project ${{ env.PROJECT_NAME }}.xcodeproj \
-scheme ${{ env.PROJECT_NAME }} \
-configuration Release \
-derivedDataPath build \
-destination 'platform=macOS' \
CODE_SIGN_IDENTITY="-" \
CODE_SIGN_STYLE=Automatic \
ARCHS="arm64 x86_64" \
ONLY_ACTIVE_ARCH=NO \
clean build
- name: Sign App & Create DMG
id: create_dmg
run: |
# Dynamically resolve signing identity from imported keychain (prioritizing Developer ID Application)
SIGN_IDENTITY=$(security find-identity -v -p codesigning "$RUNNER_TEMP/app-signing.keychain-db" | grep -m1 "Developer ID Application" | awk -F '"' '{print $2}' || true)
if [ -z "$SIGN_IDENTITY" ]; then
SIGN_IDENTITY=$(security find-identity -v -p codesigning "$RUNNER_TEMP/app-signing.keychain-db" | head -1 | awk -F '"' '{print $2}' || true)
fi
if [ -n "$SIGN_IDENTITY" ]; then
echo "Signing application bundle with: $SIGN_IDENTITY"
# --timestamp adds the RFC 3161 secure timestamp Apple notarization
# requires; --timestamp=none made the submission Invalid (1.0.2/1.0.3).
codesign --force --deep --options runtime --timestamp \
--sign "$SIGN_IDENTITY" \
build/Build/Products/Release/${{ env.PROJECT_NAME }}.app
else
echo "Warning: No code signing identity found, falling back to ad-hoc signing"
codesign --force --deep --sign - \
build/Build/Products/Release/${{ env.PROJECT_NAME }}.app
fi
mkdir -p dmg_temp
cp -R build/Build/Products/Release/${{ env.PROJECT_NAME }}.app dmg_temp/
ln -sf /Applications dmg_temp/Applications
VERSION=${{ steps.vars.outputs.version }}
DMG_FILE="${{ env.PROJECT_NAME }}-${VERSION}.dmg"
hdiutil create -volname "${{ env.PROJECT_NAME }}" \
-srcfolder dmg_temp \
-ov -format UDZO \
"$DMG_FILE"
# arm64-only build; single suffixed artifact — the appcast and the
# release notes both point at this file. No un-suffixed duplicate:
# an Intel download would not launch anyway (deployment target is
# arm64-only), and Sparkle reads the URL from our own appcast.
# Get file size
DMG_SIZE=$(stat -f%z "$DMG_FILE")
echo "dmg_size=$DMG_SIZE" >> $GITHUB_OUTPUT
echo "dmg_file=$DMG_FILE" >> $GITHUB_OUTPUT
rm -rf dmg_temp
- name: Notarize & Staple App
id: notarize
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
APP_PATH="build/Build/Products/Release/${{ env.PROJECT_NAME }}.app"
VERSION=${{ steps.vars.outputs.version }}
if [ -z "$APPLE_ID" ] || [ -z "$APPLE_APP_SPECIFIC_PASSWORD" ] || [ -z "$APPLE_TEAM_ID" ]; then
echo "Warning: Notarization secrets not configured, skipping notarization"
echo "notarized=false" >> $GITHUB_OUTPUT
exit 0
fi
if codesign -dv "$APP_PATH" 2>&1 | grep -q "Signature=adhoc"; then
echo "Warning: App is ad-hoc signed, skipping notarization"
echo "notarized=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Creating ZIP for notarization submission..."
ZIP_PATH="$RUNNER_TEMP/${{ env.PROJECT_NAME }}-${VERSION}-notarize.zip"
ditto -c -k --keepParent "$APP_PATH" "$ZIP_PATH"
echo "Submitting to Apple notarization service..."
SUBMIT_LOG="$RUNNER_TEMP/notary-submit.log"
xcrun notarytool submit "$ZIP_PATH" \
--apple-id "$APPLE_ID" \
--password "$APPLE_APP_SPECIFIC_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait \
--timeout 120m 2>&1 | tee "$SUBMIT_LOG"
# notarytool exits 0 even for status: Invalid or a wait timeout —
# surface the failure (and Apple's issue list) instead of failing
# later at stapler with exit 65 / "Record not found".
if grep -q "status: Invalid" "$SUBMIT_LOG"; then
SUBMIT_ID=$(grep -oE 'id: [0-9a-f-]{36}' "$SUBMIT_LOG" | head -1 | awk '{print $2}')
echo "Notarization Invalid. Fetching Apple's issues for submission ${SUBMIT_ID:-<unknown>}..."
if [ -n "$SUBMIT_ID" ]; then
xcrun notarytool log "$SUBMIT_ID" \
--apple-id "$APPLE_ID" \
--password "$APPLE_APP_SPECIFIC_PASSWORD" \
--team-id "$APPLE_TEAM_ID" || true
fi
echo "##[error]Apple notarization rejected the submission"
exit 1
fi
if ! grep -q "status: Accepted" "$SUBMIT_LOG"; then
SUBMIT_ID=$(grep -oE 'id: [0-9a-f-]{36}' "$SUBMIT_LOG" | head -1 | awk '{print $2}')
echo "##[error]Notarization did not reach Accepted (timeout or unknown status). Submission: ${SUBMIT_ID:-<unknown>}"
if [ -n "$SUBMIT_ID" ]; then
echo "Polling the submission in case Apple finished after the wait window..."
xcrun notarytool info "$SUBMIT_ID" \
--apple-id "$APPLE_ID" \
--password "$APPLE_APP_SPECIFIC_PASSWORD" \
--team-id "$APPLE_TEAM_ID" || true
fi
exit 1
fi
# stapler downloads the ticket from Apple's CloudKit, which can drop
# the connection transiently (-1005) — retry before giving up.
staple_with_retry() {
local target="$1"
for attempt in 1 2 3 4 5; do
if xcrun stapler staple "$target"; then
return 0
fi
echo "staple attempt $attempt for $target failed, retrying in 10s..."
sleep 10
done
return 1
}
# stapler validate also queries Apple's CloudKit for the ticket and
# hits the same transient -1005 disconnects.
validate_with_retry() {
local target="$1"
for attempt in 1 2 3 4 5; do
if xcrun stapler validate "$target"; then
return 0
fi
echo "validate attempt $attempt for $target failed, retrying in 10s..."
sleep 10
done
return 1
}
echo "Stapling notarization ticket to app..."
if ! staple_with_retry "$APP_PATH"; then
echo "##[error]stapler staple failed for app after 5 attempts"
exit 1
fi
echo "Verifying notarization..."
if ! validate_with_retry "$APP_PATH"; then
echo "##[error]stapler validate failed for app after 5 attempts"
exit 1
fi
spctl --assess --type execute --verbose "$APP_PATH"
echo "Notarization complete."
echo "Recreating DMG with stapled app..."
DMG_FILE="${{ env.PROJECT_NAME }}-${VERSION}.dmg"
mkdir -p dmg_temp
cp -R "$APP_PATH" dmg_temp/
ln -sf /Applications dmg_temp/Applications
hdiutil create -volname "${{ env.PROJECT_NAME }}" \
-srcfolder dmg_temp \
-ov -format UDZO \
"$DMG_FILE"
echo "Notarizing DMG..."
DMG_ZIP="$RUNNER_TEMP/${{ env.PROJECT_NAME }}-${VERSION}-dmg.zip"
ditto -c -k --keepParent "$DMG_FILE" "$DMG_ZIP"
xcrun notarytool submit "$DMG_ZIP" \
--apple-id "$APPLE_ID" \
--password "$APPLE_APP_SPECIFIC_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait \
--timeout 120m
if ! staple_with_retry "$DMG_FILE"; then
echo "##[error]stapler staple failed for DMG after 5 attempts"
exit 1
fi
rm -rf dmg_temp
rm -f "$ZIP_PATH" "$DMG_ZIP"
# Update DMG size for appcast (may have changed after notarization)
NEW_DMG_SIZE=$(stat -f%z "$DMG_FILE")
echo "dmg_size=$NEW_DMG_SIZE" >> $GITHUB_OUTPUT
echo "notarized=true" >> $GITHUB_OUTPUT
- name: Sign DMG for Sparkle
id: sign_dmg
run: |
VERSION=${{ steps.vars.outputs.version }}
DMG_FILE="${{ env.PROJECT_NAME }}-${VERSION}.dmg"
# Find sign_update tool in derived data
SIGN_TOOL=$(find build/SourcePackages/artifacts -name "sign_update" -type f | head -1)
if [ -z "$SIGN_TOOL" ]; then
echo "sign_update tool not found, checking alternative locations..."
SIGN_TOOL=$(find build -name "sign_update" -type f | head -1)
fi
if [ -n "$SIGN_TOOL" ]; then
echo "Found sign_update at: $SIGN_TOOL"
# Sign the DMG and get the signature
SIGNATURE=$(echo "${{ secrets.SPARKLE_PRIVATE_KEY }}" | "$SIGN_TOOL" --ed-key-file - -p "$DMG_FILE" 2>&1)
echo "Signature: $SIGNATURE"
echo "signature=$SIGNATURE" >> $GITHUB_OUTPUT
else
echo "sign_update tool not found, skipping signing"
echo "signature=" >> $GITHUB_OUTPUT
fi
- name: Generate pubDate
id: pubdate
run: echo "date=$(date -Ru)" >> $GITHUB_OUTPUT
- name: Get Build Number
id: build_number
run: |
# Extract build number from project
BUILD_NUM=$(grep -m1 'CURRENT_PROJECT_VERSION' TransFrame.xcodeproj/project.pbxproj | sed 's/.*= *//;s/;//' | tr -d ' ')
echo "build_num=$BUILD_NUM" >> $GITHUB_OUTPUT
- name: Get Tag Message
id: tag_message
env:
TAG_NAME: ${{ steps.vars.outputs.tag_name }}
run: |
# Get the tag annotation message (remove trailing PGP signature using POSIX-compatible sed)
TAG_MESSAGE=$(git tag -l --format='%(contents)' "$TAG_NAME" | sed '/^-----BEGIN PGP SIGNATURE-----/,$d' || echo "")
# If tag message is empty, use a default message
if [ -z "$TAG_MESSAGE" ]; then
TAG_MESSAGE="Latest release of TransFrame"
fi
# Escape CDATA boundaries for safe XML wrapping (not entity escaping, since we use CDATA)
TAG_MESSAGE=$(echo "$TAG_MESSAGE" | sed 's/]]>/]]]]><![CDATA[>/g')
# Generate a unique delimiter to avoid collision with message content
DELIMITER="EOF_$(uuidgen | tr -d '-')"
echo "message<<${DELIMITER}" >> $GITHUB_OUTPUT
echo "$TAG_MESSAGE" >> $GITHUB_OUTPUT
echo "${DELIMITER}" >> $GITHUB_OUTPUT
- name: Generate Sparkle Appcast
env:
RELEASE_NOTES: ${{ steps.tag_message.outputs.message }}
run: |
VERSION=${{ steps.vars.outputs.version }}
BUILD_NUM="${{ steps.build_number.outputs.build_num }}"
DMG_URL="https://github.com/${{ github.repository }}/releases/download/${{ steps.vars.outputs.tag_name }}/${{ env.PROJECT_NAME }}-${VERSION}.dmg"
PUBDATE="${{ steps.pubdate.outputs.date }}"
DMG_SIZE="${{ steps.notarize.outputs.dmg_size || steps.create_dmg.outputs.dmg_size }}"
SIGNATURE="${{ steps.sign_dmg.outputs.signature }}"
# Build enclosure tag with or without signature
if [ -n "$SIGNATURE" ]; then
ENCLOSURE="<enclosure url=\"${DMG_URL}\" length=\"${DMG_SIZE}\" type=\"application/octet-stream\" sparkle:edSignature=\"${SIGNATURE}\" />"
else
ENCLOSURE="<enclosure url=\"${DMG_URL}\" length=\"${DMG_SIZE}\" type=\"application/octet-stream\" />"
fi
# Generate unique delimiter to avoid collision with release notes content
APPCAST_DELIMITER="APPCAST_EOF_$(uuidgen | tr -d '-')"
cat > appcast.xml << ${APPCAST_DELIMITER}
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>${{ env.PROJECT_NAME }} Updates</title>
<link>https://github.com/${{ github.repository }}/releases</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>Version ${VERSION}</title>
<pubDate>${PUBDATE}</pubDate>
<sparkle:version>${BUILD_NUM}</sparkle:version>
<sparkle:shortVersionString>${VERSION}</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>26.0</sparkle:minimumSystemVersion>
${ENCLOSURE}
<description><![CDATA[${RELEASE_NOTES}]]></description>
</item>
</channel>
</rss>
${APPCAST_DELIMITER}
echo "Generated appcast.xml:"
cat appcast.xml
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.vars.outputs.tag_name }}
target_commitish: ${{ github.sha }}
prerelease: ${{ inputs.prerelease }}
files: |
${{ env.PROJECT_NAME }}-*.dmg
appcast.xml
generate_release_notes: true
body: |
> **注意**:本构建为 **universal**(arm64 + x86_64),Intel 与 Apple Silicon Mac 均可运行,需 macOS 15.0+。Apple 翻译引擎需 macOS 26,旧系统上将自动使用链中的其他引擎。
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cleanup
if: always()
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db 2>/dev/null || true
rm -rf build