1+ #! /bin/zsh
2+
3+ set -e
4+
5+ # A `realpath` alternative using the default C implementation.
6+ filepath () {
7+ [[ $1 = /* ]] && echo " $1 " || echo " $PWD /${1# ./ } "
8+ }
9+
10+ # Capture script name for usage display
11+ SCRIPT_NAME=" $( basename " $0 " ) "
12+
13+ # Usage function
14+ show_usage () {
15+ cat << EOF
16+ Usage: $SCRIPT_NAME [branch] [--force] [--help]
17+
18+ Automated script to update DarwinPrivateFrameworks with RenderBox changes.
19+
20+ Arguments:
21+ branch Target branch to generate from (default: main)
22+
23+ Options:
24+ --force Force push the branch when creating PR
25+ --help Show this help message
26+
27+ Examples:
28+ $SCRIPT_NAME # Update from main branch
29+ $SCRIPT_NAME develop # Update from develop branch
30+ $SCRIPT_NAME main --force # Update from main with force push
31+ $SCRIPT_NAME --help # Show this help
32+
33+ Description:
34+ This script automates the process of updating DarwinPrivateFrameworks
35+ with the latest RenderBox changes by:
36+ 1. Setting up a git worktree for the target branch
37+ 2. Cloning DarwinPrivateFrameworks repository
38+ 3. Generating RB template from OpenRenderBox
39+ 4. Updating headers and Swift interface templates
40+ 5. Creating and pushing a PR with the changes
41+ EOF
42+ }
43+
44+ # Parse command line arguments
45+ TARGET_BRANCH=" main"
46+ FORCE_PUSH=" "
47+
48+ # Parse arguments
49+ while [[ $# -gt 0 ]]; do
50+ case $1 in
51+ --help)
52+ show_usage
53+ exit 0
54+ ;;
55+ --force)
56+ FORCE_PUSH=" --force"
57+ shift
58+ ;;
59+ * )
60+ TARGET_BRANCH=" $1 "
61+ shift
62+ ;;
63+ esac
64+ done
65+
66+ SCRIPT_ROOT=" $( dirname $( dirname $( filepath $0 ) ) ) "
67+ ORB_REPO_DIR=" $SCRIPT_ROOT /.orb_repo"
68+ OPENRENDERBOX_ROOT=" $ORB_REPO_DIR "
69+ RB_REPO_DIR=" $SCRIPT_ROOT /.rb_repo"
70+
71+ echo " Starting DarwinPrivateFrameworks bump PR workflow..."
72+ echo " Target branch: $TARGET_BRANCH "
73+ if [[ -n " $FORCE_PUSH " ]]; then
74+ echo " Force push: enabled"
75+ fi
76+
77+ # Cleanup function
78+ cleanup () {
79+ if [[ -d " $RB_REPO_DIR " ]]; then
80+ echo " Cleaning up temporary repository..."
81+ rm -rf " $RB_REPO_DIR "
82+ fi
83+ if [[ -d " $ORB_REPO_DIR " ]]; then
84+ echo " Cleaning up git worktree..."
85+ cd " $SCRIPT_ROOT "
86+ git worktree remove --force " $ORB_REPO_DIR " 2> /dev/null || true
87+ fi
88+ }
89+
90+ # Set trap to cleanup on exit
91+ trap cleanup EXIT
92+
93+ cd " $SCRIPT_ROOT "
94+
95+ # Step 1: Setup git worktree for target branch
96+ echo " Setting up git worktree for branch: $TARGET_BRANCH "
97+ if [[ -d " $ORB_REPO_DIR " ]]; then
98+ git worktree remove --force " $ORB_REPO_DIR " 2> /dev/null || true
99+ fi
100+
101+ git worktree add " $ORB_REPO_DIR " " $TARGET_BRANCH "
102+
103+ # Step 2: Clone DarwinPrivateFrameworks repository
104+ echo " Cloning DarwinPrivateFrameworks repository..."
105+ if [[ -d " $RB_REPO_DIR " ]]; then
106+ rm -rf " $RB_REPO_DIR "
107+ fi
108+
109+ gh repo clone OpenSwiftUIProject/DarwinPrivateFrameworks " $RB_REPO_DIR "
110+
111+ # Step 3: Create new branch based on target branch name
112+ echo " Creating new branch: update-rb-$TARGET_BRANCH "
113+ cd " $RB_REPO_DIR "
114+ git checkout -b " update-rb-$TARGET_BRANCH "
115+
116+ # Step 4: Generate RB template
117+ echo " Generating RB template..."
118+ cd " $OPENRENDERBOX_ROOT "
119+ ./Scripts/gen_rb_template.sh
120+
121+ # Step 5: Update DarwinPrivateFrameworks with generated content
122+ echo " Updating DarwinPrivateFrameworks content..."
123+
124+ # Update headers in Sources/Headers
125+ if [[ -d " .rb_template/Headers" ]]; then
126+ echo " Updating headers..."
127+ rm -rf " $RB_REPO_DIR /RB/2024/Sources/Headers" /*
128+ cp -r .rb_template/Headers/* " $RB_REPO_DIR /RB/2024/Sources/Headers/"
129+ fi
130+
131+ # Update Swift interface template
132+ if [[ -f " .rb_template/template.swiftinterface" ]]; then
133+ echo " Updating Swift interface template..."
134+ cp .rb_template/template.swiftinterface " $RB_REPO_DIR /RB/2024/Sources/Modules/RenderBox.swiftmodule/template.swiftinterface"
135+ fi
136+
137+ # Step 6: Commit changes in DarwinPrivateFrameworks
138+ echo " Committing changes..."
139+ cd " $RB_REPO_DIR "
140+
141+ git add .
142+ if git diff --staged --quiet; then
143+ echo " No changes to commit"
144+ else
145+ git commit -m " feat(rb): Update RenderBox from OpenRenderBox $TARGET_BRANCH
146+
147+ - Updated headers from OpenRenderBox sources
148+ - Updated Swift interface template
149+ - Generated from OpenRenderBox branch: $TARGET_BRANCH "
150+ fi
151+
152+ # Step 7: Update xcframeworks
153+ echo " Updating xcframeworks..."
154+ swift package update-xcframeworks --allow-writing-to-package-directory
155+
156+ # Commit xcframework updates
157+ git add .
158+ if git diff --staged --quiet; then
159+ echo " No xcframework changes to commit"
160+ else
161+ git commit -m " chore(generated): Update RB framework"
162+ fi
163+
164+ # Step 8: Push branch and create PR
165+ echo " Pushing branch and creating PR..."
166+ git push origin " update-rb-$TARGET_BRANCH " $FORCE_PUSH
167+
168+ # Create PR
169+ PR_TITLE=" Update RenderBox from OpenRenderBox $TARGET_BRANCH "
170+ PR_BODY=" Automated update of RenderBox framework from OpenRenderBox.
171+
172+ **Changes:**
173+ - Updated headers from OpenRenderBox sources
174+ - Updated Swift interface template
175+ - Updated xcframework binaries
176+
177+ **Source Branch:** $TARGET_BRANCH
178+ **Generated by:** OpenRenderBox bump script"
179+
180+ gh pr create \
181+ --title " $PR_TITLE " \
182+ --body " $PR_BODY " \
183+ --head " update-rb-$TARGET_BRANCH " \
184+ --base main
185+
186+ echo " ✅ PR created successfully!"
187+ echo " Branch: update-rb-$TARGET_BRANCH "
0 commit comments