Skip to content

빌드 실패시 디스코드 알림 전송 테스트 #15

빌드 실패시 디스코드 알림 전송 테스트

빌드 실패시 디스코드 알림 전송 테스트 #15

name: Close PR when Build Fail
on:
pull_request:
types: [ opened ]
branches: [ 'main' ]
jobs:
build_and_test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
continue-on-error: true
id: build_and_test
run:
./gradlew clean build --stacktrace
- name: If build fail
continue-on-error: true
# 이전 step이 실패한 경우에만 이 step을 실행시키는 syntax
if: ${{ steps.build_and_test.conclusion == 'failure'}}
id: close_pr
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pull_number = ${{ github.event.pull_request.number }}
const updated_title = `[BUILD FAIL] ${{ github.event.pull_request.title }}`
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number,
body: '빌드에 실패했습니다.',
event: 'REQUEST_CHANGES'
})
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number,
title: updated_title,
state: 'closed'
})
- name: Send Build Fail Message to Discord
continue-on-error: true
if: ${{ steps.build_and_test.conclusion == 'failure'}}
run: |
curl --location ${{secrets.DISCORD_WEBHOOK_URL}} \
--header 'Content-Type: application/json' \
--data '{
"avatar_url": "https://cdn-icons-png.flaticon.com/512/25/25231.png",
"embeds": [
{
"title": "${{ github.event.pull_request.title }}",
"type": "rich",
"description": "빌드가 실패했습니다.",
"url": "${{github.ref}}"
}
]}'