1515 runs-on : ubuntu-latest
1616 env :
1717 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
18+ MAIN_BRANCH : main
1819 TARGET_BRANCH : local-desktop-installation-support
1920 SYNC_BRANCH : upstream-sync
2021 UPSTREAM_URL : https://github.com/Dicklesworthstone/agentic_coding_flywheel_setup.git
2526 uses : actions/checkout@v4
2627 with :
2728 fetch-depth : 0
28- ref : ${{ env.TARGET_BRANCH }}
29+ ref : ${{ env.MAIN_BRANCH }}
2930
3031 - name : Configure Git
3132 run : |
@@ -42,17 +43,35 @@ jobs:
4243 git remote add upstream "$UPSTREAM_URL"
4344 git fetch upstream
4445
45- - name : Prepare Sync Branch
46+ # Step 1: Sync fork's main branch with upstream/main (Pure Mirror)
47+ - name : Sync Main Branch with Upstream
4648 run : |
47- # Reset sync branch to target branch to ensure a clean slate
49+ echo "Syncing fork's main branch with upstream/main..."
50+
51+ # Hard reset main to match upstream/main exactly
52+ git checkout "$MAIN_BRANCH"
53+ git reset --hard upstream/main
54+
55+ # Force push to update the fork's main branch
56+ git push -f origin "$MAIN_BRANCH"
57+
58+ echo "✅ Fork's main branch is now a pure mirror of upstream/main"
59+
60+ # Step 2: Merge main into local-desktop-installation-support
61+ - name : Prepare Integration Branch
62+ run : |
63+ # Checkout the integration branch
64+ git checkout "$TARGET_BRANCH"
65+
66+ # Create/reset sync branch from target for the merge
4867 git checkout -B "$SYNC_BRANCH" "$TARGET_BRANCH"
4968
50- - name : Merge Upstream
69+ - name : Merge Main into Integration Branch
5170 id : merge
5271 continue-on-error : true
5372 run : |
54- # Attempt to merge. If conflicts, this will fail (exit 1)
55- if git merge upstream/main --no-edit; then
73+ # Attempt to merge main (which is now synced with upstream) into the integration branch
74+ if git merge "$MAIN_BRANCH" --no-edit; then
5675 echo "merge_status=success" >> "$GITHUB_OUTPUT"
5776 echo "Merge successful."
5877 else
@@ -66,18 +85,12 @@ jobs:
6685 echo "Committing conflict markers..."
6786 # Add all files with conflict markers
6887 git add .
69- git commit -m "Merge upstream/ main (with conflicts)"
88+ git commit -m "Merge main into $TARGET_BRANCH (with conflicts)"
7089
7190 - name : Push Sync Branch
7291 run : |
7392 git push -f origin "$SYNC_BRANCH"
7493
75- - name : Push to Target (Auto-Merge)
76- if : steps.merge.outputs.merge_status == 'success'
77- run : |
78- git push origin "$SYNC_BRANCH:$TARGET_BRANCH"
79- echo "Successfully synced to $TARGET_BRANCH"
80-
8194 - name : Ensure Labels Exist
8295 env :
8396 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -89,14 +102,22 @@ jobs:
89102 # Debug: List labels to verify visibility
90103 gh label list --repo ${{ github.repository }}
91104
92- - name : Create Pull Request
105+ # Step 3: Handle result based on merge status
106+ - name : Push Clean Merge Directly
107+ if : steps.merge.outputs.merge_status == 'success'
108+ run : |
109+ echo "Clean merge - pushing directly to $TARGET_BRANCH..."
110+ git push origin "$SYNC_BRANCH:$TARGET_BRANCH"
111+ echo "✅ Successfully synced to $TARGET_BRANCH"
112+
113+ - name : Create Pull Request for Conflicts
93114 if : steps.merge.outputs.merge_status == 'conflict'
94115 run : |
95116 # Check if PR already exists
96117 existing_pr=$(gh pr list --repo ${{ github.repository }} --head "$SYNC_BRANCH" --base "$TARGET_BRANCH" --json number -q '.[0].number')
97118
98119 if [[ -z "$existing_pr" ]]; then
99- echo "Creating new PR..."
120+ echo "Creating new PR for conflict resolution ..."
100121 TITLE="⚠️ Upstream Sync (Conflicts Detected)"
101122 BODY="This PR syncs changes from upstream. **Conflicts were detected and committed with markers.** Please review and resolve them."
102123 LABELS="upstream-sync,conflict"
@@ -114,19 +135,15 @@ jobs:
114135 echo "Updating existing PR #$existing_pr..."
115136 echo "PR_URL=https://github.com/${{ github.repository }}/pull/$existing_pr" >> "$GITHUB_ENV"
116137
117- # Update comments/labels if status changed
118- gh pr edit "$existing_pr" --repo ${{ github.repository }} --title "⚠️ Upstream Sync (Conflicts Detected)" --add-label "conflict" --body "Updates from upstream. Conflicts detected."
138+ gh pr edit "$existing_pr" --repo ${{ github.repository }} \
139+ --title "⚠️ Upstream Sync (Conflicts Detected)" \
140+ --add-label "conflict" \
141+ --body "Updates from upstream. Conflicts detected."
119142 fi
120143
121144 - name : Analyze Conflicts with AI
122145 if : steps.merge.outputs.merge_status == 'conflict' && env.OPENAI_API_KEY != ''
123146 run : |
124147 echo "Analyzing conflicts..."
125- # We need to install dependencies for the script if any
126- # For now assuming simple script or checking for package.json
127-
128148 # Run the analysis script
129- # Passing PR URL or Number potentially needed for the script to post comments
130- # Actually, if we use gh cli in the script, we just need GH_TOKEN
131-
132- bun run ./scripts/analyze-conflicts.ts "${{ env.PR_URL }}"
149+ bun run ./scripts/analyze-conflicts.ts "${{ env.PR_URL }}"
0 commit comments