|
| 1 | +name: CI Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + [ main ] |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + [ main ] |
| 10 | + types: |
| 11 | + [opened, synchronize, reopened] |
| 12 | + |
| 13 | +jobs: |
| 14 | + Continuous-Integration: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + env: |
| 18 | + DB_URL: ${{ secrets.DB_URL }} |
| 19 | + DB_USERNAME: ${{ secrets.DB_USERNAME }} |
| 20 | + DB_PASSWORD: ${{ secrets.DB_PASSWORD }} |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Github Repository 파일 불러오기 |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: JDK 21 버전 설치 |
| 29 | + uses: actions/setup-java@v4 |
| 30 | + with: |
| 31 | + distribution: temurin |
| 32 | + java-version: 21 |
| 33 | + |
| 34 | + - name: Gradle 캐싱 |
| 35 | + uses: actions/cache@v3 |
| 36 | + with: |
| 37 | + path: | |
| 38 | + ~/.gradle/caches |
| 39 | + ~/.gradle/wrapper |
| 40 | + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} |
| 41 | + restore-keys: | |
| 42 | + ${{ runner.os }}-gradle- |
| 43 | +
|
| 44 | + - name: 빌드 권한 부여 |
| 45 | + run: chmod +x ./gradlew |
| 46 | + shell: bash |
| 47 | + |
| 48 | + |
| 49 | + - name: 빌드 및 테스트 |
| 50 | + run: ./gradlew build |
| 51 | + |
| 52 | + |
| 53 | + - name: Close PR, if build fail |
| 54 | + if: ${{ failure() }} |
| 55 | + uses: actions/github-script@v6 |
| 56 | + with: # actions(uses)의 파라미터 역할 |
| 57 | + github-token: ${{ github.TOKEN }} |
| 58 | + script: | |
| 59 | + const pull_number = ${{ github.event.pull_request.number }} |
| 60 | + const updated_title = `[BUILD FAIL] ${{ github.event.pull_request.title }}` |
| 61 | + await github.rest.pulls.createReview({ |
| 62 | + owner: context.repo.owner, |
| 63 | + repo: context.repo.repo, |
| 64 | + pull_number: pull_number, |
| 65 | + body: '빌드에 실패했습니다.', |
| 66 | + event: 'REQUEST_CHANGES' |
| 67 | + }) |
| 68 | + await github.rest.pulls.update({ |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + pull_number: pull_number, |
| 72 | + title: updated_title, |
| 73 | + state: 'closed' |
| 74 | + }) |
0 commit comments