forked from News-Deliver/Server
-
Notifications
You must be signed in to change notification settings - Fork 0
198 lines (166 loc) · 7.13 KB
/
Copy pathdev-test.yml
File metadata and controls
198 lines (166 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Dev 브랜치 테스트
on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 12 # 테스트 시간 제한
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: testpass
MYSQL_DATABASE: backendDB
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=5s
--health-timeout=3s
--health-retries=6
redis:
image: redis:7.2
ports:
- 6379:6379
- 6380:6379
- 6381:6379
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0
env:
discovery.type: single-node
xpack.security.enabled: false
ES_JAVA_OPTS: -Xms256m -Xmx256m # 메모리 사용량 감소
ports:
- 9200:9200
steps:
- uses: actions/checkout@v4
- name: JDK 17 설정
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
- name: Gradle 패키지 캐시
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- name: gradlew 권한 설정
run: chmod +x SpringBoot/gradlew
- name: 서비스 준비 대기 (최적화)
run: |
echo "⏳ Dev 테스트 환경 준비 중..."
# 병렬로 서비스 상태 확인
wait_for_service() {
local service_name=$1
local check_cmd=$2
local max_attempts=$3
for i in $(seq 1 $max_attempts); do
if eval "$check_cmd" >/dev/null 2>&1; then
echo "✅ $service_name 준비 완료"
return 0
fi
sleep 1
done
echo "❌ $service_name 준비 실패"
return 1
}
# 병렬 서비스 체크 (시간 단축)
wait_for_service "MySQL" "mysqladmin ping -h127.0.0.1 -P3306 -uroot -ptestpass --silent" 10 &
wait_for_service "Redis" "redis-cli -h 127.0.0.1 -p 6379 ping | grep -q PONG" 8 &
wait_for_service "Elasticsearch" "curl -f http://localhost:9200/_cluster/health" 15 &
# 모든 백그라운드 작업 완료 대기
wait
echo "✅ 모든 서비스 준비 완료"
- name: 테스트용 환경설정 파일 생성
working-directory: ./SpringBoot
run: |
cat > src/main/resources/application-test.properties << 'EOF'
spring.application.name=News-Deliver
spring.main.allow-bean-definition-overriding=true
# DB Connection
spring.datasource.url=jdbc:mysql://localhost:3306/backendDB?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=testpass
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# JPA Configuration
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
# Redis Configuration
redis.cache.host=localhost
redis.cache.port=6379
redis.session1.host=localhost
redis.session1.port=6380
redis.session2.host=localhost
redis.session2.port=6381
# Elasticsearch
spring.elasticsearch.uris=http://localhost:9200
# JWT
jwt.secretKey=test-secret-key-that-is-long-enough-for-jwt-hmac-sha256-algorithm-minimum-32-bytes
jwt.accessTokenExpirationTime=1800000
jwt.refreshTokenExpirationTime=86400000
# OAuth2
spring.security.oauth2.client.registration.kakao.client-id=test-id
spring.security.oauth2.client.registration.kakao.client-secret=test-secret
spring.security.oauth2.client.registration.kakao.client-authentication-method=client_secret_post
spring.security.oauth2.client.registration.kakao.redirect-uri=http://localhost/login/oauth2/code/kakao
spring.security.oauth2.client.registration.kakao.authorization-grant-type=authorization_code
spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize
spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token
spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me
spring.security.oauth2.client.provider.kakao.user-name-attribute=id
# Spring AI
spring.ai.openai.api-key=test-key
spring.ai.openai.chat.options.model=gpt-3.5-turbo
# DeepSearch API
deepsearch.api.key=test-key
# Batch Job 비활성화 (테스트 시)
spring.batch.job.enabled=false
# Logging Configuration
logging.level.org.springframework.web=INFO
logging.level.org.hibernate.SQL=ERROR
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=ERROR
logging.level.com.zaxxer.hikari=ERROR
# Time Zone
spring.jackson.time-zone=Asia/Seoul
# Forward headers
server.forward-headers-strategy=framework
EOF
- name: 테스트 실행 (최적화)
working-directory: ./SpringBoot
env:
SPRING_PROFILES_ACTIVE: test
run: |
echo "🚀 Dev 브랜치 테스트 시작"
./gradlew clean build --no-daemon --parallel --build-cache
- name: 테스트 결과 업로드
uses: actions/upload-artifact@v4
if: failure()
with:
name: dev-test-reports-${{ github.run_number }}
path: |
SpringBoot/build/reports/
SpringBoot/build/test-results/
retention-days: 3
- name: 결과 요약
if: always()
run: |
echo "## 📋 Dev 테스트 결과" >> $GITHUB_STEP_SUMMARY
echo "- **테스트 상태**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
echo "- **브랜치**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **커밋**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **실행 시간**: $(date)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ job.status }}" == "success" ]; then
echo "### ✅ Dev 테스트 성공!" >> $GITHUB_STEP_SUMMARY
echo "모든 테스트가 통과했습니다. 프로덕션 배포 준비 완료!" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Dev 테스트 실패!" >> $GITHUB_STEP_SUMMARY
echo "테스트 실패 원인을 확인하고 수정해주세요." >> $GITHUB_STEP_SUMMARY
fi