Skip to content

[workflow] Update functions.json #9

[workflow] Update functions.json

[workflow] Update functions.json #9

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: |
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\": \"A pull request was opened by ${GITHUB_ACTOR}.\"}" \
${{ secrets.DISCORD_TOKEN }}
- 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: Wait for status checks to complete
if: steps.check_user.outputs.is_aoijsbot == 'true'
run: |
while true; do
STATUS=$(gh pr view ${{ github.event.pull_request.number }} --json statusCheckRollup --jq '.statusCheckRollup.state')
echo "Current status: $STATUS"
if [[ "$STATUS" == "SUCCESS" ]]; then
break
fi
sleep 5
done
- 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 }}
gh api -X DELETE "repos/${{ github.repository }}/git/refs/heads/$BRANCH_NAME"
- name: Notify Discord about success
if: steps.check_user.outputs.is_aoijsbot == 'true'
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\": \"Pull request #${{ github.event.pull_request.number }} by aoijsbot has been successfully approved and merged.\"}" \
${{ secrets.DISCORD_TOKEN }}
- name: Notify Discord about failure
if: steps.check_user.outputs.is_aoijsbot == 'true' && failure()
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\": \"Pull request #${{ github.event.pull_request.number }} by aoijsbot failed to be approved or merged.\"}" \
${{ secrets.DISCORD_TOKEN }}