4
4
# to the develop branch, but only when triggered by version bump commits.
5
5
# This ensures that version updates made in production are properly synchronized back to the
6
6
# development branch, maintaining version consistency across branches.
7
+ #
8
+ # Workflow logic:
9
+ # 1. Triggers only on pushes to main branch with 'bump version' in commit message
10
+ # 2. Checks if there are differences between main and develop branches
11
+ # 3. Creates a PR to merge main into develop if differences exist
7
12
8
13
name : Backmerge main to develop after version bump
9
14
10
15
# Trigger conditions for the workflow
11
16
on :
12
17
push :
13
18
branches :
14
- # Only trigger on pushes to the main branch
15
19
- main
16
20
17
21
# Add permissions needed for PR creation
@@ -23,26 +27,25 @@ jobs:
23
27
backmerge :
24
28
runs-on : ubuntu-latest
25
29
# Only run this workflow when the commit message contains 'bump version'
26
- # This prevents unnecessary backmerges for regular commits to main
27
30
if : contains(github.event.head_commit.message, 'bump version')
28
31
29
32
steps :
30
- # Step 1: Check out the repository code
31
- # This gives the workflow access to the repository contents
33
+ # Step 1: Check out the repository code with full history
32
34
- name : Checkout repository
33
35
uses : actions/checkout@v4
34
36
with :
35
37
fetch-depth : 0 # Fetch all history for proper branch comparison
36
38
37
- # Step 1.5: Ensure we have the latest develop branch and check if there are differences
38
- - name : Fetch develop branch
39
+ # Step 2: Fetch the latest develop branch and display branch information
40
+ - name : Fetch develop branch and display branch info
39
41
run : |
40
42
git fetch origin develop:develop
41
43
git branch -a
42
44
echo "Current branch: $(git branch --show-current)"
43
45
echo "Develop branch commit: $(git rev-parse develop)"
44
46
echo "Main branch commit: $(git rev-parse main)"
45
47
48
+ # Step 3: Check if there are differences between main and develop branches
46
49
- name : Check for differences between main and develop
47
50
id : check_diff
48
51
run : |
@@ -52,41 +55,54 @@ jobs:
52
55
else
53
56
echo "Found differences between main and develop branches."
54
57
echo "has_diff=true" >> $GITHUB_OUTPUT
58
+ echo "Changes detected:"
59
+ git diff --stat main develop
55
60
fi
56
61
57
- # Step 2: Create an automated pull request for the backmerge
58
- # Uses the peter-evans/create-pull-request action to generate a PR
62
+ # Step 4: Create an automated pull request for the backmerge
59
63
- name : Create Backmerge PR
60
64
uses : peter-evans/create-pull-request@v5
61
65
if : steps.check_diff.outputs.has_diff == 'true'
62
66
with :
63
- # Use the default GitHub token for authentication
64
67
token : ${{ secrets.GITHUB_TOKEN }}
65
- # Target branch that will receive the changes
66
68
base : develop
67
- # Name of the temporary branch that will be created for this PR
68
69
branch : auto/backmerge-main-to-develop
69
- # Title of the pull request with emoji for better visibility
70
70
title : " 🔁 Backmerge: main → develop (after version bump)"
71
- # Detailed description of what this PR does
72
71
body : |
73
- This automated PR syncs the **develop** branch with **main** after a production version bump.
74
-
75
- Triggered by commit:
76
- `${{ github.event.head_commit.message }}`
77
-
78
- # Commit message for the changes in this PR
72
+ ## Automated Backmerge PR
73
+
74
+ This PR syncs the **develop** branch with **main** after a production version bump.
75
+
76
+ ### Details
77
+ - Triggered by commit: `${{ github.event.head_commit.message }}`
78
+ - Commit SHA: `${{ github.sha }}`
79
+ - Workflow run: [View Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
80
+
81
+ Please review the changes and merge when ready.
79
82
commit-message : " chore(backmerge): sync main into develop after version bump"
80
- # Clean up by deleting the temporary branch after the PR is merged or closed
81
83
delete-branch : true
84
+ labels : |
85
+ automated-pr
86
+ backmerge
82
87
88
+ # Step 5: Report workflow status
83
89
- name : PR Creation Status
84
90
if : always()
85
91
run : |
86
92
echo "has_diff value: ${{ steps.check_diff.outputs.has_diff }}"
87
93
if [ "${{ steps.check_diff.outputs.has_diff }}" != 'true' ]; then
88
- echo "No PR created because there are no differences between main and develop branches."
94
+ echo "✅ No PR created: No differences found between main and develop branches."
89
95
else
90
- echo "PR creation attempted. If no PR was created, check GitHub token permissions."
91
- echo "GitHub token permissions: ${{ toJson(github.token_permissions) }}"
96
+ echo "PR creation attempted."
97
+ echo "If no PR was created, please check:"
98
+ echo "1. GitHub token permissions: ${{ toJson(github.token_permissions) }}"
99
+ echo "2. Repository settings for GitHub Actions"
100
+ echo "3. Branch protection rules on develop branch"
92
101
fi
102
+
103
+ # Step 6: Notify on workflow completion
104
+ - name : Workflow Summary
105
+ if : always()
106
+ run : |
107
+ echo "::notice::Backmerge workflow completed at $(date)"
108
+ echo "::notice::Triggered by commit: ${{ github.event.head_commit.message }}"
0 commit comments