Skip to content

Commit b4dbb0d

Browse files
authored
Add bump_ag_pr script (#156)
1 parent 07157fa commit b4dbb0d

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

0 commit comments

Comments
 (0)