55 - cron : ' 0 0 * * *' # Daily at midnight
66 workflow_dispatch :
77
8+ concurrency :
9+ group : upstream-sync
10+ cancel-in-progress : false
11+
812permissions :
913 contents : write
1014 pull-requests : write
@@ -14,19 +18,26 @@ jobs:
1418 sync :
1519 runs-on : ubuntu-latest
1620 env :
17- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
18- MAIN_BRANCH : main
19- TARGET_BRANCH : local-desktop-installation-support
20- SYNC_BRANCH : upstream-sync
21- UPSTREAM_URL : https://github.com/Dicklesworthstone/agentic_coding_flywheel_setup.git
22- OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
21+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22+ PUSH_TOKEN : ${{ secrets.UPSTREAM_SYNC_TOKEN }}
23+ MAIN_BRANCH : main
24+ TARGET_BRANCH : local-desktop-installation-support
25+ SYNC_BRANCH : upstream-sync
26+ UPSTREAM_URL : https://github.com/Dicklesworthstone/agentic_coding_flywheel_setup.git
27+ OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
2328
2429 steps :
2530 - name : Checkout
2631 uses : actions/checkout@v4
2732 with :
2833 fetch-depth : 0
2934 ref : ${{ env.MAIN_BRANCH }}
35+ token : ${{ secrets.UPSTREAM_SYNC_TOKEN != '' && secrets.UPSTREAM_SYNC_TOKEN || secrets.GITHUB_TOKEN }}
36+
37+ - name : Warn if mirror token is missing
38+ if : env.PUSH_TOKEN == ''
39+ run : |
40+ echo "::warning::UPSTREAM_SYNC_TOKEN is not configured. Pushes that update .github/workflows may be rejected."
3041
3142 - name : Configure Git
3243 run : |
@@ -40,29 +51,33 @@ jobs:
4051
4152 - name : Add and Fetch Upstream
4253 run : |
43- git remote add upstream "$UPSTREAM_URL"
54+ if git remote get-url upstream >/dev/null 2>&1; then
55+ git remote set-url upstream "$UPSTREAM_URL"
56+ else
57+ git remote add upstream "$UPSTREAM_URL"
58+ fi
4459 git fetch upstream
4560
4661 # Step 1: Sync fork's main branch with upstream/main (Pure Mirror)
4762 - name : Sync Main Branch with Upstream
4863 run : |
4964 echo "Syncing fork's main branch with upstream/main..."
50-
65+
5166 # Hard reset main to match upstream/main exactly
5267 git checkout "$MAIN_BRANCH"
5368 git reset --hard upstream/main
54-
69+
5570 # Force push to update the fork's main branch
5671 git push -f origin "$MAIN_BRANCH"
57-
72+
5873 echo "✅ Fork's main branch is now a pure mirror of upstream/main"
5974
6075 # Step 2: Merge main into local-desktop-installation-support
6176 - name : Prepare Integration Branch
6277 run : |
6378 # Checkout the integration branch
6479 git checkout "$TARGET_BRANCH"
65-
80+
6681 # Create/reset sync branch from target for the merge
6782 git checkout -B "$SYNC_BRANCH" "$TARGET_BRANCH"
6883
98113 # Ensure labels exist to prevent errors during PR creation
99114 gh label create upstream-sync --repo ${{ github.repository }} --description "Syncs changes from upstream" --color 1d76db || true
100115 gh label create conflict --repo ${{ github.repository }} --description "Merge conflicts detected" --color b60205 || true
101-
102- # Debug: List labels to verify visibility
103- gh label list --repo ${{ github.repository }}
104116
105117 # Step 3: Handle result based on merge status
106118 - name : Push Clean Merge Directly
@@ -115,35 +127,35 @@ jobs:
115127 run : |
116128 # Check if PR already exists
117129 existing_pr=$(gh pr list --repo ${{ github.repository }} --head "$SYNC_BRANCH" --base "$TARGET_BRANCH" --json number -q '.[0].number')
118-
130+
119131 if [[ -z "$existing_pr" ]]; then
120132 echo "Creating new PR for conflict resolution..."
121133 TITLE="⚠️ Upstream Sync (Conflicts Detected)"
122134 BODY="This PR syncs changes from upstream. **Conflicts were detected and committed with markers.** Please review and resolve them."
123- LABELS="upstream-sync,conflict"
124-
135+
125136 PR_URL=$(gh pr create \
126137 --repo ${{ github.repository }} \
127138 --title "$TITLE" \
128139 --body "$BODY" \
129140 --head "$SYNC_BRANCH" \
130141 --base "$TARGET_BRANCH" \
131- --label "$LABELS")
132-
142+ --label "upstream-sync" \
143+ --label "conflict")
144+
133145 echo "PR_URL=$PR_URL" >> "$GITHUB_ENV"
134146 else
135- echo "Updating existing PR #$existing_pr..."
136- echo "PR_URL=https://github.com/${{ github.repository }}/pull/$existing_pr" >> "$GITHUB_ENV"
137-
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."
147+ echo "Updating existing PR #$existing_pr..."
148+ echo "PR_URL=https://github.com/${{ github.repository }}/pull/$existing_pr" >> "$GITHUB_ENV"
149+
150+ gh pr edit "$existing_pr" --repo ${{ github.repository }} \
151+ --title "⚠️ Upstream Sync (Conflicts Detected)" \
152+ --add-label "conflict" \
153+ --body "Updates from upstream. Conflicts detected."
142154 fi
143155
144156 - name : Analyze Conflicts with AI
145157 if : steps.merge.outputs.merge_status == 'conflict' && env.OPENAI_API_KEY != ''
146158 run : |
147159 echo "Analyzing conflicts..."
148160 # Run the analysis script
149- bun run ./scripts/analyze-conflicts.ts "${{ env.PR_URL }}"
161+ bun run ./scripts/analyze-conflicts.ts "${{ env.PR_URL }}"
0 commit comments