|
1 | 1 | name: Sync Fork with Upstream Master |
2 | 2 |
|
3 | 3 | on: |
| 4 | + schedule: |
| 5 | + - cron: '0 3 * * *' # Daily at 3:00 AM UTC |
| 6 | + workflow_dispatch: |
4 | 7 | issue_comment: |
5 | 8 | types: [created] |
6 | 9 |
|
7 | 10 | jobs: |
8 | | - sync-upstream: |
9 | | - name: Sync Fork with Upstream |
| 11 | + sync-scheduled: |
| 12 | + name: Sync Fork with Upstream (Scheduled) |
| 13 | + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + steps: |
| 18 | + - name: Checkout master branch |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + ref: master |
| 22 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Configure Git |
| 26 | + run: | |
| 27 | + git config user.name "github-actions[bot]" |
| 28 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 29 | +
|
| 30 | + - name: Sync with upstream and squash fork-specific commits |
| 31 | + id: sync |
| 32 | + run: | |
| 33 | + set -e |
| 34 | + |
| 35 | + echo "Adding upstream remote..." |
| 36 | + git remote add upstream https://github.com/eclipse-jdt/eclipse.jdt.debug.git || true |
| 37 | + |
| 38 | + echo "Fetching from upstream and origin..." |
| 39 | + git fetch upstream master |
| 40 | + git fetch origin master |
| 41 | + |
| 42 | + # Check if there are new commits in upstream |
| 43 | + echo "Checking for new commits in upstream..." |
| 44 | + UPSTREAM_SHA=$(git rev-parse upstream/master) |
| 45 | + CURRENT_SHA=$(git rev-parse origin/master) |
| 46 | + |
| 47 | + # Get the base commit (where fork diverged from upstream) |
| 48 | + BASE_SHA=$(git merge-base origin/master upstream/master 2>/dev/null || echo "") |
| 49 | + |
| 50 | + if [ "$UPSTREAM_SHA" = "$BASE_SHA" ]; then |
| 51 | + echo "No new commits in upstream. Skipping sync." |
| 52 | + echo "sync_needed=false" >> $GITHUB_OUTPUT |
| 53 | + exit 0 |
| 54 | + fi |
| 55 | + |
| 56 | + echo "New commits found in upstream." |
| 57 | + echo "sync_needed=true" >> $GITHUB_OUTPUT |
| 58 | + |
| 59 | + echo "Identifying fork-specific files..." |
| 60 | + # Get list of files that exist in origin/master but not in upstream/master |
| 61 | + # Focus on .github/workflows and other fork-specific paths |
| 62 | + git checkout origin/master |
| 63 | + FORK_FILES=$(git diff --name-only origin/master upstream/master | grep -E '^\.github/workflows/' || true) |
| 64 | + |
| 65 | + if [ -z "$FORK_FILES" ]; then |
| 66 | + echo "No fork-specific files found." |
| 67 | + else |
| 68 | + echo "Fork-specific files found:" |
| 69 | + echo "$FORK_FILES" |
| 70 | + fi |
| 71 | + |
| 72 | + # Create a temporary branch from upstream/master |
| 73 | + echo "Creating new-master branch from upstream/master..." |
| 74 | + git checkout -b new-master upstream/master |
| 75 | + |
| 76 | + # Apply fork-specific changes if any |
| 77 | + if [ -n "$FORK_FILES" ]; then |
| 78 | + echo "Applying fork-specific changes..." |
| 79 | + # Checkout the fork-specific files from origin/master |
| 80 | + for file in $FORK_FILES; do |
| 81 | + mkdir -p "$(dirname "$file")" |
| 82 | + git show origin/master:"$file" > "$file" |
| 83 | + git add "$file" |
| 84 | + done |
| 85 | + |
| 86 | + # Create a single squashed commit for all fork-specific changes |
| 87 | + if ! git diff --cached --quiet; then |
| 88 | + echo "Creating squashed commit for fork-specific changes..." |
| 89 | + git commit -m "chore: fork-specific CI and workflow configurations" \ |
| 90 | + -m "This commit contains all fork-specific customizations including:" \ |
| 91 | + -m "- GitHub Actions workflows" \ |
| 92 | + -m "- CI configuration files" \ |
| 93 | + -m "- Other fork-specific settings" \ |
| 94 | + -m "" \ |
| 95 | + -m "These changes are maintained as a single commit to keep the fork" \ |
| 96 | + -m "in sync with upstream while preserving fork customizations." |
| 97 | + fi |
| 98 | + fi |
| 99 | + |
| 100 | + echo "Force pushing to origin/master..." |
| 101 | + git push origin new-master:master --force |
| 102 | + |
| 103 | + echo "✅ Successfully synced fork with upstream" |
| 104 | +
|
| 105 | + sync-manual: |
| 106 | + name: Sync Fork with Upstream (Manual) |
10 | 107 | if: | |
| 108 | + github.event_name == 'issue_comment' && |
11 | 109 | (github.event.issue.pull_request != null || github.event_name == 'issue_comment') && |
12 | 110 | contains(github.event.comment.body, '/sync-upstream') |
13 | 111 | runs-on: ubuntu-latest |
@@ -110,7 +208,7 @@ jobs: |
110 | 208 | echo "sync_needed=false" >> $GITHUB_OUTPUT |
111 | 209 | else |
112 | 210 | echo "Creating squashed commit for fork-specific changes..." |
113 | | - git commit -m "Fork-specific CI and workflow configurations" \ |
| 211 | + git commit -m "chore: fork-specific CI and workflow configurations" \ |
114 | 212 | -m "This commit contains all fork-specific customizations including:" \ |
115 | 213 | -m "- GitHub Actions workflows" \ |
116 | 214 | -m "- CI configuration files" \ |
|
0 commit comments