1
- name : Sync Demo Branch
1
+ # Workflow from the previous step - attempting merge and resolving conflicts
2
+ name : Sync Demo Branch (Merge & Resolve)
2
3
3
4
on :
4
5
push :
9
10
sync-demo-branch :
10
11
runs-on : ubuntu-latest
11
12
steps :
12
- # Use v4
13
+ # Checkout demo branch
13
14
- name : Checkout demo branch
14
15
uses : actions/checkout@v4
15
16
with :
16
17
ref : ' demo'
17
18
token : ${{ secrets.DEMO_UPDATE_PAT }}
18
- fetch-depth : 0
19
+ fetch-depth : 0 # Needed for merge
19
20
20
- # Verify .gitattributes
21
- - name : Verify .gitattributes
22
- run : |
23
- echo "Checking .gitattributes content:"
24
- cat .gitattributes || echo ".gitattributes not found!"
25
-
26
- # Check Git Version
27
- - name : Check Git Version
28
- run : git --version
29
-
30
- # Configure Git user for the commit
21
+ # Configure Git User
31
22
- name : Configure Git User
32
23
run : |
33
24
git config user.name "GitHub Actions Bot"
@@ -37,64 +28,51 @@ jobs:
37
28
- name : Disable autocrlf
38
29
run : git config --global core.autocrlf false
39
30
40
- # Fetch the latest changes from the remote, including main
31
+ # Fetch origin
41
32
- name : Fetch origin
42
33
run : git fetch origin
43
34
44
- # Attempt the merge using -X ours, allow failure
35
+ # Attempt Merge
45
36
- name : Attempt Merge main into demo using -X ours
46
- id : merge_attempt # Give the step an ID
37
+ id : merge_attempt
47
38
run : |
48
39
echo "Attempting merge with: git merge --no-ff -X ours origin/main"
49
- # Use a standard merge message here, we might amend it later if needed
50
40
git merge --no-ff -X ours origin/main -m "Auto-merge main into demo"
51
41
continue-on-error : true
52
42
53
- # *** NEW: Resolve conflicts by keeping 'ours' if merge failed ***
43
+ # Resolve Conflicts Favoring 'ours'
54
44
- name : Resolve Conflicts Favoring 'ours'
55
- # Run only if the previous merge step failed
56
45
if : steps.merge_attempt.outcome == 'failure'
57
46
run : |
58
47
echo "Merge failed, attempting to resolve conflicts favouring 'ours'..."
59
- # Get list of unmerged files (conflicts)
60
48
git diff --name-only --diff-filter=U > conflicted_files.txt
61
-
62
49
if [ -s conflicted_files.txt ]; then
63
50
echo "Conflicting files found:"
64
51
cat conflicted_files.txt
65
- # For each conflicting file, checkout the version from 'ours' (demo branch)
66
- # Use xargs to handle the list of files efficiently
67
52
echo "Checking out 'ours' version for conflicting files..."
68
53
xargs -r -a conflicted_files.txt git checkout --ours --
69
- # Add the now-resolved files to the index
70
54
echo "Adding resolved files..."
71
55
xargs -r -a conflicted_files.txt git add --
72
- # Commit the resolved merge
73
56
echo "Committing resolved merge..."
74
- # You can use a specific message or potentially amend the failed merge commit
75
- # Using a new message for clarity:
76
57
git commit -m "Auto-merge main into demo (Conflicts resolved favoring demo)"
77
58
echo "Conflicts resolved and committed."
78
59
else
79
- echo "Merge failed, but no conflicting files found by 'git diff --diff-filter=U'. This is unexpected."
80
- # Explicitly fail the job if merge failed but we couldn't find/resolve conflicts
60
+ echo "Merge failed, but no conflicting files found by 'git diff --diff-filter=U'. Aborting."
81
61
exit 1
82
62
fi
83
63
84
- # Check final status ONLY IF the resolution step ran (i.e., merge initially failed)
85
- # This is mostly for logging/debugging if the resolution itself failed.
64
+ # Check Status After Resolution Attempt (Safety Check)
86
65
- name : Check Status After Resolution Attempt
87
66
if : steps.merge_attempt.outcome == 'failure'
88
67
run : |
89
68
echo "--- Git Status after conflict resolution attempt ---"
90
69
git status --short
91
- # Check again for unmerged files. If any exist here, the resolution failed.
92
70
if git diff --name-only --diff-filter=U | read; then
93
71
echo "ERROR: Unmerged files still exist after resolution attempt!"
94
72
exit 1
95
73
fi
96
74
97
- # Push the changes (either the successful initial merge or the resolved merge )
75
+ # Push changes to demo (no force needed )
98
76
- name : Push changes to demo
99
77
run : |
100
78
echo "Pushing changes to demo..."
0 commit comments