added new 6 #123
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync Demo Branch | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
sync-demo-branch: | |
runs-on: ubuntu-latest | |
steps: | |
# Use v4, as v3 didn't help either | |
- name: Checkout demo branch | |
uses: actions/checkout@v4 | |
with: | |
ref: 'demo' | |
token: ${{ secrets.DEMO_UPDATE_PAT }} | |
fetch-depth: 0 | |
# Verify .gitattributes (still good practice) | |
- name: Verify .gitattributes | |
run: | | |
echo "Checking .gitattributes content:" | |
cat .gitattributes || echo ".gitattributes not found!" | |
# *** ADDED: Check Git Version *** | |
- name: Check Git Version | |
run: git --version | |
# Configure Git user for the commit | |
- name: Configure Git User | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "actions-bot@github.com" | |
# Disable autocrlf | |
- name: Disable autocrlf | |
run: git config --global core.autocrlf false | |
# Fetch the latest changes from the remote, including main | |
- name: Fetch origin | |
run: git fetch origin | |
# Perform the merge using -X ours and add verbose output | |
# Use continue-on-error to allow the next step to run | |
- name: Merge main into demo using -X ours (VERBOSE) | |
run: | | |
echo "Attempting merge with: git merge --no-ff -X ours --verbose origin/main" | |
git merge --no-ff -X ours --verbose origin/main -m "Auto-merge main into demo (using -X ours, verbose)" | |
continue-on-error: true # IMPORTANT: Allow workflow to continue to next step on failure | |
# *** ADDED: Show Git Status After Merge Attempt *** | |
# This step will run regardless of merge success/failure IF the previous step used continue-on-error | |
- name: Show Git Status After Merge Attempt | |
if: always() # Ensure this runs even if merge succeeded or failed | |
run: | | |
echo "--- Git Status after merge attempt ---" | |
git status --short # Use --short for concise output | |
echo "--- Files with conflicts (if any) ---" | |
# List files specifically marked as Unmerged (U) | |
git diff --name-only --diff-filter=U || echo "No files found with Unmerged status." | |
# *** IMPORTANT: Check if merge failed before trying to push *** | |
- name: Check merge result before push | |
id: merge_check | |
# Check the exit code of the merge step | |
run: | | |
# Note: This relies on the step ID of the merge step if you named it. | |
# Adjust 'steps.merge_step_id.outcome' if your merge step has an id: | |
# For now, we check if status shows unmerged files as a proxy | |
if git status --short | grep -q '^UU '; then | |
echo "Merge failed with conflicts. Aborting push." | |
echo "outcome=failure" >> $GITHUB_OUTPUT | |
exit 1 # Fail the workflow explicitly | |
elif git status --short | grep -q '^AA '; then # Added by us, deleted by them | |
echo "Merge failed with conflicts (AA). Aborting push." | |
echo "outcome=failure" >> $GITHUB_OUTPUT | |
exit 1 # Fail the workflow explicitly | |
elif git status --short | grep -q '^DD '; then # Deleted by both | |
echo "Merge failed with conflicts (DD). Aborting push." | |
echo "outcome=failure" >> $GITHUB_OUTPUT | |
exit 1 # Fail the workflow explicitly | |
elif git status --short | grep -q '^AU '; then # Added by us, unmerged by them | |
echo "Merge failed with conflicts (AU). Aborting push." | |
echo "outcome=failure" >> $GITHUB_OUTPUT | |
exit 1 # Fail the workflow explicitly | |
elif git status --short | grep -q '^UA '; then # Unmerged by us, added by them | |
echo "Merge failed with conflicts (UA). Aborting push." | |
echo "outcome=failure" >> $GITHUB_OUTPUT | |
exit 1 # Fail the workflow explicitly | |
elif git status --short | grep -q '^UD '; then # Unmerged by us, deleted by them | |
echo "Merge failed with conflicts (UD). Aborting push." | |
echo "outcome=failure" >> $GITHUB_OUTPUT | |
exit 1 # Fail the workflow explicitly | |
elif git status --short | grep -q '^DU '; then # Deleted by us, unmerged by them | |
echo "Merge failed with conflicts (DU). Aborting push." | |
echo "outcome=failure" >> $GITHUB_OUTPUT | |
exit 1 # Fail the workflow explicitly | |
else | |
echo "Merge appears successful or conflicts resolved automatically." | |
echo "outcome=success" >> $GITHUB_OUTPUT | |
fi | |
# Push only if the merge succeeded (checked in previous step) | |
- name: Push changes to demo | |
if: steps.merge_check.outputs.outcome == 'success' | |
run: | | |
git push origin demo |