Skip to content

Sync Flywheel Upstream #10

Sync Flywheel Upstream

Sync Flywheel Upstream #10

Workflow file for this run

name: Sync Flywheel Upstream
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: Push to Target (Auto-Merge)
if: steps.merge.outputs.merge_status == 'success'
run: |
git push origin "$SYNC_BRANCH:$TARGET_BRANCH"
echo "Successfully synced to $TARGET_BRANCH"
- name: Ensure Labels Exist
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Ensure labels exist to prevent errors during PR creation
gh label create upstream-sync --repo ${{ github.repository }} --description "Syncs changes from upstream" --color 1d76db || true
gh label create conflict --repo ${{ github.repository }} --description "Merge conflicts detected" --color b60205 || true
# Debug: List labels to verify visibility
gh label list --repo ${{ github.repository }}
- name: Create Pull Request
if: steps.merge.outputs.merge_status == 'conflict'
run: |
# Check if PR already exists
existing_pr=$(gh pr list --repo ${{ github.repository }} --head "$SYNC_BRANCH" --base "$TARGET_BRANCH" --json number -q '.[0].number')
if [[ -z "$existing_pr" ]]; then
echo "Creating new PR..."
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"
PR_URL=$(gh pr create \
--repo ${{ github.repository }} \
--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
gh pr edit "$existing_pr" --repo ${{ github.repository }} --title "⚠️ Upstream Sync (Conflicts Detected)" --add-label "conflict" --body "Updates from upstream. Conflicts detected."
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 }}"