Skip to content

Commit 2a68616

Browse files
authored
cicd: main 브랜치에 대한 CI 파이프라인 설정
- main 브랜치에 푸시 및 PR 시 CI가 트리거되도록 설정 - 빌드, 테스트 및 실패 시 알림및 PR close 설정
1 parent 6efaa37 commit 2a68616

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

.github/workflows/CI.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)