forked from Dicklesworthstone/agentic_coding_flywheel_setup
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (105 loc) · 4.51 KB
/
upstream-sync.yml
File metadata and controls
124 lines (105 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Upstream Sync
on:
schedule:
- cron: '0 0 * * *' # Daily at midnight
workflow_dispatch:
permissions:
contents: write
pull-requests: write
issues: write
jobs:
sync:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_BRANCH: local-desktop-installation-support
SYNC_BRANCH: upstream-sync
UPSTREAM_URL: https://github.com/Dicklesworthstone/agentic_coding_flywheel_setup.git
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.TARGET_BRANCH }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Add and Fetch Upstream
run: |
git remote add upstream "$UPSTREAM_URL"
git fetch upstream
- name: Prepare Sync Branch
run: |
# Reset sync branch to target branch to ensure a clean slate
git checkout -B "$SYNC_BRANCH" "$TARGET_BRANCH"
- name: Merge Upstream
id: merge
continue-on-error: true
run: |
# Attempt to merge. If conflicts, this will fail (exit 1)
if git merge upstream/main --no-edit; then
echo "merge_status=success" >> "$GITHUB_OUTPUT"
echo "Merge successful."
else
echo "merge_status=conflict" >> "$GITHUB_OUTPUT"
echo "Merge conflict detected."
fi
- name: Handle Conflicts
if: steps.merge.outputs.merge_status == 'conflict'
run: |
echo "Committing conflict markers..."
# Add all files with conflict markers
git add .
git commit -m "Merge upstream/main (with conflicts)"
- name: Push Sync Branch
run: |
git push -f origin "$SYNC_BRANCH"
- name: Create Pull Request
if: steps.merge.outputs.merge_status == 'success' || steps.merge.outputs.merge_status == 'conflict'
run: |
# Check if PR already exists
existing_pr=$(gh pr list --head "$SYNC_BRANCH" --base "$TARGET_BRANCH" --json number -q '.[0].number')
if [[ -z "$existing_pr" ]]; then
echo "Creating new PR..."
if [[ "${{ steps.merge.outputs.merge_status }}" == "conflict" ]]; then
TITLE="⚠️ Upstream Sync (Conflicts Detected)"
BODY="This PR syncs changes from upstream. **Conflicts were detected and committed with markers.** Please review and resolve them."
LABELS="upstream-sync,conflict"
else
TITLE="🔄 Upstream Sync (Clean)"
BODY="This PR syncs changes from upstream. No conflicts detected."
LABELS="upstream-sync"
fi
PR_URL=$(gh pr create \
--title "$TITLE" \
--body "$BODY" \
--head "$SYNC_BRANCH" \
--base "$TARGET_BRANCH" \
--label "$LABELS")
echo "PR_URL=$PR_URL" >> "$GITHUB_ENV"
else
echo "Updating existing PR #$existing_pr..."
echo "PR_URL=https://github.com/${{ github.repository }}/pull/$existing_pr" >> "$GITHUB_ENV"
# Update comments/labels if status changed
if [[ "${{ steps.merge.outputs.merge_status }}" == "conflict" ]]; then
gh pr edit "$existing_pr" --title "⚠️ Upstream Sync (Conflicts Detected)" --add-label "conflict" --body "Updates from upstream. Conflicts detected."
else
gh pr edit "$existing_pr" --title "🔄 Upstream Sync (Clean)" --remove-label "conflict" --body "Updates from upstream. Clean merge."
fi
fi
- name: Analyze Conflicts with AI
if: steps.merge.outputs.merge_status == 'conflict' && env.OPENAI_API_KEY != ''
run: |
echo "Analyzing conflicts..."
# We need to install dependencies for the script if any
# For now assuming simple script or checking for package.json
# Run the analysis script
# Passing PR URL or Number potentially needed for the script to post comments
# Actually, if we use gh cli in the script, we just need GH_TOKEN
bun run ./scripts/analyze-conflicts.ts "${{ env.PR_URL }}"