Skip to content

Commit

Permalink
Add script to upload to emerge (#399) (#400)
Browse files Browse the repository at this point in the history
* Add script to upload to emerge

* Fix missing `Combine` import

* Update buildEmerge.yml

---------

Co-authored-by: Itay Brenner <[email protected]>
  • Loading branch information
piercifani and Itaybre committed Oct 18, 2024
1 parent 796f1d2 commit 3b7a475
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/buildEmerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build Emerge

on:
push:
branches: [develop]

jobs:
build:
name: Build XCFramework
runs-on: ios
env:
PRODUCT_NAME: BSWInterfaceKit

steps:
- uses: actions/checkout@v4
with:
lfs: true

- name: Build XCFramework
run: sh build.sh $PRODUCT_NAME

- name: Upload artifact to Emerge
uses: EmergeTools/[email protected]
with:
build_type: release
artifact_path: ./${{ env.PRODUCT_NAME }}.xcframework.zip
emerge_api_key: ${{ secrets.EMERGE_API_KEY }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ Carthage/Build
fastlane/report.xml
fastlane/screenshots
.DS_Store

BSWInterfaceKit-*.xcarchive
BSWInterfaceKit.xcframework.zip
BSWInterfaceKit.xcframework
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if canImport(SwiftUI)

import SwiftUI
import Combine

/// As of iOS 18 and aligned releases, this is no longer recommended as
/// there are cleaner alternatives like `InfiniteVerticalScrollView`
Expand Down
80 changes: 80 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd -P)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

PROJECT_BUILD_DIR="${PROJECT_BUILD_DIR:-"${PROJECT_ROOT}/build"}"
XCODEBUILD_BUILD_DIR="$PROJECT_BUILD_DIR/xcodebuild"
XCODEBUILD_DERIVED_DATA_PATH="$XCODEBUILD_BUILD_DIR/DerivedData"

PACKAGE_NAME=$1
if [ -z "$PACKAGE_NAME" ]; then
echo "No package name provided. Using the first scheme found in the Package.swift."
PACKAGE_NAME=$(xcodebuild -list | awk 'schemes && NF>0 { print $1; exit } /Schemes:$/ { schemes = 1 }')
echo "Using: $PACKAGE_NAME"
fi

backup_package_swift() {
cp Package.swift Package.swift.bak
}

restore_package_swift() {
mv Package.swift.bak Package.swift
}

modify_package_swift() {
sed -i '' 's/type: .static,//g' Package.swift
sed -i '' 's/type: .dynamic,//g' Package.swift
sed -i '' -e ':a' -e 'N' -e '$!ba' -e 's/\(library[^,]*name: [^,]*,\)/\1 type: .dynamic,/g' Package.swift
}

build_framework() {
local sdk="$1"
local destination="$2"
local scheme="$3"

local XCODEBUILD_ARCHIVE_PATH="./$scheme-$sdk.xcarchive"

rm -rf "$XCODEBUILD_ARCHIVE_PATH"

xcodebuild archive \
-scheme $scheme \
-archivePath $XCODEBUILD_ARCHIVE_PATH \
-derivedDataPath "$XCODEBUILD_DERIVED_DATA_PATH" \
-sdk "$sdk" \
-destination "$destination" \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
INSTALL_PATH='Library/Frameworks' \
OTHER_SWIFT_FLAGS=-no-verify-emitted-module-interface \
| xcbeautify

FRAMEWORK_MODULES_PATH="$XCODEBUILD_ARCHIVE_PATH/Products/Library/Frameworks/$scheme.framework/Modules"
mkdir -p "$FRAMEWORK_MODULES_PATH"
cp -r \
"$XCODEBUILD_DERIVED_DATA_PATH/Build/Intermediates.noindex/ArchiveIntermediates/$scheme/BuildProductsPath/Release-$sdk/$scheme.swiftmodule" \
"$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule"
# Delete private swiftinterface
rm -f "$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule/*.private.swiftinterface"
}

echo "Modifying Package.swift"
backup_package_swift
modify_package_swift

build_framework "iphonesimulator" "generic/platform=iOS Simulator" "$PACKAGE_NAME"
build_framework "iphoneos" "generic/platform=iOS" "$PACKAGE_NAME"

echo "Builds completed successfully."

rm -rf "$PACKAGE_NAME.xcframework"
xcodebuild -create-xcframework -framework $PACKAGE_NAME-iphonesimulator.xcarchive/Products/Library/Frameworks/$PACKAGE_NAME.framework -framework $PACKAGE_NAME-iphoneos.xcarchive/Products/Library/Frameworks/$PACKAGE_NAME.framework -output $PACKAGE_NAME.xcframework

cp -r $PACKAGE_NAME-iphonesimulator.xcarchive/dSYMs $PACKAGE_NAME.xcframework/ios-arm64_x86_64-simulator
cp -r $PACKAGE_NAME-iphoneos.xcarchive/dSYMs $PACKAGE_NAME.xcframework/ios-arm64

zip -r "$PACKAGE_NAME.xcframework.zip" "$PACKAGE_NAME.xcframework"

echo "Restoring Package.swift"
restore_package_swift

0 comments on commit 3b7a475

Please sign in to comment.