-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (67 loc) · 2.29 KB
/
sync-develop.yml
File metadata and controls
78 lines (67 loc) · 2.29 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
name: Sync Develop Branch
on:
push:
branches:
- main
workflow_dispatch:
jobs:
sync-develop:
name: Sync develop branch with main
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch all branches
run: |
git fetch origin main
git fetch origin develop
- name: Check if develop branch exists
id: check-develop
run: |
if git show-ref --verify --quiet refs/remotes/origin/develop; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create develop branch if it doesn't exist
if: steps.check-develop.outputs.exists == 'false'
run: |
git checkout -b develop
git push origin develop
- name: Sync develop with main
if: steps.check-develop.outputs.exists == 'true'
run: |
git checkout develop
DEVELOP_BEFORE=$(git rev-parse HEAD)
MAIN_COMMIT=$(git rev-parse origin/main)
if [ "$DEVELOP_BEFORE" = "$MAIN_COMMIT" ]; then
echo "develop is already up to date"
exit 0
fi
if git merge --ff-only origin/main; then
git push origin develop
else
DIVERGED_COMMITS=$(git rev-list --count origin/main..develop)
if [ "$DIVERGED_COMMITS" -gt 0 ]; then
echo "develop has $DIVERGED_COMMITS commits not in main"
git log --oneline origin/main..develop
exit 1
else
exit 1
fi
fi
- name: Create summary
if: always()
run: |
echo "## Develop Branch Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Main commit**: \`$(git rev-parse origin/main)\`" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY