Skip to content

Commit f6dddec

Browse files
committed
feat: release
1 parent a1c290b commit f6dddec

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
release:
10+
runs-on: macos-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Setup Xcode
19+
uses: maxim-lobanov/setup-xcode@v1
20+
with:
21+
xcode-version: latest-stable
22+
23+
- name: Get tag name
24+
id: tag
25+
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
26+
27+
- name: Build XCFramework
28+
run: |
29+
chmod +x build-xcframework.sh
30+
./build-xcframework.sh CacheKit
31+
32+
- name: Calculate checksum
33+
id: checksum
34+
run: |
35+
CHECKSUM=$(shasum -a 256 build/CacheKit.xcframework.zip | cut -d' ' -f1)
36+
echo "CHECKSUM=$CHECKSUM" >> $GITHUB_OUTPUT
37+
echo "Checksum: $CHECKSUM"
38+
39+
- name: Create Release
40+
id: create_release
41+
uses: actions/create-release@v1
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
with:
45+
tag_name: ${{ steps.tag.outputs.TAG_NAME }}
46+
release_name: Release ${{ steps.tag.outputs.TAG_NAME }}
47+
draft: false
48+
prerelease: false
49+
50+
- name: Upload XCFramework to Release
51+
uses: actions/upload-release-asset@v1
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
with:
55+
upload_url: ${{ steps.create_release.outputs.upload_url }}
56+
asset_path: build/CacheKit.xcframework.zip
57+
asset_name: CacheKit.xcframework.zip
58+
asset_content_type: application/zip
59+
60+
- name: Update Package.swift
61+
run: |
62+
# Update Package.swift with new URL and checksum
63+
sed -i '' "s|url: \"https://github.com/BBC6BAE9/cachekit/releases/download/.*/CacheKit.xcframework.zip\"|url: \"https://github.com/BBC6BAE9/cachekit/releases/download/${{ steps.tag.outputs.TAG_NAME }}/CacheKit.xcframework.zip\"|g" Package.swift
64+
sed -i '' "s|checksum: \".*\"|checksum: \"${{ steps.checksum.outputs.CHECKSUM }}\"|g" Package.swift
65+
echo "Updated Package.swift for tag ${{ steps.tag.outputs.TAG_NAME }} with checksum ${{ steps.checksum.outputs.CHECKSUM }}"
66+
67+
- name: Commit updated Package.swift
68+
run: |
69+
git config --local user.email "[email protected]"
70+
git config --local user.name "GitHub Action"
71+
git add Package.swift
72+
if git diff --staged --quiet; then
73+
echo "No changes to commit"
74+
else
75+
git commit -m "Update Package.swift for release ${{ steps.tag.outputs.TAG_NAME }}"
76+
git push origin HEAD:main
77+
fi

build-xcframework.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,42 @@ main() {
290290
XCFRAMEWORK_SIZE=$(du -h "$XCFRAMEWORK_OUTPUT" | cut -f1)
291291
print_status "XCFramework size: $XCFRAMEWORK_SIZE"
292292

293+
# Create ZIP archive for distribution
294+
print_status "Creating ZIP archive for distribution..."
295+
ZIP_OUTPUT="${BUILD_DIR}/${NAME}.xcframework.zip"
296+
297+
cd "$BUILD_DIR"
298+
zip -r "${NAME}.xcframework.zip" "${NAME}.xcframework"
299+
cd - > /dev/null
300+
301+
if [ -f "$ZIP_OUTPUT" ]; then
302+
ZIP_SIZE=$(du -h "$ZIP_OUTPUT" | cut -f1)
303+
print_success "ZIP archive created: $ZIP_OUTPUT (Size: $ZIP_SIZE)"
304+
305+
# Calculate and display checksum
306+
print_status "Calculating SHA256 checksum..."
307+
CHECKSUM=$(shasum -a 256 "$ZIP_OUTPUT" | cut -d' ' -f1)
308+
print_status "SHA256 Checksum: $CHECKSUM"
309+
echo "$CHECKSUM" > "${ZIP_OUTPUT}.checksum"
310+
print_status "Checksum saved to: ${ZIP_OUTPUT}.checksum"
311+
else
312+
print_error "Failed to create ZIP archive"
313+
fi
314+
293315
print_success ""
294316
print_success "🎉 Build completed successfully!"
295317
print_success ""
318+
print_status "Generated files:"
319+
print_status " 📦 XCFramework: $XCFRAMEWORK_OUTPUT"
320+
print_status " 🗜️ ZIP Archive: $ZIP_OUTPUT"
321+
print_status " 🔐 Checksum: ${ZIP_OUTPUT}.checksum"
322+
print_success ""
296323
print_status "Next steps:"
297324
print_status "1. Drag $XCFRAMEWORK_OUTPUT to your Xcode project"
298325
print_status "2. Add to 'Frameworks, Libraries, and Embedded Content'"
299326
print_status "3. Set embedding option as needed"
300327
print_status "4. Import $NAME in your Swift files"
328+
print_status "5. For SPM binary target, use $ZIP_OUTPUT"
301329
print_success ""
302330
print_status "Based on tutorial: https://davidwanderer.github.io/Blog/2024/05/12/如何将Swift-Package编译成XCFramework/"
303331
else

0 commit comments

Comments
 (0)