@@ -11,13 +11,15 @@ jobs:
1111 steps :
1212 - name : Checkout code
1313 uses : actions/checkout@v2
14+ with :
15+ fetch-depth : 0 # Ensure full history for merge operations
1416
1517 - name : Get last commit message on Develop
1618 id : last_commit
1719 run : |
1820 LAST_COMMIT_MSG=$(git log -1 --pretty=%B)
1921 echo "Last commit message: $LAST_COMMIT_MSG"
20- echo "::set-output name= commit_message:: $LAST_COMMIT_MSG"
22+ echo "commit_message= $LAST_COMMIT_MSG" >> $GITHUB_ENV
2123
2224 - name : Set up Git
2325 run : |
@@ -31,16 +33,20 @@ jobs:
3133
3234 - name : Merge Develop into main (if commit message matches)
3335 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-
36+ COMMIT_MSG_LOWER=$(echo "$commit_message" | tr '[:upper:]' '[:lower:]')
37+
3738 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
39+ echo "Commit message matches, attempting merge."
40+
41+ # Merge and detect conflicts
42+ if git merge origin/Develop --no-ff -m "Merge Develop into main"; then
43+ git push origin main
44+ echo "Merge successful, pushed to main."
45+ else
46+ echo "Merge conflicts detected. Stopping merge."
47+ git merge --abort
48+ exit 1
49+ fi
4450 else
4551 echo "Commit message does not match, skipping merge."
4652 fi
0 commit comments