diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml new file mode 100644 index 0000000..1ab77f0 --- /dev/null +++ b/.github/workflows/deploy_docs.yml @@ -0,0 +1,52 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy DocC + +on: + # Runs on new releases + release: + types: [published] + push: + branches: [docc_deploy, main] + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow one concurrent deployment +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + # Single deploy job since we're just deploying + deploy: + # Will only publish if the new release matches with the latest main branch commit. + if: ${{ github.event.release.prerelease == false && github.event.release.draft == false }} + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: macos-12 + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + - name: Build DocC + run: | + sh -e doc_gen/dl_framework.sh AgoraChat + sh -e doc_gen/move_header_files.sh AgoraChat.xcframework + sh -e doc_gen/headers_to_xcodeproj.sh AgoraChat docc_builder + xcodebuild -project docc_builder/AgoraChat.xcodeproj docbuild -scheme AgoraChat -derivedDataPath /tmp/docbuild -destination generic/platform=iOS + $(xcrun --find docc) process-archive \ + transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/AgoraChat.doccarchive \ + --hosting-base-path AgoraChat_iOS \ + --output-path docs; + echo "" > docs/index.html + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + # Upload docs directory + path: 'docs' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v1 diff --git a/.gitignore b/.gitignore index 3b29812..51b1f33 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ DerivedData/ .swiftpm/config/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc +*.xcframework +*.xcframework.zip +docc_builder +docs \ No newline at end of file diff --git a/doc_gen/dl_framework.sh b/doc_gen/dl_framework.sh new file mode 100644 index 0000000..5a5c9a1 --- /dev/null +++ b/doc_gen/dl_framework.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +framework_name=$1 + +# Get URL for AgoraRtcKit binary target from Package.swift +url=$(grep -m 1 "https.*$framework_name.*.xcframework.zip" Package.swift | sed -E "s/.*(https.*$framework_name.*.xcframework.zip).*/\1/") + +# Download the AgoraRtcKit xcframework zip file +curl -O $url + +# Extract the contents of the zip file to the current directory +unzip $(basename $url) diff --git a/doc_gen/docc_builder.zip b/doc_gen/docc_builder.zip new file mode 100644 index 0000000..0614f76 Binary files /dev/null and b/doc_gen/docc_builder.zip differ diff --git a/doc_gen/headers_to_xcodeproj.sh b/doc_gen/headers_to_xcodeproj.sh new file mode 100644 index 0000000..78eea6e --- /dev/null +++ b/doc_gen/headers_to_xcodeproj.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +xcframework_path=$1 +frameworkname=$(basename "$xcframework_path" | cut -f 1 -d '.') +xcoderoot="$2" + +# Set the path to the .pbxproj file +pbxproj_path="$xcoderoot/$frameworkname.xcodeproj/project.pbxproj" +echo "Building framework: $frameworkname" + +# Set the path to the directory containing the header files +headers_dir="$xcoderoot/$frameworkname/Headers" +#!/bin/bash + +private_headers="AgoraChat-Swift.h, AgoraChatOptions+PrivateDeploy.h, NSObject+Coding.h" + +# Add each header file to the project +for file_path in "$headers_dir"/*.h; do + if [ "$(basename "$file_path")" = "$frameworkname.h" ]; then + continue + fi + file_name=$(basename "$file_path") + file_uuid=$(uuidgen) + echo "Adding $file_name to project" + + # Add a line to the PBXFileReference section :done for basic files: + file_ref_line=" $file_uuid /* $file_name */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = \"$file_name\"; sourceTree = \"\\"; };" + sed -i '' -e $'/End PBXFileReference section/ i\\\n'"$file_ref_line" "$pbxproj_path" + + # Add a line to the PBXBuildFile section :done for basic files: + build_file_uuid=$(uuidgen) + build_file_line=" $build_file_uuid /* $file_name in Headers */ = {isa = PBXBuildFile; fileRef = $file_uuid /* $file_name */; };" + if [[ "$private_headers" == *"$file_name"* ]]; then + echo $file_name + else + build_file_line="$build_file_uuid /* $file_name in Headers */ = {isa = PBXBuildFile; fileRef = $file_uuid /* $file_name */; settings = {ATTRIBUTES = (Public, ); }; };" + sed -i '' -E "s/#import +\"(.*)\"/#import <$frameworkname\/\1>/" "$file_path" + fi + + sed -i '' -e $'/End PBXBuildFile section/ i\\\n'"$build_file_line" "$pbxproj_path" + + # Add the file to the Headers group in the PBXGroup section + line_number=$(awk '/path = Headers;/ {print NR-1; exit}' "$pbxproj_path") + # Insert the file to the children list in the PBXGroup section + group_line=" $file_uuid /* $file_name */," + sed -i '' -e "${line_number}i\\ + $group_line" "$pbxproj_path" + + # Add the file to the Headers build phase in the PBXHeadersBuildPhase section + line_number=$(awk '/isa = PBXHeadersBuildPhase;/ {print NR+3; exit}' "$pbxproj_path") + build_phase_line=" $build_file_uuid /* $file_name in Headers */," + sed -i '' -e "${line_number}i\\ + $build_phase_line" "$pbxproj_path" +done \ No newline at end of file diff --git a/doc_gen/move_header_files.sh b/doc_gen/move_header_files.sh new file mode 100644 index 0000000..e84be08 --- /dev/null +++ b/doc_gen/move_header_files.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +zippedxcodeproj=$(dirname "${BASH_SOURCE[0]}")/docc_builder.zip + +unzip "$zippedxcodeproj" + +xcframework_path=$1 +frameworkname="$(basename "$xcframework_path" | cut -f 1 -d '.')" +xcoderoot=docc_builder +doccpath=$2 +pbxproj_path="$xcoderoot/$frameworkname.xcodeproj/project.pbxproj" + +# Set the source and destination directories +src_dir="$xcframework_path/ios-arm64_armv7/$frameworkname.framework/Headers" +dest_dir="$xcoderoot/$frameworkname" + +# Replace all instances of "FRAMEWORK_NAME" with the new value +mv $xcoderoot/FRAMEWORK_NAME.xcodeproj $xcoderoot/$frameworkname.xcodeproj +mv $xcoderoot/FRAMEWORK_NAME $xcoderoot/$frameworkname +sed -i '' "s/FRAMEWORK_NAME/$frameworkname/g" $pbxproj_path +# main_group=$(grep -o 'mainGroup = [[:alnum:]]\{24\}' $pbxproj_path | cut -d' ' -f3 | tr -d ';') + +# Copy all header files including "AgoraRtcKit.h" to the Headers subdirectory +find "$src_dir" -type f -name "*.h" -exec cp {} "$dest_dir/Headers" \; + +file_name=$(basename "$frameworkname.h") +file_uuid=$(uuidgen) +echo "Adding $file_name to project" +build_file_uuid=$(uuidgen) +# F3B5915329E28E6E007A92E3 /* AgoraRtcKit.h in Headers */ = {isa = PBXBuildFile; fileRef = F3B5915229E28E6E007A92E3 /* AgoraRtcKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; +build_file_line=" $build_file_uuid /* $file_name in Headers */ = {isa = PBXBuildFile; fileRef = $file_uuid /* $file_name */; settings = {ATTRIBUTES = (Public, ); }; };" +echo "$build_file_line" +sed -i '' -e $'/End PBXBuildFile section/ i\\\n'"$build_file_line" "$pbxproj_path" + +# F3B5915229E28E6E007A92E3 /* AgoraRtcKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AgoraRtcKit.h; sourceTree = ""; }; +file_ref_line=" $file_uuid /* $file_name */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = \"$file_name\"; sourceTree = \"\"; };" +echo "$file_ref_line" +sed -i '' -e $'/End PBXFileReference section/ i\\\n'"$file_ref_line" "$pbxproj_path" + +# Add the file to the Headers group in the PBXGroup section +line_number=$(awk '/path = Headers;/ {print NR-1; exit}' "$pbxproj_path") +# Insert the file to the children list in the PBXGroup section +group_line=" $file_uuid /* $file_name */," +sed -i '' -e "${line_number}i\\ + $group_line" "$pbxproj_path" + +# Add the file to the Headers build phase in the PBXHeadersBuildPhase section +line_number=$(awk '/isa = PBXHeadersBuildPhase;/ {print NR+3; exit}' "$pbxproj_path") +build_phase_line=" $build_file_uuid /* $file_name in Headers */," +sed -i '' -e "${line_number}i\\ + $build_phase_line" "$pbxproj_path" + +if [ ! -z $2 ]; then + # Add DocC + # cp -r $doccpath $dest_dir + file_name=$(basename "$dest_dir/$doccpath") + file_uuid=$(uuidgen) + echo "Adding $file_name to project" + docc_relpath="../$doccpath" + + build_file_uuid=$(uuidgen) + build_file_line=" $build_file_uuid /* $file_name in Sources */ = {isa = PBXBuildFile; fileRef = $file_uuid /* $file_name */; };" + sed -i '' -e $'/End PBXBuildFile section/ i\\\n'"$build_file_line" "$pbxproj_path" + + file_ref_line=" $file_uuid /* $file_name */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; name = $file_name; path = $docc_relpath; sourceTree = SOURCE_ROOT; };" + + echo "$file_ref_line" + sed -i '' -e $'/End PBXFileReference section/ i\\\n'"$file_ref_line" "$pbxproj_path" + + # Add the file to the Headers build phase in the PBXSourcesBuildPhase section + line_number=$(awk '/isa = PBXSourcesBuildPhase;/ {print NR+3; exit}' "$pbxproj_path") + build_phase_line=" $build_file_uuid /* $file_name */," + echo "$build_phase_line" + sed -i '' -e "${line_number}i\\ + $build_phase_line" "$pbxproj_path" + + line_number=$(awk -v frameworkname=$frameworkname -v string="path = ${frameworkname};" '$0 ~ string {print NR-2; exit}' $pbxproj_path) + file_ref_line=" $file_uuid /* $file_name */," + echo "$file_ref_line" + sed -i '' -e "${line_number}i\\ + $file_ref_line" "$pbxproj_path" +fi