Create main.yml #1
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: Auto-Merge Main into Sub-Branches | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
jobs: | |
auto-merge: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout main branch | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- 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: Fetch all branches | |
run: | | |
git fetch --prune --all | |
- name: Merge main into sub-branches | |
run: | | |
for branch in functional technical quality_assurance management dev; do | |
echo "Checking branch: $branch" | |
if git ls-remote --heads origin "$branch" | grep -q "refs/heads/$branch"; then | |
echo "Branch $branch exists, proceeding..." | |
if git show-ref --verify --quiet "refs/heads/$branch"; then | |
git checkout "$branch" | |
else | |
git checkout -b "$branch" "origin/$branch" | |
fi | |
if git merge --no-edit main; then | |
git push origin "$branch" | |
else | |
echo "Merge conflict in $branch, please resolve manually." | |
exit 1 | |
fi | |
else | |
echo "Branch $branch does not exist on origin, skipping." | |
fi | |
done |