test : 빌드 실패시 디스코드에 알림 전송하는 기능 테스트 #14
Workflow file for this run
This file contains 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: 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 | |
run: | |
./gradlew clean build --stacktrace | |
- name: If build fail | |
# 이전 step이 실패한 경우에만 이 step을 실행시키는 syntax | |
if: ${{ failure() }} | |
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' | |
}) | |
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}}" | |
} | |
]}' |