Skip to content

add README for contributors #68

add README for contributors

add README for contributors #68

Workflow file for this run

name: Sync Branches with Main
on:
push:
branches: [main]
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
strategy:
matrix:
branches: [content] # Add new branches here
steps:
- name: Checkout Main Branch
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Git User
run: |
git config user.name "GitHub Action"
git config user.email "action@github.com"
- name: Sync with ${{ matrix.branch }}
run: |
TARGET_BRANCH="${{ matrix.branch }}"
git fetch --all --prune
# Check if target branch is an ancestor of main (can fast-forward)
if git merge-base --is-ancestor origin/${TARGET_BRANCH} origin/main 2>/dev/null; then
echo "Branch ${TARGET_BRANCH} is behind main and can be fast-forwarded"
git checkout ${TARGET_BRANCH}
git reset --hard origin/main
git push origin ${TARGET_BRANCH} --force
else
echo "Branch ${TARGET_BRANCH} has diverged from main, attempting merge"
# Ensure target branch is up-to-date with origin
git checkout ${TARGET_BRANCH}
git pull --no-rebase origin ${TARGET_BRANCH} || true
# Merge origin/main into the target branch
# Use --no-ff to create an explicit merge commit when required and
# --no-edit to avoid interactive editor for the merge message.
if git merge --no-ff --no-edit origin/main; then
git push origin ${TARGET_BRANCH}
else
# On merge conflict, abort and push a backup branch so nothing is lost.
git merge --abort || true
BACKUP_BRANCH="backup/${TARGET_BRANCH}-merge-failed-$(date +%s)"
git push origin HEAD:refs/heads/${BACKUP_BRANCH}
echo "Merge failed. Backup pushed to ${BACKUP_BRANCH}. Exiting with failure."
exit 1
fi
fi