Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocC Deployment #10

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
@@ -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 "<script>window.location.href += \"/documentation/agorachat\"</script>" > 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
*.xcframework
*.xcframework.zip
docc_builder
docs
12 changes: 12 additions & 0 deletions doc_gen/dl_framework.sh
Original file line number Diff line number Diff line change
@@ -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)
Binary file added doc_gen/docc_builder.zip
Binary file not shown.
54 changes: 54 additions & 0 deletions doc_gen/headers_to_xcodeproj.sh
Original file line number Diff line number Diff line change
@@ -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 = \"\<group\>\"; };"
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
82 changes: 82 additions & 0 deletions doc_gen/move_header_files.sh
Original file line number Diff line number Diff line change
@@ -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 = "<group>"; };
file_ref_line=" $file_uuid /* $file_name */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = \"$file_name\"; sourceTree = \"<group>\"; };"
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