Skip to content

Commit f07f67f

Browse files
Merge pull request #3 from SomeRandomiOSDev/XCFramework
Added a new script + workflows for building an XCFramework and uploading it to releases
2 parents 852d099 + 24f5087 commit f07f67f

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Upload Assets
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
build:
8+
name: Upload Assets
9+
runs-on: macOS-latest
10+
env:
11+
TMPDIR: /tmp/.protocolproxy.xcframework.build
12+
13+
steps:
14+
- name: Checkout Code
15+
uses: actions/checkout@v2
16+
17+
- name: Build
18+
run: |
19+
./scripts/xcframework.sh -output ${TMPDIR}/${GITHUB_SHA}/ProtocolProxy.xcframework
20+
21+
- name: Create Zip
22+
run: |
23+
zip -rX ${TMPDIR}/${GITHUB_SHA}/ProtocolProxy.xcframework.zip ${TMPDIR}/${GITHUB_SHA}/ProtocolProxy.xcframework
24+
25+
- name: Upload Zip
26+
uses: actions/upload-release-asset@v1
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
upload_url: ${{ github.event.release.upload_url }}
31+
asset_path: ${{ env.TMPDIR }}/${{ env.GITHUB_SHA }}/ProtocolProxy.xcframework.zip
32+
asset_name: ProtocolProxy.xcframework.zip
33+
asset_content_type: application/zip
34+
35+
- name: Create Tar
36+
run: |
37+
tar -zcvf ${TMPDIR}/${GITHUB_SHA}/ProtocolProxy.xcframework.tar.gz ${TMPDIR}/${GITHUB_SHA}/ProtocolProxy.xcframework
38+
39+
- name: Upload Tar
40+
uses: actions/upload-release-asset@v1
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
with:
44+
upload_url: ${{ github.event.release.upload_url }}
45+
asset_path: ${{ env.TMPDIR }}/${{ env.GITHUB_SHA }}/ProtocolProxy.xcframework.tar.gz
46+
asset_name: ProtocolProxy.xcframework.tar.gz
47+
asset_content_type: application/gzip

.github/workflows/xcframework.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: XCFramework
2+
on: push
3+
4+
jobs:
5+
build:
6+
name: Build
7+
runs-on: macOS-latest
8+
env:
9+
TMPDIR: /tmp/.protocolproxy.xcframework.build
10+
11+
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@v2
14+
15+
- name: Build
16+
run: |
17+
./scripts/xcframework.sh -output ${TMPDIR}/${GITHUB_SHA}/ProtocolProxy.xcframework

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ ProtocolProxy.xcodeproj/xcuserdata
33

44
.build
55
.swiftpm
6+
scripts/build

scripts/xcframework.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
3+
# xcframework.sh
4+
# Usage example: ./xcframework.sh -output <some_path>/ProtocolProxy.xcframework
5+
6+
# Parse Arguments
7+
8+
while [[ $# -gt 0 ]]; do
9+
case "$1" in
10+
-output)
11+
OUTPUT_DIR="$2"
12+
shift # -output
13+
shift # <output_dir>
14+
;;
15+
16+
*)
17+
echo "Unknown argument: $1"
18+
echo "./xcframework.sh [-output <output_xcframework>]"]
19+
exit 1
20+
esac
21+
done
22+
23+
if [ -z ${OUTPUT_DIR+x} ]; then
24+
OUTPUT_DIR="$(dirname $(realpath $0))/build/ProtocolProxy.xcframework"
25+
fi
26+
27+
# Create Temporary Directory
28+
29+
TMPDIR=`mktemp -d /tmp/.protocolproxy.xcframework.build.XXXXXX`
30+
cd "$(dirname $(dirname $(realpath $0)))"
31+
32+
check_result() {
33+
if [ $1 -ne 0 ]; then
34+
rm -rf "${TMPDIR}"
35+
exit $1
36+
fi
37+
}
38+
39+
# Build iOS
40+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy" -destination "generic/platform=iOS" -archivePath "${TMPDIR}/iphoneos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="armv7 armv7s arm64 arm64e" archive
41+
check_result $?
42+
43+
# Build iOS Simulator
44+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy" -destination "generic/platform=iOS Simulator" -archivePath "${TMPDIR}/iphonesimulator.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="i386 x86_64 arm64" archive
45+
check_result $?
46+
47+
# Build Mac Catalyst
48+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy" -destination "generic/platform=macOS,variant=Mac Catalyst" -archivePath "${TMPDIR}/maccatalyst.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="x86_64 arm64 arm64e" archive
49+
check_result $?
50+
51+
# Build Mac
52+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy macOS" -destination "generic/platform=macOS" -archivePath "${TMPDIR}/macos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="x86_64 arm64 arm64e" archive
53+
check_result $?
54+
55+
# Build tvOS
56+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy tvOS" -destination "generic/platform=tvOS" -archivePath "${TMPDIR}/appletvos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="arm64 arm64e" archive
57+
check_result $?
58+
59+
# Build tvOS Simulator
60+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy tvOS" -destination "generic/platform=tvOS Simulator" -archivePath "${TMPDIR}/appletvsimulator.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="x86_64 arm64" archive
61+
check_result $?
62+
63+
# Build watchOS
64+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy watchOS" -destination "generic/platform=watchOS" -archivePath "${TMPDIR}/watchos.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="arm64_32 armv7k" archive
65+
check_result $?
66+
67+
# Build watchOS Simulator
68+
xcodebuild -project "ProtocolProxy.xcodeproj" -scheme "ProtocolProxy watchOS" -destination "generic/platform=watchOS Simulator" -archivePath "${TMPDIR}/watchsimulator.xcarchive" -configuration Release SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES ONLY_ACTIVE_ARCH=NO ARCHS="i386 x86_64 arm64" archive
69+
check_result $?
70+
71+
# Make XCFramework
72+
73+
if [[ -d "${OUTPUT_DIR}" ]]; then
74+
rm -rf "${OUTPUT_DIR}"
75+
fi
76+
77+
xcodebuild -create-xcframework \
78+
-framework "${TMPDIR}/iphoneos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
79+
-framework "${TMPDIR}/iphonesimulator.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
80+
-framework "${TMPDIR}/maccatalyst.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
81+
-framework "${TMPDIR}/macos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
82+
-framework "${TMPDIR}/appletvos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
83+
-framework "${TMPDIR}/appletvsimulator.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
84+
-framework "${TMPDIR}/watchos.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
85+
-framework "${TMPDIR}/watchsimulator.xcarchive/Products/Library/Frameworks/ProtocolProxy.framework" \
86+
-output "${OUTPUT_DIR}"
87+
check_result $?
88+
89+
# Cleanup
90+
91+
rm -rf "${TMPDIR}"
92+
exit 0

0 commit comments

Comments
 (0)