test(빌드 실패 시 pr 종료) : test 코드 실패시 pr 닫히는지 테스트 #10
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 | |
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.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull_number, | |
title: updated_title, | |
state: 'closed' | |
}) |