Skip to content

Commit d586baa

Browse files
committed
Use matrix job to merge main into branches
Consolidate separate merge-to-dev and merge-to-release jobs into a single matrix job that iterates over dev and release. Rename the workflow to 'Merge Main to branches' and remove the concurrency block. Use matrix.branch for checkout, merge commit messages and push; log an info and skip (exit 0) if a target branch doesn't exist, while merge conflicts still fail (exit 1). This reduces duplication and simplifies maintenance.
1 parent db19392 commit d586baa

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed
Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,20 @@
11
# This workflow automatically merges the 'main' branch into 'dev' and 'release' branches
22
# whenever changes are pushed to 'main', without requiring manual confirmation.
33

4-
name: Merge Main to Dev and Release
4+
name: Merge Main to branches
55

66
on:
77
push:
88
branches:
99
- main
1010

11-
concurrency:
12-
group: merge-main-to-branches
13-
cancel-in-progress: false
14-
1511
jobs:
16-
merge-to-dev:
17-
name: Merge main → dev
18-
runs-on: ubuntu-latest
19-
permissions:
20-
contents: write
21-
steps:
22-
- name: Checkout Repository
23-
uses: actions/checkout@v5
24-
with:
25-
fetch-depth: 0
26-
token: ${{ secrets.GITHUB_TOKEN }}
27-
28-
- name: Merge main into dev
29-
run: |
30-
git config user.name "github-actions[bot]"
31-
git config user.email "github-actions[bot]@users.noreply.github.com"
32-
if ! git checkout dev; then
33-
echo "::error::Branch 'dev' does not exist. Skipping merge."
34-
exit 1
35-
fi
36-
if ! git merge --no-ff origin/main -m "chore: merge main into dev [skip ci]"; then
37-
echo "::error::Merge conflict detected when merging main into dev. Manual intervention required."
38-
exit 1
39-
fi
40-
git push origin dev
41-
42-
merge-to-release:
43-
name: Merge main → release
12+
merge-to-branch:
4413
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
branch: [ 'dev', 'release' ]
17+
name: main -> ${{ matrix.branch }}
4518
permissions:
4619
contents: write
4720
steps:
@@ -51,16 +24,16 @@ jobs:
5124
fetch-depth: 0
5225
token: ${{ secrets.GITHUB_TOKEN }}
5326

54-
- name: Merge main into release
27+
- name: Merge main into ${{ matrix.branch }}
5528
run: |
5629
git config user.name "github-actions[bot]"
5730
git config user.email "github-actions[bot]@users.noreply.github.com"
58-
if ! git checkout release; then
59-
echo "::error::Branch 'release' does not exist. Skipping merge."
60-
exit 1
31+
if ! git checkout ${{ matrix.branch }}; then
32+
echo "[INFO] Branch '${{ matrix.branch }}' does not exist. Skipping merge."
33+
exit 0
6134
fi
62-
if ! git merge --no-ff origin/main -m "chore: merge main into release [skip ci]"; then
63-
echo "::error::Merge conflict detected when merging main into release. Manual intervention required."
35+
if ! git merge --no-ff origin/main -m "chore: merge main into ${{ matrix.branch }} [skip ci]"; then
36+
echo "[ERROR] Merge conflict detected when merging main into ${{ matrix.branch }}. Manual intervention required."
6437
exit 1
6538
fi
66-
git push origin release
39+
git push origin ${{ matrix.branch }}

0 commit comments

Comments
 (0)