|
| 1 | +name: Sync Develop with Master |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Semantic Release"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + sync-develop: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + # Only run if semantic release succeeded and actually released |
| 19 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + |
| 28 | + - name: Configure Git |
| 29 | + run: | |
| 30 | + git config user.name "github-actions[bot]" |
| 31 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 32 | +
|
| 33 | + - name: Fetch all branches |
| 34 | + run: | |
| 35 | + git fetch origin master:master |
| 36 | + git fetch origin develop:develop |
| 37 | +
|
| 38 | + - name: Check if develop is behind master |
| 39 | + id: check |
| 40 | + run: | |
| 41 | + git checkout develop |
| 42 | + BEHIND=$(git rev-list --count develop..master) |
| 43 | + echo "commits_behind=$BEHIND" >> $GITHUB_OUTPUT |
| 44 | +
|
| 45 | + if [ "$BEHIND" -eq "0" ]; then |
| 46 | + echo "Develop is already up to date with master" |
| 47 | + echo "needs_sync=false" >> $GITHUB_OUTPUT |
| 48 | + else |
| 49 | + echo "Develop is $BEHIND commits behind master" |
| 50 | + echo "needs_sync=true" >> $GITHUB_OUTPUT |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Attempt automatic merge |
| 54 | + id: merge |
| 55 | + if: steps.check.outputs.needs_sync == 'true' |
| 56 | + run: | |
| 57 | + git checkout develop |
| 58 | +
|
| 59 | + # Try to merge master into develop |
| 60 | + if git merge master --no-edit; then |
| 61 | + echo "Merge successful - no conflicts" |
| 62 | + echo "status=success" >> $GITHUB_OUTPUT |
| 63 | + echo "has_conflicts=false" >> $GITHUB_OUTPUT |
| 64 | + else |
| 65 | + echo "Merge has conflicts" |
| 66 | + git merge --abort |
| 67 | + echo "status=conflict" >> $GITHUB_OUTPUT |
| 68 | + echo "has_conflicts=true" >> $GITHUB_OUTPUT |
| 69 | + fi |
| 70 | +
|
| 71 | + - name: Push changes if no conflicts |
| 72 | + if: steps.merge.outputs.status == 'success' |
| 73 | + run: | |
| 74 | + git push origin develop |
| 75 | + echo "✅ Successfully synced develop with master" |
| 76 | +
|
| 77 | + - name: Get latest version tag |
| 78 | + id: version |
| 79 | + if: steps.merge.outputs.has_conflicts == 'true' |
| 80 | + run: | |
| 81 | + VERSION=$(git describe --tags --abbrev=0 master) |
| 82 | + echo "tag=$VERSION" >> $GITHUB_OUTPUT |
| 83 | +
|
| 84 | + - name: Create PR if conflicts exist |
| 85 | + if: steps.merge.outputs.has_conflicts == 'true' |
| 86 | + uses: peter-evans/create-pull-request@v6 |
| 87 | + with: |
| 88 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + branch: sync/master-to-develop-${{ steps.version.outputs.tag }} |
| 90 | + base: develop |
| 91 | + title: "chore: sync develop with master ${{ steps.version.outputs.tag }}" |
| 92 | + body: | |
| 93 | + ## 🔄 Automatic Sync: Master → Develop |
| 94 | +
|
| 95 | + This PR syncs `develop` branch with the latest release from `master`. |
| 96 | +
|
| 97 | + **Release Version:** `${{ steps.version.outputs.tag }}` |
| 98 | + **Triggered by:** Semantic Release workflow completion |
| 99 | +
|
| 100 | + ### ⚠️ Merge Conflicts Detected |
| 101 | +
|
| 102 | + Automatic merge failed due to conflicts. Please resolve conflicts manually: |
| 103 | +
|
| 104 | + ```bash |
| 105 | + git checkout develop |
| 106 | + git pull origin develop |
| 107 | + git merge master |
| 108 | + # Resolve conflicts |
| 109 | + git add . |
| 110 | + git commit |
| 111 | + git push origin develop |
| 112 | + ``` |
| 113 | +
|
| 114 | + ### Changes from Master: |
| 115 | + - Updated version files (`pyproject.toml`, `__version__.py`) |
| 116 | + - Updated `CHANGELOG.md` |
| 117 | + - New release tag: `${{ steps.version.outputs.tag }}` |
| 118 | +
|
| 119 | + --- |
| 120 | +
|
| 121 | + 🤖 This PR was created automatically by the sync-develop workflow. |
| 122 | + labels: | |
| 123 | + chore |
| 124 | + sync |
| 125 | + automated |
| 126 | + assignees: ${{ github.repository_owner }} |
| 127 | + |
| 128 | + - name: Add comment with instructions |
| 129 | + if: steps.merge.outputs.has_conflicts == 'true' |
| 130 | + uses: peter-evans/create-or-update-comment@v4 |
| 131 | + with: |
| 132 | + issue-number: ${{ steps.pr.outputs.pull-request-number }} |
| 133 | + body: | |
| 134 | + ### 📋 Manual Merge Instructions |
| 135 | +
|
| 136 | + Since automatic merge failed, follow these steps: |
| 137 | +
|
| 138 | + 1. **Checkout and update develop:** |
| 139 | + ```bash |
| 140 | + git checkout develop |
| 141 | + git pull origin develop |
| 142 | + ``` |
| 143 | +
|
| 144 | + 2. **Merge master:** |
| 145 | + ```bash |
| 146 | + git merge master |
| 147 | + ``` |
| 148 | +
|
| 149 | + 3. **Resolve conflicts** in: |
| 150 | + - `pyproject.toml` (keep master version) |
| 151 | + - `deeptab/__version__.py` (keep master version) |
| 152 | + - `CHANGELOG.md` (merge both) |
| 153 | + - Any other conflicting files |
| 154 | +
|
| 155 | + 4. **Complete the merge:** |
| 156 | + ```bash |
| 157 | + git add . |
| 158 | + git commit -m "chore: sync develop with master ${{ steps.version.outputs.tag }}" |
| 159 | + git push origin develop |
| 160 | + ``` |
| 161 | +
|
| 162 | + 5. **Close this PR** (changes will be in develop) |
| 163 | +
|
| 164 | + 💡 **Tip:** Version files should always use master's values after a release. |
| 165 | +
|
| 166 | + - name: Summary |
| 167 | + if: always() |
| 168 | + run: | |
| 169 | + echo "## Sync Develop Workflow Summary" >> $GITHUB_STEP_SUMMARY |
| 170 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 171 | +
|
| 172 | + if [ "${{ steps.check.outputs.needs_sync }}" == "false" ]; then |
| 173 | + echo "✅ Develop is already up to date with master" >> $GITHUB_STEP_SUMMARY |
| 174 | + elif [ "${{ steps.merge.outputs.status }}" == "success" ]; then |
| 175 | + echo "✅ Successfully merged master into develop automatically" >> $GITHUB_STEP_SUMMARY |
| 176 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 177 | + echo "**Commits synced:** ${{ steps.check.outputs.commits_behind }}" >> $GITHUB_STEP_SUMMARY |
| 178 | + elif [ "${{ steps.merge.outputs.has_conflicts }}" == "true" ]; then |
| 179 | + echo "⚠️ Merge conflicts detected - PR created for manual resolution" >> $GITHUB_STEP_SUMMARY |
| 180 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 181 | + echo "**Action required:** Review and merge the auto-created PR" >> $GITHUB_STEP_SUMMARY |
| 182 | + fi |
0 commit comments