-
Notifications
You must be signed in to change notification settings - Fork 0
289 lines (257 loc) Β· 9.76 KB
/
Copy pathci.yml
File metadata and controls
289 lines (257 loc) Β· 9.76 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
name: Build-Up CI Pipeline
on:
pull_request:
branches: [ 'main', 'develop' ]
push:
branches: [ 'main', 'develop' ]
# λμΌν λΈλμΉμ λν΄ μ€λ³΅ μ€ν λ°©μ§
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
# ---------------------------------
# 1. Repo Checkout
# ---------------------------------
- name: π₯ Checkout repository
uses: actions/checkout@v4
# ---------------------------------
# 2. Set up Java 21
# ---------------------------------
- name: β Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'gradle'
# ---------------------------------
# 3. Gradle Wrapper μ€ν κΆν λΆμ¬
# ---------------------------------
- name: π§ Grant execute permission for Gradle Wrapper
run: chmod +x ./gradlew
# ---------------------------------
# 4. ν
μ€νΈ μ€ν
# ---------------------------------
- name: π§ͺ Run Tests
run: ./gradlew test --no-daemon --stacktrace
env:
SPRING_PROFILES_ACTIVE: test
# ν
μ€νΈμ© λλ―Έ κ° (application-test.ymlμ κΈ°λ³Έκ° μ¬μ©)
JWT_SECRET: test-secret-key-min-256-bits-long-for-hs256-algorithm-test
ENCRYPTION_KEY: 0123456789abcdef0123456789abcdef
# ν
μ€νΈλ H2 DBλ₯Ό μ¬μ©νλ―λ‘ MySQL μ€μ λΆνμ
# ---------------------------------
# 5. ν
μ€νΈ κ²°κ³Ό μ
λ‘λ
# ---------------------------------
- name: π Upload Test Report
if: always()
uses: actions/upload-artifact@v4
with:
name: test-report
path: build/reports/tests/test/
retention-days: 7
# ---------------------------------
# 6. ν
μ€νΈ 컀λ²λ¦¬μ§ 리ν¬νΈ (μ νμ¬ν)
# ---------------------------------
- name: π Upload Coverage Report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: build/reports/jacoco/test/html/
retention-days: 7
# ---------------------------------
# 7. μ ν리μΌμ΄μ
λΉλ
# ---------------------------------
- name: ποΈ Build Application
run: ./gradlew clean build -x test --no-daemon
env:
# λΉλμ© λλ―Έ κ° (μ€μ λ°νμμμλ μ¬μ©λμ§ μμ)
JWT_SECRET: ${{ secrets.JWT_SECRET || 'test-secret-key-min-256-bits-long-for-hs256-algorithm-test' }}
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY || '0123456789abcdef0123456789abcdef' }}
# ---------------------------------
# 8. JAR νμΌ μ
λ‘λ
# ---------------------------------
- name: π¦ Upload JAR Artifact
uses: actions/upload-artifact@v4
with:
name: buildup-jar
path: build/libs/*.jar
retention-days: 7
docker-build:
needs: build-and-test
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
# ---------------------------------
# 1. Repo Checkout
# ---------------------------------
- name: π₯ Checkout repository
uses: actions/checkout@v4
# ---------------------------------
# 2. Docker Buildx μ€μ
# ---------------------------------
- name: π³ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# ---------------------------------
# 3. Docker Image Build (Push μμ΄)
# ---------------------------------
- name: ποΈ Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: buildup:pr-${{ github.event.pull_request.number }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
# ---------------------------------
# 4. Docker 컨ν
μ΄λ μ€ν ν
μ€νΈ
# ---------------------------------
- name: π§ͺ Test Docker container
run: |
# Docker λ€νΈμν¬ μμ±
docker network create buildup-test-network
# MySQL 컨ν
μ΄λ μμ (ν
μ€νΈμ©)
docker run -d --name mysql-test \
--network buildup-test-network \
-e MYSQL_ROOT_PASSWORD=test_root_pass \
-e MYSQL_DATABASE=buildup_test \
-e MYSQL_USER=buildup_user \
-e MYSQL_PASSWORD=test_pass \
mysql:8.0
echo "β³ MySQL μμ λκΈ° μ€..."
sleep 20
# μ ν리μΌμ΄μ
컨ν
μ΄λ μμ
docker run -d --name buildup-test \
--network buildup-test-network \
-e SPRING_PROFILES_ACTIVE=dev \
-e JWT_SECRET=test-secret-key-min-256-bits-long-for-hs256-algorithm-test \
-e ENCRYPTION_KEY=0123456789abcdef0123456789abcdef \
-e SPRING_DATASOURCE_URL="jdbc:mysql://mysql-test:3306/buildup_test?useSSL=false&allowPublicKeyRetrieval=true" \
-e SPRING_DATASOURCE_USERNAME=buildup_user \
-e SPRING_DATASOURCE_PASSWORD=test_pass \
-e ADMIN_USERNAME=admin \
-e ADMIN_PASSWORD=test_admin_pass \
-e AWS_S3_ENABLED=false \
-e AWS_S3_BUCKET=test-bucket \
-e AWS_REGION=ap-northeast-2 \
-e AWS_ACCESS_KEY_ID=test-key \
-e AWS_SECRET_ACCESS_KEY=test-secret \
buildup:pr-${{ github.event.pull_request.number }}
echo "β³ μ ν리μΌμ΄μ
μμ λκΈ° μ€..."
sleep 40
# ν¬μ€μ²΄ν¬
if docker ps | grep buildup-test; then
echo "β
Docker 컨ν
μ΄λ μ μ μ€ν μ€"
# λ‘κ·Έ νμΈ
echo "π 컨ν
μ΄λ λ‘κ·Έ (λ§μ§λ§ 50μ€):"
docker logs buildup-test --tail 50
# ν¬μ€μ²΄ν¬ μλν¬μΈνΈ νμΈ
CONTAINER_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' buildup-test)
echo "π ν¬μ€μ²΄ν¬ ν
μ€νΈ: http://${CONTAINER_IP}:8080/api/actuator/health"
# μ 리
docker stop buildup-test
docker rm buildup-test
docker stop mysql-test
docker rm mysql-test
docker network rm buildup-test-network
echo "β
Docker 컨ν
μ΄λ ν
μ€νΈ μλ£"
else
echo "β Docker 컨ν
μ΄λ μ€ν μ€ν¨"
docker logs buildup-test 2>/dev/null || echo "컨ν
μ΄λ λ‘κ·Έλ₯Ό κ°μ Έμ¬ μ μμ΅λλ€"
docker rm buildup-test 2>/dev/null || true
docker stop mysql-test
docker rm mysql-test
docker network rm buildup-test-network
exit 1
fi
# ---------------------------------
# μλ¦Ό μμ
(μ νμ¬ν - DISCORD_WEBHOOK μ€μ μ μλ)
# ---------------------------------
notify:
needs: [build-and-test, docker-build]
runs-on: ubuntu-latest
if: always()
steps:
- name: π’ Notify Discord
continue-on-error: true
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
# Discord Webhookμ΄ μ€μ λμ§ μμ κ²½μ° μ€ν΅
if [ -z "$DISCORD_WEBHOOK" ]; then
echo "β οΈ Discord Webhookμ΄ μ€μ λμ§ μμ μλ¦Όμ 건λλλλ€."
exit 0
fi
BUILD_STATUS="${{ needs.build-and-test.result }}"
DOCKER_STATUS="${{ needs.docker-build.result }}"
BRANCH="${{ github.ref_name }}"
AUTHOR="${{ github.actor }}"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
if [ "${{ github.event_name }}" = "pull_request" ]; then
PR_INFO="PR #${{ github.event.pull_request.number }}"
PR_TITLE="${{ github.event.pull_request.title }}"
else
PR_INFO="Push to ${BRANCH}"
PR_TITLE="Direct Push"
fi
# μ 체 μν νλ¨
if [ "${BUILD_STATUS}" = "success" ] && ([ "${DOCKER_STATUS}" = "success" ] || [ "${DOCKER_STATUS}" = "skipped" ]); then
ICON="β
"
COLOR=3066993
MESSAGE="Build-Up CI μ±κ³΅"
else
ICON="β"
COLOR=15158332
MESSAGE="Build-Up CI μ€ν¨"
fi
PAYLOAD=$(cat <<EOF
{
"embeds": [{
"title": "${ICON} ${MESSAGE}",
"description": "${PR_TITLE}",
"color": ${COLOR},
"fields": [
{
"name": "μ΄λ²€νΈ",
"value": "${PR_INFO}",
"inline": true
},
{
"name": "λΈλμΉ",
"value": "\`${BRANCH}\`",
"inline": true
},
{
"name": "μμ±μ",
"value": "${AUTHOR}",
"inline": true
},
{
"name": "λΉλ μν",
"value": "${BUILD_STATUS}",
"inline": true
},
{
"name": "Docker λΉλ",
"value": "${DOCKER_STATUS}",
"inline": true
},
{
"name": "λ‘κ·Έ",
"value": "[보기](${RUN_URL})",
"inline": true
}
],
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)"
}]
}
EOF
)
curl -X POST \
-H 'Content-Type: application/json' \
--data "${PAYLOAD}" \
"$DISCORD_WEBHOOK"