Skip to content

Commit 38fc02a

Browse files
committed
added new 8
1 parent a6a0007 commit 38fc02a

File tree

2 files changed

+12
-382
lines changed

2 files changed

+12
-382
lines changed

.github/workflows/sync-demo-branch.yml

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Sync Demo Branch
1+
# Workflow from the previous step - attempting merge and resolving conflicts
2+
name: Sync Demo Branch (Merge & Resolve)
23

34
on:
45
push:
@@ -9,25 +10,15 @@ jobs:
910
sync-demo-branch:
1011
runs-on: ubuntu-latest
1112
steps:
12-
# Use v4
13+
# Checkout demo branch
1314
- name: Checkout demo branch
1415
uses: actions/checkout@v4
1516
with:
1617
ref: 'demo'
1718
token: ${{ secrets.DEMO_UPDATE_PAT }}
18-
fetch-depth: 0
19+
fetch-depth: 0 # Needed for merge
1920

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
3122
- name: Configure Git User
3223
run: |
3324
git config user.name "GitHub Actions Bot"
@@ -37,64 +28,51 @@ jobs:
3728
- name: Disable autocrlf
3829
run: git config --global core.autocrlf false
3930

40-
# Fetch the latest changes from the remote, including main
31+
# Fetch origin
4132
- name: Fetch origin
4233
run: git fetch origin
4334

44-
# Attempt the merge using -X ours, allow failure
35+
# Attempt Merge
4536
- name: Attempt Merge main into demo using -X ours
46-
id: merge_attempt # Give the step an ID
37+
id: merge_attempt
4738
run: |
4839
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
5040
git merge --no-ff -X ours origin/main -m "Auto-merge main into demo"
5141
continue-on-error: true
5242

53-
# *** NEW: Resolve conflicts by keeping 'ours' if merge failed ***
43+
# Resolve Conflicts Favoring 'ours'
5444
- name: Resolve Conflicts Favoring 'ours'
55-
# Run only if the previous merge step failed
5645
if: steps.merge_attempt.outcome == 'failure'
5746
run: |
5847
echo "Merge failed, attempting to resolve conflicts favouring 'ours'..."
59-
# Get list of unmerged files (conflicts)
6048
git diff --name-only --diff-filter=U > conflicted_files.txt
61-
6249
if [ -s conflicted_files.txt ]; then
6350
echo "Conflicting files found:"
6451
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
6752
echo "Checking out 'ours' version for conflicting files..."
6853
xargs -r -a conflicted_files.txt git checkout --ours --
69-
# Add the now-resolved files to the index
7054
echo "Adding resolved files..."
7155
xargs -r -a conflicted_files.txt git add --
72-
# Commit the resolved merge
7356
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:
7657
git commit -m "Auto-merge main into demo (Conflicts resolved favoring demo)"
7758
echo "Conflicts resolved and committed."
7859
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."
8161
exit 1
8262
fi
8363
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)
8665
- name: Check Status After Resolution Attempt
8766
if: steps.merge_attempt.outcome == 'failure'
8867
run: |
8968
echo "--- Git Status after conflict resolution attempt ---"
9069
git status --short
91-
# Check again for unmerged files. If any exist here, the resolution failed.
9270
if git diff --name-only --diff-filter=U | read; then
9371
echo "ERROR: Unmerged files still exist after resolution attempt!"
9472
exit 1
9573
fi
9674
97-
# Push the changes (either the successful initial merge or the resolved merge)
75+
# Push changes to demo (no force needed)
9876
- name: Push changes to demo
9977
run: |
10078
echo "Pushing changes to demo..."

0 commit comments

Comments
 (0)