-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (166 loc) · 7.41 KB
/
sync.yml
File metadata and controls
201 lines (166 loc) · 7.41 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Sync from upstream
on:
schedule:
- cron: '0 * * * *' # Hourly at the top of every hour
workflow_dispatch: # Manual trigger
env:
UPSTREAM_REPO: "garrytan/gstack"
FILTER_SCRIPT: "scripts/filter_skills.py"
CLEANUP_SCRIPT: "scripts/cleanup.py"
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Fireworks AI SDK
run: |
pip install --pre fireworks-ai
- name: Configure Git
run: |
git config user.name "Ambisphaeric"
git config user.email "Ambisphaeric@users.noreply.github.com"
- name: Add upstream remote
run: |
git remote add upstream https://github.com/${{ env.UPSTREAM_REPO }}.git
git fetch upstream main --tags 2>/dev/null || git fetch upstream master --tags 2>/dev/null || true
- name: Get upstream info
id: upstream
run: |
UPSTREAM_BRANCH=$(git rev-parse --verify upstream/main 2>/dev/null || git rev-parse --verify upstream/master 2>/dev/null || echo "")
echo "sha=$UPSTREAM_BRANCH" >> $GITHUB_OUTPUT
if [ -n "$UPSTREAM_BRANCH" ]; then
UPSTREAM_VERSION=$(git ls-remote upstream refs/tags/v* 2>/dev/null | sort -V | tail -1 | sed 's/.*v//' || echo "unknown")
echo "version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
fi
- name: Check for updates
id: check
run: |
CURRENT=$(git rev-parse HEAD 2>/dev/null || echo "")
UPSTREAM=${{ steps.upstream.outputs.sha }}
if [ -z "$UPSTREAM" ]; then
echo "updating=false" >> $GITHUB_OUTPUT
echo "No upstream found"
exit 0
fi
if [ "$CURRENT" = "$UPSTREAM" ]; then
echo "updating=false" >> $GITHUB_OUTPUT
echo "Already up to date with upstream"
else
echo "updating=true" >> $GITHUB_OUTPUT
echo "Updates available from upstream"
fi
- name: Create sync branch
if: steps.check.outputs.updating == 'true'
run: |
BRANCH_NAME="sync/upstream-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
id: branch
- name: Intelligent merge from upstream
if: steps.check.outputs.updating == 'true'
env:
FIREWORKS_API_KEY: ${{ secrets.AI_KEY }}
run: |
# Attempt clean merge first
if git merge upstream/main --no-edit -m "chore: merge from ${{ env.UPSTREAM_REPO }}" 2>/dev/null; then
echo "Clean merge successful"
else
echo "Merge conflicts detected, using AI to resolve..."
git merge --abort 2>/dev/null || true
# Get list of conflicting files
git merge upstream/main --no-commit || true
CONFLICTS=$(git diff --name-only --diff-filter=U)
if [ -n "$CONFLICTS" ]; then
echo "Resolving conflicts with Fireworks AI for:"
echo "$CONFLICTS"
python3 << 'PYEOF'
import os
import sys
import subprocess
from fireworks.client import Fireworks
client = Fireworks(api_key=os.environ['FIREWORKS_API_KEY'])
# Get conflicted files
result = subprocess.run(['git', 'diff', '--name-only', '--diff-filter=U'],
capture_output=True, text=True)
conflicts = result.stdout.strip().split('\n')
for filepath in conflicts:
if not filepath:
continue
try:
with open(filepath, 'r') as f:
content = f.read()
# Use AI to resolve the conflict
response = client.chat.completions.create(
model="accounts/fireworks/models/llama-v3p1-70b-instruct",
messages=[
{"role": "system", "content": "You are a code merge expert. Resolve git conflicts by keeping the best parts of both versions, preferring the incoming upstream changes while preserving OpenGStack's telemetry removal modifications."},
{"role": "user", "content": f"Resolve this git conflict in {filepath}:\n\n```\n{content}\n```\n\nReturn only the resolved file content without any explanation."}
]
)
resolved = response.choices[0].message.content
# Clean up code fence markers if present
resolved = resolved.replace('```', '').strip()
with open(filepath, 'w') as f:
f.write(resolved + '\n')
subprocess.run(['git', 'add', filepath])
print(f"Resolved: {filepath}")
except Exception as e:
print(f"Error resolving {filepath}: {e}")
sys.exit(1)
# Complete the merge
subprocess.run(['git', 'commit', '-m', 'chore: merge from upstream with AI conflict resolution'])
PYEOF
fi
fi
- name: Apply opengstack filters
if: steps.check.outputs.updating == 'true'
run: |
python3 ${{ env.FILTER_SCRIPT }} .
python3 ${{ env.CLEANUP_SCRIPT }} .
- name: Commit filtered changes
if: steps.check.outputs.updating == 'true'
run: |
git add -A
git diff --cached --quiet || git commit -m "chore: apply opengstack filters"
- name: Push sync branch
if: steps.check.outputs.updating == 'true'
run: |
git push origin ${{ steps.branch.outputs.branch_name }}
- name: Create Pull Request
if: steps.check.outputs.updating == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.branch.outputs.branch_name }}
base: main
title: "chore: sync from garrytan/gstack v${{ steps.upstream.outputs.version }}"
body: |
## Sync Report
Merged latest changes from [garrytan/gstack](https://github.com/${{ env.UPSTREAM_REPO }}).
**Upstream version:** v${{ steps.upstream.outputs.version }}
Applied filters:
- Removed telemetry/analytics
- Removed YC references
- Removed garrytan-specific content
- Merged using Fireworks AI (FIREWORKS_API_KEY)
**Note:** Merge this PR to complete the sync. Do not push directly to main.
draft: false
- name: Create version tag (after PR merge)
if: steps.check.outputs.updating == 'true'
run: |
UPSTREAM_VERSION="${{ steps.upstream.outputs.version }}"
if [ -n "$UPSTREAM_VERSION" ] && [ "$UPSTREAM_VERSION" != "unknown" ]; then
TAG="v${UPSTREAM_VERSION}.0"
echo "::notice::After merging the PR, create tag: $TAG"
fi