Skip to content

Update default direction to column #65

Update default direction to column

Update default direction to column #65

name: Sync Theme Branches
on:
push:
branches:
- main
paths-ignore: # Theme specific files, also needed in .gitattributes below.
- 'config/markets.json'
- 'config/settings_data.json'
- 'sections/*.json'
- 'templates/*.json'
pull_request:
types: [closed]
branches:
- main
paths-ignore:
- 'config/markets.json'
- 'config/settings_data.json'
- 'sections/*.json'
- 'templates/*.json'
jobs:
sync-stores:
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
store: [live/site2] # Add your store branches here: [live/US, live/CA]
fail-fast: false # Continue with other stores if one fails
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better merge resolution
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Checkout target branch
run: |
# Check if the target branch exists remotely
if git ls-remote --heads origin ${{ matrix.store }} | grep -q ${{ matrix.store }}; then
# Branch exists, checkout and track it
git checkout -b ${{ matrix.store }} origin/${{ matrix.store }}
else
# Branch doesn't exist, create it from main
echo "Branch ${{ matrix.store }} doesn't exist, creating from main..."
git checkout -b ${{ matrix.store }} main
git push -u origin ${{ matrix.store }}
fi
- name: Merge main into ${{ matrix.store }}
id: merge
run: |
# Check if we're already up to date
if git merge-base --is-ancestor main HEAD; then
echo "Branch ${{ matrix.store }} is already up to date with main"
exit 0
fi
# Merge main into target branch, automatically resolving conflicts in ignored files
echo "Merging main into ${{ matrix.store }} with automatic conflict resolution..."
# Set up merge strategy to automatically resolve conflicts in ignored files
git config merge.ours.driver true
# Create .gitattributes to handle ignored files properly
cat > .gitattributes << 'EOF'
config/markets.json merge=ours
config/settings_data.json merge=ours
sections/*.json merge=ours
templates/*.json merge=ours
EOF
# Perform the merge
if git merge --no-ff main -m "Auto-sync from main branch [skip ci]"; then
echo "Merge successful, pushing changes..."
git push origin ${{ matrix.store }}
else
echo "Handling merge conflicts in ignored files..."
# Check if conflicts are only in ignored files
CONFLICT_FILES=$(git diff --name-only --diff-filter=U)
IGNORED_CONFLICTS=""
NON_IGNORED_CONFLICTS=""
for file in $CONFLICT_FILES; do
if [[ "$file" =~ ^(config/markets\.json|config/settings_data\.json|sections/.*\.json|templates/.*\.json)$ ]]; then
IGNORED_CONFLICTS="$IGNORED_CONFLICTS $file"
else
NON_IGNORED_CONFLICTS="$NON_IGNORED_CONFLICTS $file"
fi
done
if [ -n "$NON_IGNORED_CONFLICTS" ]; then
echo "::error::Merge conflict in non-ignored files:$NON_IGNORED_CONFLICTS"
git merge --abort
exit 1
fi
# Resolve conflicts in ignored files by keeping target branch version
echo "Resolving conflicts in ignored files:$IGNORED_CONFLICTS"
for file in $IGNORED_CONFLICTS; do
echo "Resolving conflict for $file by keeping target branch version"
# Check if file exists in target branch (HEAD)
if git show HEAD:"$file" >/dev/null 2>&1; then
# File exists in target branch, keep it
echo " File exists in target branch, keeping target version"
git checkout --ours "$file"
git add "$file"
else
# File doesn't exist in target branch, remove it
echo " File doesn't exist in target branch, removing it"
git rm --cached "$file" 2>/dev/null || true
# Also remove from working directory if it exists
rm -f "$file"
fi
done
# Complete the merge
git commit --no-edit
echo "Merge successful after resolving ignored file conflicts, pushing changes..."
git push origin ${{ matrix.store }}
fi
# Clean up
rm -f .gitattributes
git config --unset merge.ours.driver
- name: Verify merge
run: |
# Check if the merge was successful
git log --oneline -5
- name: Notify success
if: success()
run: |
echo "✅ Successfully synced ${{ matrix.store }} with main branch"
- name: Notify failure
if: failure()
run: |
echo "❌ Failed to sync ${{ matrix.store }} with main branch"
echo "Please check for merge conflicts and resolve manually"