@@ -3,26 +3,30 @@ name: Auto Merge Develop to Main
33on :
44 push :
55 branches :
6- - Develop # Trigger action on push to Develop
6+ - Develop
77
88jobs :
99 merge :
1010 runs-on : ubuntu-latest
11+ permissions :
12+ contents : write
13+
1114 steps :
1215 - name : Checkout code
1316 uses : actions/checkout@v2
17+ with :
18+ fetch-depth : 0
1419
1520 - name : Get last commit message on Develop
1621 id : last_commit
1722 run : |
1823 LAST_COMMIT_MSG=$(git log -1 --pretty=%B)
19- echo "Last commit message: $LAST_COMMIT_MSG"
20- echo "::set-output name=commit_message::$LAST_COMMIT_MSG"
24+ echo "commit_message=$LAST_COMMIT_MSG" >> $GITHUB_ENV
2125
22- - name : Set up Git
26+ - name : Set up Git with Your Credentials
2327 run : |
24- git config user.name "github-actions "
25- git config user.email "github-actions@github .com"
28+ git config user.name "RNViththagan "
29+ git config user.email "viththagan1999@gmail .com"
2630
2731 - name : Checkout main branch
2832 run : |
@@ -31,16 +35,23 @@ jobs:
3135
3236 - name : Merge Develop into main (if commit message matches)
3337 run : |
34- # Convert commit message to lowercase for case-insensitive comparison
35- COMMIT_MSG_LOWER=$(echo "${{ steps.last_commit.outputs.commit_message }}" | tr '[:upper:]' '[:lower:]')
36-
38+ COMMIT_MSG_LOWER=$(echo "$commit_message" | tr '[:upper:]' '[:lower:]')
39+
3740 if [[ "$COMMIT_MSG_LOWER" == *"ready to deploy"* ]]; then
38- echo "Commit message matches, merging Develop into main."
39- git merge origin/Develop --no-ff --allow-unrelated-histories -m "Merge Develop into main"
40- # Attempt the merge and capture the result
41- git merge origin/Develop --no-ff -m "Merge Develop into main" || { echo "Merge conflicts detected, skipping push."; exit 1; }
42-
43- git push origin main
41+ echo "Commit message matches, attempting merge."
42+ if git merge origin/Develop --no-ff -m "Merge Develop into main"; then
43+ echo "Merge successful."
44+ else
45+ echo "Merge conflicts detected. Aborting."
46+ git merge --abort
47+ exit 1
48+ fi
4449 else
4550 echo "Commit message does not match, skipping merge."
4651 fi
52+
53+ - name : Push changes to main
54+ run : |
55+ git push origin main
56+ env :
57+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments