diff --git a/.gitignore b/.gitignore index a86491db..cc8d7833 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ DerivedData/ coverage.txt TODO.md .ag_template/ -build/ \ No newline at end of file +build/ +.ag_repo/ +.og_repo/ \ No newline at end of file diff --git a/Scripts/bump_ag_pr.sh b/Scripts/bump_ag_pr.sh new file mode 100755 index 00000000..970f9b43 --- /dev/null +++ b/Scripts/bump_ag_pr.sh @@ -0,0 +1,133 @@ +#!/bin/zsh + +set -e + +# A `realpath` alternative using the default C implementation. +filepath() { + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" +} + +# Accept optional branch argument, default to "main" +TARGET_BRANCH="${1:-main}" + +SCRIPT_ROOT="$(dirname $(dirname $(filepath $0)))" +OG_REPO_DIR="$SCRIPT_ROOT/.og_repo" +OPENGRAPH_ROOT="$OG_REPO_DIR" +AG_REPO_DIR="$SCRIPT_ROOT/.ag_repo" + +echo "Starting DarwinPrivateFrameworks bump PR workflow..." +echo "Target branch: $TARGET_BRANCH" + +# Cleanup function +cleanup() { + if [[ -d "$AG_REPO_DIR" ]]; then + echo "Cleaning up temporary repository..." + rm -rf "$AG_REPO_DIR" + fi + if [[ -d "$OG_REPO_DIR" ]]; then + echo "Cleaning up git worktree..." + cd "$SCRIPT_ROOT" + git worktree remove --force "$OG_REPO_DIR" 2>/dev/null || true + fi +} + +# Set trap to cleanup on exit +trap cleanup EXIT + +cd "$SCRIPT_ROOT" + +# Step 1: Setup git worktree for target branch +echo "Setting up git worktree for branch: $TARGET_BRANCH" +if [[ -d "$OG_REPO_DIR" ]]; then + git worktree remove --force "$OG_REPO_DIR" 2>/dev/null || true +fi + +git worktree add "$OG_REPO_DIR" "$TARGET_BRANCH" + +# Step 2: Clone DarwinPrivateFrameworks repository +echo "Cloning DarwinPrivateFrameworks repository..." +if [[ -d "$AG_REPO_DIR" ]]; then + rm -rf "$AG_REPO_DIR" +fi + +gh repo clone OpenSwiftUIProject/DarwinPrivateFrameworks "$AG_REPO_DIR" + +# Step 3: Create new branch based on target branch name +echo "Creating new branch: update-ag-$TARGET_BRANCH" +cd "$AG_REPO_DIR" +git checkout -b "update-ag-$TARGET_BRANCH" + +# Step 4: Generate AG template +echo "Generating AG template..." +cd "$OPENGRAPH_ROOT" +./Scripts/gen_ag_template.sh + +# Step 5: Update DarwinPrivateFrameworks with generated content +echo "Updating DarwinPrivateFrameworks content..." + +# Update headers in Sources/Headers +if [[ -d ".ag_template/Headers" ]]; then + echo "Updating headers..." + rm -rf "$AG_REPO_DIR/AG/2024/Sources/Headers"/* + cp -r .ag_template/Headers/* "$AG_REPO_DIR/AG/2024/Sources/Headers/" +fi + +# Update Swift interface template +if [[ -f ".ag_template/template.swiftinterface" ]]; then + echo "Updating Swift interface template..." + cp .ag_template/template.swiftinterface "$AG_REPO_DIR/AG/2024/Sources/Modules/AttributeGraph.swiftmodule/template.swiftinterface" +fi + +# Step 6: Commit changes in DarwinPrivateFrameworks +echo "Committing changes..." +cd "$AG_REPO_DIR" + +git add . +if git diff --staged --quiet; then + echo "No changes to commit" +else + git commit -m "feat(ag): Update AttributeGraph from OpenGraph $TARGET_BRANCH + +- Updated headers from OpenGraph sources +- Updated Swift interface template +- Generated from OpenGraph branch: $TARGET_BRANCH" +fi + +# Step 7: Update xcframeworks +echo "Updating xcframeworks..." +swift package update-xcframeworks --allow-writing-to-package-directory + +# Commit xcframework updates +git add . +if git diff --staged --quiet; then + echo "No xcframework changes to commit" +else + git commit -m "chore(generated): Update AG framework" +fi + +# Step 8: Push branch and create PR +echo "Pushing branch and creating PR..." +git push origin "update-ag-$TARGET_BRANCH" + +# Create PR +PR_TITLE="Update AttributeGraph from OpenGraph $TARGET_BRANCH" +PR_BODY="Automated update of AttributeGraph framework from OpenGraph. + +**Changes:** +- Updated headers from OpenGraph sources +- Updated Swift interface template +- Updated xcframework binaries + +**Source Branch:** $TARGET_BRANCH +**Generated by:** OpenGraph bump script" + +gh pr create \ + --title "$PR_TITLE" \ + --body "$PR_BODY" \ + --head "update-ag-$TARGET_BRANCH" \ + --base main + +echo "✅ PR created successfully!" +echo "Branch: update-ag-$TARGET_BRANCH" +echo "✅ PR created successfully!" +echo "Branch: update-ag-$CURRENT_BRANCH"