Skip to content

Fix sync-upstream workflow to squash all fork-specific files into single commit#51

Merged
carstenartur merged 7 commits into
masterfrom
copilot/fix-sync-upstream-workflow
Feb 13, 2026
Merged

Fix sync-upstream workflow to squash all fork-specific files into single commit#51
carstenartur merged 7 commits into
masterfrom
copilot/fix-sync-upstream-workflow

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 13, 2026

The current workflow only preserves .github/workflows/ files and uses a merge-base diff approach that doesn't consistently squash fork changes. This causes the fork history to diverge with multiple commits instead of maintaining upstream commits + 1 fork commit.

Changes

Core Logic Replacement

  • Replaced merge-base diff with git reset --hard upstream/master + selective restore pattern
  • Expanded file detection from .github/workflows/ to all files in repository
  • Uses git cat-file -e upstream/master:"$file" to identify fork-specific files (files absent in upstream)

Implementation

# Backup all fork-specific files
for file in $FILES_TO_CHECK; do
  if ! git cat-file -e upstream/master:"$file" 2>/dev/null; then
    cp "$file" "/tmp/fork-specific/$file"
  fi
done

# Reset to upstream, restore fork files, commit as single squashed commit
git reset --hard upstream/master
cp -r /tmp/fork-specific/* ./
git add . && git commit -m "Fork-specific customizations"

Additional Improvements

  • Added proper await to all GitHub API calls (reactions, comments)
  • Removed redundant git fetch operations
  • Added || true to git remote add for workflow re-runs
  • Updated to actions/github-script@v8
  • Simplified manual sync job condition (removed redundant event type check)

Result

Fork master will maintain clean history: all upstream commits followed by exactly one squashed commit containing all customizations. Works for scheduled (daily 3am UTC) and manual (/sync-upstream comment) triggers.

Original prompt

Problem

Der aktuelle sync-upstream.yml Workflow in diesem Repository squasht nicht korrekt alle Fork-Änderungen auf einen einzelnen Commit. Im Vergleich dazu funktioniert der Workflow in carstenartur/eclipse.jdt.ui wie gewünscht:

  • Gewünschtes Verhalten (jdt.ui): Jede Nacht werden ALLE Fork-spezifischen Änderungen gegenüber upstream auf einen einzigen Commit gesquasht
  • Aktuelles Verhalten (jdt.debug): Nur .github/workflows/ Dateien werden berücksichtigt

Lösung

Ersetze den aktuellen .github/workflows/sync-upstream.yml durch die Version aus eclipse.jdt.ui, angepasst für eclipse.jdt.debug:

Wichtige Änderungen:

  1. Upstream-URL anpassen:

    • Von: https://github.com/eclipse-jdt/eclipse.jdt.ui.git
    • Zu: https://github.com/eclipse-jdt/eclipse.jdt.debug.git
  2. Commit-Messages und Kommentare anpassen:

    • Alle Referenzen zu eclipse.jdt.ui durch eclipse.jdt.debug ersetzen
  3. Logik übernehmen:

    • git reset --hard upstream/master Ansatz verwenden
    • Alle fork-spezifischen Dateien (nicht nur .github/workflows/) sichern und wiederherstellen
    • Fork-spezifische Dateien = Dateien die im Fork existieren aber nicht in upstream

Neuer Workflow (aus jdt.ui adaptiert):

name: Sync Fork with Upstream

on:
  schedule:
    - cron: '0 3 * * *'  # Daily at 3:00 AM UTC
  workflow_dispatch:
  issue_comment:
    types: [created]

jobs:
  sync-scheduled:
    name: Sync Fork (Scheduled)
    if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout fork master
        uses: actions/checkout@v4
        with:
          ref: master
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Configure Git
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

      - name: Add upstream remote
        run: |
          git remote add upstream https://github.com/eclipse-jdt/eclipse.jdt.debug.git
          git fetch upstream master

      - name: Identify and backup fork-specific files
        id: backup
        run: |
          # Create temporary directory for fork-specific files
          mkdir -p /tmp/fork-specific
          
          # Identify fork-specific workflow files (files that don't exist in upstream)
          git fetch upstream master
          
          # Get list of workflow files in fork
          FORK_WORKFLOWS=$(git ls-tree -r HEAD --name-only .github/workflows/ 2>/dev/null || echo "")
          
          # For each workflow file in fork, check if it exists in upstream
          for file in $FORK_WORKFLOWS; do
            if ! git cat-file -e upstream/master:"$file" 2>/dev/null; then
              echo "Fork-specific file: $file"
              # Create directory structure and copy file
              mkdir -p "/tmp/fork-specific/$(dirname "$file")"
              cp "$file" "/tmp/fork-specific/$file"
            fi
          done
          
          # Check if any fork-specific files were found
          if [ -d "/tmp/fork-specific/.github" ]; then
            echo "has_fork_files=true" >> $GITHUB_OUTPUT
            echo "Found fork-specific files:"
            find /tmp/fork-specific -type f
          else
            echo "has_fork_files=false" >> $GITHUB_OUTPUT
            echo "No fork-specific files found"
          fi

      - name: Reset to upstream master
        run: |
          # Reset fork master to upstream master
          git reset --hard upstream/master

      - name: Restore fork-specific files
        if: steps.backup.outputs.has_fork_files == 'true'
        run: |
          # Copy fork-specific files back
          if [ -d "/tmp/fork-specific" ]; then
            cp -r /tmp/fork-specific/.github ./ 2>/dev/null || true
          fi
          
          # Add all fork-specific changes
          git add .github/

      - name: Commit fork-specific changes
        if: steps.backup.outputs.has_fork_files == 'true'
        run: |
          # Check if there are changes to commit
          if ! git diff --cached --quiet; then
            git commit -m "Fork-specific CI and workflow configurations"
            echo "✅ Fork-specific changes committed"
          else
            echo "ℹ️  No fork-specific changes to commit"
          fi

      - name: Push to fork master
        run: |
          git push --force origin master
          echo "✅ Successfully synced with upstream"

  sync-manual:
    name: Sync Fork (Manual)
    if: |
      github.event_name == 'issue_comment' &&
      contains(github.event.comment.body, '/sync-upstream')
    runs-on: ubuntu-latest
    permissions:
      contents: write
      issues: write
    steps:
      - name: Check user permission
        id: check
        uses: actions/github-script@v8
        with:
          result-encoding: string
          script: |
        ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI and others added 6 commits February 13, 2026 15:27
…-specific files

Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
…andling

Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
…t file checking

Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
…mit message

Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sync-upstream.yml to squash all fork changes Fix sync-upstream workflow to squash all fork-specific files into single commit Feb 13, 2026
Copilot AI requested a review from carstenartur February 13, 2026 15:37
@carstenartur carstenartur marked this pull request as ready for review February 13, 2026 15:51
@carstenartur carstenartur merged commit ff1590d into master Feb 13, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants