|
| 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 | +# Step 6: Commit changes in DarwinPrivateFrameworks |
| 132 | +echo "Committing changes..." |
| 133 | +cd "$RB_REPO_DIR" |
| 134 | + |
| 135 | +git add . |
| 136 | +if git diff --staged --quiet; then |
| 137 | + echo "No changes to commit" |
| 138 | +else |
| 139 | + git commit -m "feat(rb): Update RenderBox from OpenRenderBox $TARGET_BRANCH |
| 140 | +
|
| 141 | +- Updated headers from OpenRenderBox sources |
| 142 | +- Generated from OpenRenderBox branch: $TARGET_BRANCH" |
| 143 | +fi |
| 144 | + |
| 145 | +# Step 7: Update xcframeworks |
| 146 | +echo "Updating xcframeworks..." |
| 147 | +swift package update-xcframeworks --allow-writing-to-package-directory |
| 148 | + |
| 149 | +# Commit xcframework updates |
| 150 | +git add . |
| 151 | +if git diff --staged --quiet; then |
| 152 | + echo "No xcframework changes to commit" |
| 153 | +else |
| 154 | + git commit -m "chore(generated): Update RB framework" |
| 155 | +fi |
| 156 | + |
| 157 | +# Step 8: Push branch and create PR |
| 158 | +echo "Pushing branch and creating PR..." |
| 159 | +git push origin "update-rb-$TARGET_BRANCH" $FORCE_PUSH |
| 160 | + |
| 161 | +# Create PR |
| 162 | +PR_TITLE="Update RenderBox from OpenRenderBox $TARGET_BRANCH" |
| 163 | +PR_BODY="Automated update of RenderBox framework from OpenRenderBox. |
| 164 | +
|
| 165 | +**Changes:** |
| 166 | +- Updated headers from OpenRenderBox sources |
| 167 | +- Updated xcframework binaries |
| 168 | +
|
| 169 | +**Source Branch:** $TARGET_BRANCH |
| 170 | +**Generated by:** OpenRenderBox bump script" |
| 171 | + |
| 172 | +gh pr create \ |
| 173 | + --title "$PR_TITLE" \ |
| 174 | + --body "$PR_BODY" \ |
| 175 | + --head "update-rb-$TARGET_BRANCH" \ |
| 176 | + --base main |
| 177 | + |
| 178 | +echo "✅ PR created successfully!" |
| 179 | +echo "Branch: update-rb-$TARGET_BRANCH" |
0 commit comments