Skip to content

Merge core/v7.0 into docs #6

Merge core/v7.0 into docs

Merge core/v7.0 into docs #6

name: Auto Merge Core
on:
push:
branches:
- 'core/v7.0'
run-name: "Merge ${{ github.ref_name }} into docs"
jobs:
merge_branches:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
name: Merge ${{ github.ref_name }} into ${{ matrix.branch }}
strategy:
matrix:
branch: [unity/v5.0]
outputs:
success_branches: ${{ steps.aggregate.outputs.success_branches }}
conflicted_branches: ${{ steps.aggregate.outputs.conflicted_branches }}
steps:
- name: Checkout target branch
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Attempt merge
id: merge
run: |
git fetch origin core/v7.0
if git merge origin/core/v7.0 --no-commit --no-ff --allow-unrelated-histories; then
git commit -m "Merge core/v7.0 into ${{ matrix.branch }}" || true
git push origin ${{ matrix.branch }}
echo "status=success" >> $GITHUB_OUTPUT
else
git merge --abort
echo "status=conflict" >> $GITHUB_OUTPUT
fi
- name: Create PR on conflict
if: steps.merge.outputs.status == 'conflict'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Merge ${{ github.ref_name }} into ${{ matrix.branch }} (Conflicts)"
body: "Automatic merge failed due to conflicts. Please resolve manually."
base: ${{ github.ref_name }}
branch: ${{ github.ref_name }}
labels: auto-merge-conflict
- name: Collect PR URL
id: collect_pr
run: |
if [ "${{ steps.merge.outputs.status }}" == "conflict" ]; then
echo "PR_URL_${{ matrix.branch }}=${{ steps.create_pr.outputs.pull-request-url }}" >> "$GITHUB_ENV"
fi
- name: Aggregate results
id: aggregate
run: |
echo "SUCCESS_LIST=${{ matrix.branch }}" >> $GITHUB_OUTPUT
echo "CONFLICT_LIST=" >> $GITHUB_OUTPUT
if [ "${{ steps.merge.outputs.status }}" == "success" ]; then
echo "success_branches=${{ matrix.branch }}" >> $GITHUB_OUTPUT
echo "conflicted_branches=" >> $GITHUB_OUTPUT
else
echo "success_branches=" >> $GITHUB_OUTPUT
echo "conflicted_branches=${{ matrix.branch }}" >> $GITHUB_OUTPUT
fi
notify_slack:
runs-on: ubuntu-latest
needs: merge_branches
steps:
- name: Send Slack Summary
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DOCS_CHANNEL_URL }}
SUCCESS: ${{ needs.merge_branches.outputs.success_branches }}
CONFLICT: ${{ needs.merge_branches.outputs.conflicted_branches }}
PR_URLS: ${{ needs.merge_branches.outputs.conflict_pr_urls }}
run: |
SUCCESS_MSG=$( [ -n "$SUCCESS" ] && echo $'Success:\n• '"$SUCCESS" || echo "Success: None" )
if [ -n "$CONFLICT" ]; then
CONFLICT_MSG="Conflicts:"
IFS=',' read -ra BRANCHES <<< "$CONFLICT"
for b in "${BRANCHES[@]}"; do
# Assuming PR_URLS are stored in format branch=URL
url=$(echo "$PR_URLS" | grep "^PR_URL_$b=" | cut -d= -f2-)
CONFLICT_MSG+=$'\n• '"$b: $url"
done
else
CONFLICT_MSG="Conflicts: None"
fi
PAYLOAD=$(jq -n --arg success "$SUCCESS_MSG" --arg conflict "$CONFLICT_MSG" \
'{text: "${{ github.ref_name }} auto merge results:\n \($success)\n\($conflict)"}')
curl -s -X POST "$SLACK_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"