Skip to content

[workflow] Update functions.json #31

[workflow] Update functions.json

[workflow] Update functions.json #31

Workflow file for this run

name: Auto Approve and Merge
on:
pull_request:
types: [opened]
workflow_dispatch:
jobs:
auto-approve-and-merge:
runs-on: ubuntu-latest
outputs:
is_aoijsbot: ${{ steps.check_user.outputs.is_aoijsbot }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check if the PR is opened by aoijsbot
id: check_user
run: |
if [ "${{ github.actor }}" == "aoijsbot" ]; then
echo "Is opened by aoijsbot."
echo "::set-output name=is_aoijsbot::true"
else
echo "Not opened by aoijsbot, skipping."
echo "::set-output name=is_aoijsbot::false"
fi
continue-on-error: true
- name: Notify Discord about PR opened
if: steps.check_user.outputs.is_aoijsbot == 'true'
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
PR_LINK="${{ github.event.pull_request.html_url }}"
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\": \"Found docs changes in [${PR_TITLE}](${PR_LINK}), pulling changes.\"}" \
${{ secrets.DISCORD_TOKEN }}
- name: Sleep
if: steps.check_user.outputs.is_aoijsbot == 'true'
run: |
echo "Waiting 35 seconds for check to complete"
sleep 35
- name: Approve the pull request
if: steps.check_user.outputs.is_aoijsbot == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr review ${{ github.event.pull_request.number }} --approve
- name: Merge the pull request
if: steps.check_user.outputs.is_aoijsbot == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr merge ${{ github.event.pull_request.number }} --squash --admin
- name: Delete branch after merge
if: steps.check_user.outputs.is_aoijsbot == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
REPO="${{ github.repository }}"
echo "Deleting branch ${BRANCH_NAME} from ${REPO}..."
gh api -X DELETE /repos/${REPO}/git/refs/heads/${BRANCH_NAME}
- name: Notify Discord about success
if: steps.check_user.outputs.is_aoijsbot == 'true'
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
PR_LINK="${{ github.event.pull_request.html_url }}"
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\": \"Successfully merged and deleted branch for [${PR_TITLE}](<${PR_LINK}>).\"}" \
${{ secrets.DISCORD_TOKEN }}
- name: Notify Discord about failure
if: steps.check_user.outputs.is_aoijsbot == 'true' && failure()
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
PR_LINK="${{ github.event.pull_request.html_url }}"
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\": \"Failed to merge changes in [${PR_TITLE}](<${PR_LINK}>).\"}" \
${{ secrets.DISCORD_TOKEN }}