Skip to content

Commit 6e94539

Browse files
CICD:: test.yml 파일 생성
- main브랜치에 PULL을 요청하는 PR을 감지해 테스트 코드를 수행 - 테스트 코드가 정상적으로 통과하면 PR이 정상동작 - 테스트 코드가 정상적으로 작동하지 않으면 PR이 반환되며 오류 Comment가 PR에 달림
1 parent a597f24 commit 6e94539

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

.github/workflows/test.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: PR Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main # main 브랜치로 머지되는 PR에서 실행
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# 1. 코드 체크아웃
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
# 2. JDK 21 설정
18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v2
20+
with:
21+
java-version: '21'
22+
distribution: 'temurin'
23+
24+
# 3. Gradle Wrapper 검증
25+
- name: Validate Gradle Wrapper
26+
uses: gradle/wrapper-validation-action@v1
27+
28+
# 4. 환경 변수 설정 파일 생성
29+
- name: Create Config Files
30+
run: |
31+
mkdir -p ontime-back/src/main/resources
32+
echo "spring.application.name=${{ secrets.SPRING_APPLICATION_NAME }}" > ontime-back/src/main/resources/application.properties
33+
echo "spring.datasource.url=${{ secrets.SPRING_DATASOURCE_URL }}" >> ontime-back/src/main/resources/application.properties
34+
echo "spring.datasource.username=${{ secrets.SPRING_DATASOURCE_USERNAME }}" >> ontime-back/src/main/resources/application.properties
35+
echo "spring.datasource.password=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" >> ontime-back/src/main/resources/application.properties
36+
echo "spring.datasource.driver-class-name=${{ secrets.SPRING_DATASOURCE_DRIVER_CLASS_NAME }}" >> ontime-back/src/main/resources/application.properties
37+
echo "spring.jpa.hibernate.ddl-auto=${{ secrets.SPRING_JPA_HIBERNATE_DDL_AUTO }}" >> ontime-back/src/main/resources/application.properties
38+
echo "jwt.secret.key=${{ secrets.JWT_SECRETKEY }}" >> ontime-back/src/main/resources/application.properties
39+
echo "jwt.access.expiration=${{ secrets.JWT_ACCESS_EXPIRATION }}" >> ontime-back/src/main/resources/application.properties
40+
echo "jwt.refresh.expiration=${{ secrets.JWT_REFRESH_EXPIRATION }}" >> ontime-back/src/main/resources/application.properties
41+
echo "jwt.access.header=${{ secrets.JWT_ACCESS_HEADER }}" >> ontime-back/src/main/resources/application.properties
42+
echo "jwt.refresh.header=${{ secrets.JWT_REFRESH_HEADER }}" >> ontime-back/src/main/resources/application.properties
43+
44+
# 5. Gradle 빌드 & JUnit 테스트 실행
45+
- name: Run Tests with Gradle
46+
id: test
47+
run: |
48+
cd ontime-back
49+
./gradlew test
50+
continue-on-error: true # 실패해도 다음 스텝 실행 가능하도록 설정
51+
52+
handle-failure:
53+
needs: test
54+
if: failure() # 이전 job이 실패한 경우 실행
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Close PR
58+
uses: octokit/request-action@v2.x
59+
with:
60+
route: PATCH /repos/{owner}/{repo}/pulls/{pull_number}
61+
owner: ${{ github.repository_owner }}
62+
repo: ${{ github.event.repository.name }}
63+
pull_number: ${{ github.event.pull_request.number }}
64+
state: closed
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Comment on PR
69+
uses: actions/github-script@v6
70+
with:
71+
github-token: ${{ secrets.GITHUB_TOKEN }}
72+
script: |
73+
github.issues.createComment({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
issue_number: context.payload.pull_request.number,
77+
body: "테스트가 실패했습니다.\n자세한 실패 로그를 확인하고 수정한 후 다시 PR을 올려주세요!"
78+
})

0 commit comments

Comments
 (0)