-
Notifications
You must be signed in to change notification settings - Fork 24
182 lines (151 loc) · 6.1 KB
/
sync-develop.yml
File metadata and controls
182 lines (151 loc) · 6.1 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
name: Sync Develop with Master
on:
workflow_run:
workflows: ["Semantic Release"]
types:
- completed
branches:
- master
permissions:
contents: write
pull-requests: write
jobs:
sync-develop:
runs-on: ubuntu-latest
# Only run if semantic release succeeded and actually released
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
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: Fetch all branches
run: |
git fetch origin master:master
git fetch origin develop:develop
- name: Check if develop is behind master
id: check
run: |
git checkout develop
BEHIND=$(git rev-list --count develop..master)
echo "commits_behind=$BEHIND" >> $GITHUB_OUTPUT
if [ "$BEHIND" -eq "0" ]; then
echo "Develop is already up to date with master"
echo "needs_sync=false" >> $GITHUB_OUTPUT
else
echo "Develop is $BEHIND commits behind master"
echo "needs_sync=true" >> $GITHUB_OUTPUT
fi
- name: Attempt automatic merge
id: merge
if: steps.check.outputs.needs_sync == 'true'
run: |
git checkout develop
# Try to merge master into develop
if git merge master --no-edit; then
echo "Merge successful - no conflicts"
echo "status=success" >> $GITHUB_OUTPUT
echo "has_conflicts=false" >> $GITHUB_OUTPUT
else
echo "Merge has conflicts"
git merge --abort
echo "status=conflict" >> $GITHUB_OUTPUT
echo "has_conflicts=true" >> $GITHUB_OUTPUT
fi
- name: Push changes if no conflicts
if: steps.merge.outputs.status == 'success'
run: |
git push origin develop
echo "✅ Successfully synced develop with master"
- name: Get latest version tag
id: version
if: steps.merge.outputs.has_conflicts == 'true'
run: |
VERSION=$(git describe --tags --abbrev=0 master)
echo "tag=$VERSION" >> $GITHUB_OUTPUT
- name: Create PR if conflicts exist
if: steps.merge.outputs.has_conflicts == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: sync/master-to-develop-${{ steps.version.outputs.tag }}
base: develop
title: "chore: sync develop with master ${{ steps.version.outputs.tag }}"
body: |
## 🔄 Automatic Sync: Master → Develop
This PR syncs `develop` branch with the latest release from `master`.
**Release Version:** `${{ steps.version.outputs.tag }}`
**Triggered by:** Semantic Release workflow completion
### ⚠️ Merge Conflicts Detected
Automatic merge failed due to conflicts. Please resolve conflicts manually:
```bash
git checkout develop
git pull origin develop
git merge master
# Resolve conflicts
git add .
git commit
git push origin develop
```
### Changes from Master:
- Updated version files (`pyproject.toml`, `__version__.py`)
- Updated `CHANGELOG.md`
- New release tag: `${{ steps.version.outputs.tag }}`
---
🤖 This PR was created automatically by the sync-develop workflow.
labels: |
chore
sync
automated
assignees: ${{ github.repository_owner }}
- name: Add comment with instructions
if: steps.merge.outputs.has_conflicts == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.pr.outputs.pull-request-number }}
body: |
### 📋 Manual Merge Instructions
Since automatic merge failed, follow these steps:
1. **Checkout and update develop:**
```bash
git checkout develop
git pull origin develop
```
2. **Merge master:**
```bash
git merge master
```
3. **Resolve conflicts** in:
- `pyproject.toml` (keep master version)
- `deeptab/__version__.py` (keep master version)
- `CHANGELOG.md` (merge both)
- Any other conflicting files
4. **Complete the merge:**
```bash
git add .
git commit -m "chore: sync develop with master ${{ steps.version.outputs.tag }}"
git push origin develop
```
5. **Close this PR** (changes will be in develop)
💡 **Tip:** Version files should always use master's values after a release.
- name: Summary
if: always()
run: |
echo "## Sync Develop Workflow Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check.outputs.needs_sync }}" == "false" ]; then
echo "✅ Develop is already up to date with master" >> $GITHUB_STEP_SUMMARY
elif [ "${{ steps.merge.outputs.status }}" == "success" ]; then
echo "✅ Successfully merged master into develop automatically" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commits synced:** ${{ steps.check.outputs.commits_behind }}" >> $GITHUB_STEP_SUMMARY
elif [ "${{ steps.merge.outputs.has_conflicts }}" == "true" ]; then
echo "⚠️ Merge conflicts detected - PR created for manual resolution" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Action required:** Review and merge the auto-created PR" >> $GITHUB_STEP_SUMMARY
fi