Skip to content

Commit feb717f

Browse files
committed
ci: add automated backmerge workflow for version bump commits from main to develop
1 parent 1a2172e commit feb717f

File tree

2 files changed

+39
-76
lines changed

2 files changed

+39
-76
lines changed

.github/pr-backmerge.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/pr-backmerge.yml

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
# to the develop branch, but only when triggered by version bump commits.
55
# This ensures that version updates made in production are properly synchronized back to the
66
# 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
712

813
name: Backmerge main to develop after version bump
914

1015
# Trigger conditions for the workflow
1116
on:
1217
push:
1318
branches:
14-
# Only trigger on pushes to the main branch
1519
- main
1620

1721
# Add permissions needed for PR creation
@@ -23,26 +27,25 @@ jobs:
2327
backmerge:
2428
runs-on: ubuntu-latest
2529
# Only run this workflow when the commit message contains 'bump version'
26-
# This prevents unnecessary backmerges for regular commits to main
2730
if: contains(github.event.head_commit.message, 'bump version')
2831

2932
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
3234
- name: Checkout repository
3335
uses: actions/checkout@v4
3436
with:
3537
fetch-depth: 0 # Fetch all history for proper branch comparison
3638

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
3941
run: |
4042
git fetch origin develop:develop
4143
git branch -a
4244
echo "Current branch: $(git branch --show-current)"
4345
echo "Develop branch commit: $(git rev-parse develop)"
4446
echo "Main branch commit: $(git rev-parse main)"
4547
48+
# Step 3: Check if there are differences between main and develop branches
4649
- name: Check for differences between main and develop
4750
id: check_diff
4851
run: |
@@ -52,41 +55,54 @@ jobs:
5255
else
5356
echo "Found differences between main and develop branches."
5457
echo "has_diff=true" >> $GITHUB_OUTPUT
58+
echo "Changes detected:"
59+
git diff --stat main develop
5560
fi
5661
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
5963
- name: Create Backmerge PR
6064
uses: peter-evans/create-pull-request@v5
6165
if: steps.check_diff.outputs.has_diff == 'true'
6266
with:
63-
# Use the default GitHub token for authentication
6467
token: ${{ secrets.GITHUB_TOKEN }}
65-
# Target branch that will receive the changes
6668
base: develop
67-
# Name of the temporary branch that will be created for this PR
6869
branch: auto/backmerge-main-to-develop
69-
# Title of the pull request with emoji for better visibility
7070
title: "🔁 Backmerge: main → develop (after version bump)"
71-
# Detailed description of what this PR does
7271
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.
7982
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
8183
delete-branch: true
84+
labels: |
85+
automated-pr
86+
backmerge
8287
88+
# Step 5: Report workflow status
8389
- name: PR Creation Status
8490
if: always()
8591
run: |
8692
echo "has_diff value: ${{ steps.check_diff.outputs.has_diff }}"
8793
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."
8995
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"
92101
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

Comments
 (0)