9
9
sync-demo-branch :
10
10
runs-on : ubuntu-latest
11
11
steps :
12
- # Keep v4 for this test
12
+ # Use v4, as v3 didn't help either
13
13
- name : Checkout demo branch
14
14
uses : actions/checkout@v4
15
15
with :
23
23
echo "Checking .gitattributes content:"
24
24
cat .gitattributes || echo ".gitattributes not found!"
25
25
26
+ # *** ADDED: Check Git Version ***
27
+ - name : Check Git Version
28
+ run : git --version
29
+
26
30
# Configure Git user for the commit
27
31
- name : Configure Git User
28
32
run : |
@@ -37,13 +41,68 @@ jobs:
37
41
- name : Fetch origin
38
42
run : git fetch origin
39
43
40
- # *** CHANGE HERE: Use -X ours strategy ***
41
- - name : Merge main into demo using -X ours
44
+ # Perform the merge using -X ours and add verbose output
45
+ # Use continue-on-error to allow the next step to run
46
+ - name : Merge main into demo using -X ours (VERBOSE)
47
+ run : |
48
+ echo "Attempting merge with: git merge --no-ff -X ours --verbose origin/main"
49
+ git merge --no-ff -X ours --verbose origin/main -m "Auto-merge main into demo (using -X ours, verbose)"
50
+ continue-on-error : true # IMPORTANT: Allow workflow to continue to next step on failure
51
+
52
+ # *** ADDED: Show Git Status After Merge Attempt ***
53
+ # This step will run regardless of merge success/failure IF the previous step used continue-on-error
54
+ - name : Show Git Status After Merge Attempt
55
+ if : always() # Ensure this runs even if merge succeeded or failed
56
+ run : |
57
+ echo "--- Git Status after merge attempt ---"
58
+ git status --short # Use --short for concise output
59
+ echo "--- Files with conflicts (if any) ---"
60
+ # List files specifically marked as Unmerged (U)
61
+ git diff --name-only --diff-filter=U || echo "No files found with Unmerged status."
62
+
63
+ # *** IMPORTANT: Check if merge failed before trying to push ***
64
+ - name : Check merge result before push
65
+ id : merge_check
66
+ # Check the exit code of the merge step
42
67
run : |
43
- # Using -X ours to force keeping demo's version on all conflicts
44
- git merge --no-ff -X ours origin/main -m "Auto-merge main into demo (using -X ours)"
68
+ # Note: This relies on the step ID of the merge step if you named it.
69
+ # Adjust 'steps.merge_step_id.outcome' if your merge step has an id:
70
+ # For now, we check if status shows unmerged files as a proxy
71
+ if git status --short | grep -q '^UU '; then
72
+ echo "Merge failed with conflicts. Aborting push."
73
+ echo "outcome=failure" >> $GITHUB_OUTPUT
74
+ exit 1 # Fail the workflow explicitly
75
+ elif git status --short | grep -q '^AA '; then # Added by us, deleted by them
76
+ echo "Merge failed with conflicts (AA). Aborting push."
77
+ echo "outcome=failure" >> $GITHUB_OUTPUT
78
+ exit 1 # Fail the workflow explicitly
79
+ elif git status --short | grep -q '^DD '; then # Deleted by both
80
+ echo "Merge failed with conflicts (DD). Aborting push."
81
+ echo "outcome=failure" >> $GITHUB_OUTPUT
82
+ exit 1 # Fail the workflow explicitly
83
+ elif git status --short | grep -q '^AU '; then # Added by us, unmerged by them
84
+ echo "Merge failed with conflicts (AU). Aborting push."
85
+ echo "outcome=failure" >> $GITHUB_OUTPUT
86
+ exit 1 # Fail the workflow explicitly
87
+ elif git status --short | grep -q '^UA '; then # Unmerged by us, added by them
88
+ echo "Merge failed with conflicts (UA). Aborting push."
89
+ echo "outcome=failure" >> $GITHUB_OUTPUT
90
+ exit 1 # Fail the workflow explicitly
91
+ elif git status --short | grep -q '^UD '; then # Unmerged by us, deleted by them
92
+ echo "Merge failed with conflicts (UD). Aborting push."
93
+ echo "outcome=failure" >> $GITHUB_OUTPUT
94
+ exit 1 # Fail the workflow explicitly
95
+ elif git status --short | grep -q '^DU '; then # Deleted by us, unmerged by them
96
+ echo "Merge failed with conflicts (DU). Aborting push."
97
+ echo "outcome=failure" >> $GITHUB_OUTPUT
98
+ exit 1 # Fail the workflow explicitly
99
+ else
100
+ echo "Merge appears successful or conflicts resolved automatically."
101
+ echo "outcome=success" >> $GITHUB_OUTPUT
102
+ fi
45
103
46
- # Push the merge commit (and resolved changes) back to the demo branch
104
+ # Push only if the merge succeeded (checked in previous step)
47
105
- name : Push changes to demo
106
+ if : steps.merge_check.outputs.outcome == 'success'
48
107
run : |
49
108
git push origin demo
0 commit comments