Skip to content

Commit bff130d

Browse files
committed
Enhances DMG creation and build process
Refines the build workflow to ensure correct versioning and improve the DMG creation process. - Updates the Info.plist with version and build number and verifies that the changes are applied. - Adds a fallback mechanism when the initial build scheme fails by attempting to build with the first available scheme. - Uses `create-dmg` to generate a more visually appealing DMG with a link to the Applications folder. Falls back to a simple DMG if fancy DMG creation fails.
1 parent a2858a2 commit bff130d

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

.github/workflows/release.yml

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,21 @@ jobs:
9696
- name: Update version and build number
9797
run: |
9898
PLIST_PATH="${PLIST_PATH:-./Kettle/Info.plist}"
99+
100+
# 确保使用标准格式的版本号和构建号
99101
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" "$PLIST_PATH"
100102
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "$PLIST_PATH"
101103
102104
echo "📱 App version updated to $VERSION (Build: $BUILD_NUMBER)"
103105
echo "Info.plist content:"
104106
cat "$PLIST_PATH"
107+
108+
# 确保构建前能看到更新后的 Info.plist
109+
cp -f "$PLIST_PATH" "./Kettle/Info.plist" || echo "Already in the right place"
110+
111+
# 确认最终的 Info.plist 内容
112+
echo "Final Info.plist content for build:"
113+
cat "./Kettle/Info.plist"
105114
106115
- name: List available schemes
107116
run: |
@@ -111,19 +120,36 @@ jobs:
111120
- name: Build app
112121
run: |
113122
# 尝试构建应用
114-
xcodebuild clean archive -project "Kettle.xcodeproj" -scheme "Kettle" -archivePath "build/Kettle.xcarchive" CODE_SIGN_IDENTITY="-" || {
123+
xcodebuild clean archive \
124+
-project "Kettle.xcodeproj" \
125+
-scheme "Kettle" \
126+
-archivePath "build/Kettle.xcarchive" \
127+
CODE_SIGN_IDENTITY="-" \
128+
CURRENT_PROJECT_VERSION=$BUILD_NUMBER \
129+
MARKETING_VERSION=$VERSION || {
130+
115131
echo "Build failed. Trying alternate scheme..."
116132
# 尝试构建第一个找到的 scheme
117133
FIRST_SCHEME=$(xcodebuild -list -project "Kettle.xcodeproj" -json 2>/dev/null | grep -o '"name" : "[^"]*"' | head -1 | cut -d'"' -f4)
118134
if [ -n "$FIRST_SCHEME" ]; then
119135
echo "Trying to build with scheme: $FIRST_SCHEME"
120-
xcodebuild clean archive -project "Kettle.xcodeproj" -scheme "$FIRST_SCHEME" -archivePath "build/Kettle.xcarchive" CODE_SIGN_IDENTITY="-"
136+
xcodebuild clean archive \
137+
-project "Kettle.xcodeproj" \
138+
-scheme "$FIRST_SCHEME" \
139+
-archivePath "build/Kettle.xcarchive" \
140+
CODE_SIGN_IDENTITY="-" \
141+
CURRENT_PROJECT_VERSION=$BUILD_NUMBER \
142+
MARKETING_VERSION=$VERSION
121143
else
122144
echo "No schemes found. Build failed."
123145
exit 1
124146
fi
125147
}
126148
149+
- name: Install create-dmg
150+
run: |
151+
brew install create-dmg
152+
127153
- name: Create DMG
128154
run: |
129155
# 创建临时目录
@@ -141,8 +167,49 @@ jobs:
141167
fi
142168
}
143169
144-
# 创建 DMG
145-
hdiutil create -volname "Kettle" -srcfolder build/dmg -ov -format UDZO "build/$DMG_NAME"
170+
# 创建带有 Applications 链接的 DMG
171+
APP_NAME="Kettle"
172+
DMG_DIR="build/dmg_final"
173+
mkdir -p "$DMG_DIR"
174+
cp -R "build/dmg/Kettle.app" "$DMG_DIR"
175+
176+
# 创建指向 Applications 的符号链接
177+
ln -s /Applications "$DMG_DIR/Applications"
178+
179+
# 使用 create-dmg 创建美观的 DMG
180+
DMG_PATH="build/$DMG_NAME"
181+
182+
# 检查是否有图标文件
183+
ICON_OPTION=""
184+
if [ -f "Kettle/Resources/AppIcon.icns" ]; then
185+
ICON_OPTION="--volicon Kettle/Resources/AppIcon.icns"
186+
fi
187+
188+
# 检查是否有背景图像
189+
BG_OPTION=""
190+
if [ -f "Kettle/Resources/dmg-background.png" ]; then
191+
BG_OPTION="--background Kettle/Resources/dmg-background.png"
192+
fi
193+
194+
create-dmg \
195+
--volname "$APP_NAME" \
196+
$ICON_OPTION \
197+
$BG_OPTION \
198+
--window-pos 200 120 \
199+
--window-size 600 400 \
200+
--icon-size 100 \
201+
--icon "$APP_NAME.app" 150 190 \
202+
--hide-extension "$APP_NAME.app" \
203+
--app-drop-link 450 190 \
204+
--no-internet-enable \
205+
"$DMG_PATH" \
206+
"$DMG_DIR" \
207+
|| {
208+
echo "Failed to create fancy DMG. Falling back to simple DMG with Applications link."
209+
# 创建简单的 DMG 作为备选,但保留 Applications 链接
210+
hdiutil create -volname "Kettle" -srcfolder "$DMG_DIR" -ov -format UDZO "$DMG_PATH"
211+
}
212+
146213
echo "📦 App built and DMG created at build/$DMG_NAME"
147214
148215
- name: Upload DMG as artifact

Kettle/Info.plist

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
<string>AppIcon</string>
77
<key>CFBundleIconName</key>
88
<string>AppIcon</string>
9+
<key>CFBundleShortVersionString</key>
10+
<string>1.0.0</string>
11+
<key>CFBundleVersion</key>
12+
<string>1</string>
913
</dict>
10-
</plist>
14+
</plist>

0 commit comments

Comments
 (0)