Merge core/v7.0 into docs #11
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 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@v4 | |
| with: | |
| ref: ${{ matrix.branch }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch_depth: 0 | |
| - 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 ${{ github.ref_name }} | |
| if git merge origin/${{ github.ref_name }} --no-commit --no-ff --allow-unrelated-histories; then | |
| git commit -m "Merge ${{ github.ref_name }} 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 Pull Request | |
| uses: peter-evans/create-pull-request@v7 | |
| id: create-pr | |
| if: steps.merge.outputs.status == 'conflict' | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| title: "Merge ${{ github.ref_name }} into ${{ matrix.branch }} (Conflicts)" | |
| body: The CLI autogenerated these changes to the SDK | |
| branch: merge-${{ github.ref_name }}-into-${{ matrix.branch }} | |
| base: ${{ matrix.branch }} | |
| labels: bot | |
| - 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" |