Skip to content

Commit 5391f8a

Browse files
committed
Add bump_ag_pr script
1 parent 52f9ffc commit 5391f8a

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ DerivedData/
99
coverage.txt
1010
TODO.md
1111
.ag_template/
12-
build/
12+
build/
13+
.ag_repo/
14+
.og_repo/

Scripts/bump_ag_pr.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
# Accept optional branch argument, default to "main"
11+
TARGET_BRANCH="${1:-main}"
12+
13+
SCRIPT_ROOT="$(dirname $(dirname $(filepath $0)))"
14+
OG_REPO_DIR="$SCRIPT_ROOT/.og_repo"
15+
OPENGRAPH_ROOT="$OG_REPO_DIR"
16+
TEMP_REPO_DIR="$SCRIPT_ROOT/.ag_repo"
17+
CURRENT_BRANCH=$(git branch --show-current)
18+
19+
echo "Starting DarwinPrivateFrameworks bump PR workflow..."
20+
echo "Target branch: $TARGET_BRANCH"
21+
echo "Current branch: $CURRENT_BRANCH"
22+
23+
# Cleanup function
24+
cleanup() {
25+
if [[ -d "$TEMP_REPO_DIR" ]]; then
26+
echo "Cleaning up temporary repository..."
27+
rm -rf "$TEMP_REPO_DIR"
28+
fi
29+
if [[ -d "$OG_REPO_DIR" ]]; then
30+
echo "Cleaning up git worktree..."
31+
cd "$SCRIPT_ROOT"
32+
git worktree remove --force "$OG_REPO_DIR" 2>/dev/null || true
33+
fi
34+
}
35+
36+
# Set trap to cleanup on exit
37+
trap cleanup EXIT
38+
39+
cd "$SCRIPT_ROOT"
40+
41+
# Step 1: Setup git worktree for target branch
42+
echo "Setting up git worktree for branch: $TARGET_BRANCH"
43+
if [[ -d "$OG_REPO_DIR" ]]; then
44+
git worktree remove --force "$OG_REPO_DIR" 2>/dev/null || true
45+
fi
46+
47+
git worktree add "$OG_REPO_DIR" "$TARGET_BRANCH"
48+
49+
# Step 2: Clone DarwinPrivateFrameworks repository
50+
echo "Cloning DarwinPrivateFrameworks repository..."
51+
if [[ -d "$TEMP_REPO_DIR" ]]; then
52+
rm -rf "$TEMP_REPO_DIR"
53+
fi
54+
55+
gh repo clone OpenSwiftUIProject/DarwinPrivateFrameworks "$TEMP_REPO_DIR"
56+
57+
# Step 3: Create new branch based on target branch name
58+
echo "Creating new branch: update-ag-$TARGET_BRANCH"
59+
cd "$TEMP_REPO_DIR"
60+
git checkout -b "update-ag-$TARGET_BRANCH"
61+
62+
# Step 4: Generate AG template
63+
echo "Generating AG template..."
64+
cd "$OPENGRAPH_ROOT"
65+
./Scripts/gen_ag_template.sh
66+
67+
# Step 5: Update DarwinPrivateFrameworks with generated content
68+
echo "Updating DarwinPrivateFrameworks content..."
69+
70+
# Update headers in Sources/Headers
71+
if [[ -d ".ag_template/Headers" ]]; then
72+
echo "Updating headers..."
73+
rm -rf "$TEMP_REPO_DIR/AG/2024/Sources/Headers"/*
74+
cp -r .ag_template/Headers/* "$TEMP_REPO_DIR/AG/2024/Sources/Headers/"
75+
fi
76+
77+
# Update Swift interface template
78+
if [[ -f ".ag_template/template.swiftinterface" ]]; then
79+
echo "Updating Swift interface template..."
80+
cp .ag_template/template.swiftinterface "$TEMP_REPO_DIR/AG/2024/Sources/Modules/AttributeGraph.swiftmodule/template.swiftinterface"
81+
fi
82+
83+
# Step 6: Commit changes in DarwinPrivateFrameworks
84+
echo "Committing changes..."
85+
cd "$TEMP_REPO_DIR"
86+
87+
git add .
88+
if git diff --staged --quiet; then
89+
echo "No changes to commit"
90+
else
91+
git commit -m "feat(ag): Update AttributeGraph from OpenGraph $CURRENT_BRANCH
92+
93+
- Updated headers from OpenGraph sources
94+
- Updated Swift interface template
95+
- Generated from OpenGraph branch: $CURRENT_BRANCH"
96+
fi
97+
98+
# Step 7: Update xcframeworks
99+
echo "Updating xcframeworks..."
100+
swift package update-xcframeworks --allow-writing-to-package-directory
101+
102+
# Commit xcframework updates
103+
git add .
104+
if git diff --staged --quiet; then
105+
echo "No xcframework changes to commit"
106+
else
107+
git commit -m "chore(generated): Update AG framework"
108+
fi
109+
110+
# Step 8: Push branch and create PR
111+
echo "Pushing branch and creating PR..."
112+
git push origin "update-ag-$CURRENT_BRANCH"
113+
114+
# Create PR
115+
PR_TITLE="Update AttributeGraph from OpenGraph $CURRENT_BRANCH"
116+
PR_BODY="Automated update of AttributeGraph framework from OpenGraph.
117+
118+
**Changes:**
119+
- Updated headers from OpenGraph sources
120+
- Updated Swift interface template
121+
- Updated xcframework binaries
122+
123+
**Source Branch:** $CURRENT_BRANCH
124+
**Generated by:** OpenGraph bump script"
125+
126+
gh pr create \
127+
--title "$PR_TITLE" \
128+
--body "$PR_BODY" \
129+
--head "update-ag-$CURRENT_BRANCH" \
130+
--base main
131+
132+
echo "✅ PR created successfully!"
133+
echo "Branch: update-ag-$CURRENT_BRANCH"

0 commit comments

Comments
 (0)