Skip to content

Commit 68ed03d

Browse files
committed
ci: sync develop post semantic release
1 parent d364bce commit 68ed03d

File tree

2 files changed

+231
-21
lines changed

2 files changed

+231
-21
lines changed

.github/workflows/sync-develop.yml

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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

docs/contributing.md

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,59 @@ BREAKING CHANGE: Python 3.10 is now the minimum required version"
169169

170170
#### Working with Updated Versions
171171

172-
**Q: What happens if I create a branch from `develop` after a release?**
172+
**Q: What happens to `develop` branch after a release?**
173+
174+
After semantic-release completes on `master`, the version files are automatically updated. The `develop` branch syncs automatically:
175+
176+
**Automatic Sync Flow:**
177+
178+
```
179+
┌─────────────────────────────────────────────────────────────┐
180+
│ Release & Sync Process │
181+
└─────────────────────────────────────────────────────────────┘
182+
183+
1. Merge develop → master
184+
185+
186+
2. Semantic Release runs on master
187+
188+
├─→ Version: 1.6.1 → 1.7.0
189+
├─→ Update pyproject.toml
190+
├─→ Update __version__.py
191+
├─→ Update CHANGELOG.md
192+
└─→ Create tag v1.7.0
193+
194+
195+
3. Auto-Sync Workflow triggers
196+
197+
├─→ [No Conflicts] ✅
198+
│ │
199+
│ ├─→ Merge master → develop automatically
200+
│ └─→ Develop updated within 60 seconds
201+
202+
└─→ [Conflicts Detected] ⚠️
203+
204+
├─→ Create PR: "chore: sync develop with master"
205+
├─→ Notify maintainers
206+
└─→ Manual merge required (rare)
207+
```
208+
209+
**For Contributors:**
210+
211+
Before starting new work, always pull the latest `develop`:
173212

174-
After a release is merged to `master`, the version files are updated automatically. To get the latest version:
175-
176-
1. **Sync develop with master** (maintainers do this):
177-
178-
```bash
179-
git checkout develop
180-
git merge master
181-
git push origin develop
182-
```
183-
184-
2. **Update your local develop branch** (before creating new branches):
213+
```bash
214+
# Pull latest develop (already synced automatically)
215+
git checkout develop
216+
git pull origin develop
185217

186-
```bash
187-
git checkout develop
188-
git pull origin develop
189-
```
218+
# Create your feature branch
219+
git checkout -b feature/my-new-feature
220+
```
190221

191-
3. **Create your feature branch from updated develop**:
192-
```bash
193-
git checkout -b feature/my-new-feature
194-
```
222+
**Note:** 95% of the time, `develop` syncs automatically. If you see a PR titled "sync develop with master", it means manual conflict resolution is needed (maintainers handle this).
195223

196-
This ensures your branch has the correct version number as a starting point. Don't worry if the version seems "old" in your branch - semantic-release will calculate the correct new version based on commits when merging to master.
224+
Don't worry if the version seems "old" in your branch - semantic-release calculates the correct new version based on commits when merging to master.
197225

198226
### Submitting Contributions
199227

0 commit comments

Comments
 (0)