-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (129 loc) · 6 KB
/
Copy pathci.yml
File metadata and controls
146 lines (129 loc) · 6 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
name: CI
on:
push:
branches: [dev, main]
pull_request:
types: [opened, synchronize]
branches: [dev, main]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle.kts', '**/gradle-wrapper.properties') }}
restore-keys: gradle-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build
run: ./gradlew assemble --no-daemon
# 배포(deploy.yml)가 이 JAR 을 그대로 받아쓰도록 업로드해, deploy 단계의 재빌드(중복)를 없앤다.
# deploy 는 push CI 의 workflow_run 으로만 트리거되므로(PR 은 배포 안 됨) push 일 때만 올린다.
# 보존 3일이 안전한 이유: 아티팩트는 이 CI 직후(수분 내) 그 workflow_run 배포가 소비하므로 3일은 큰 여유다.
# 롤백·재배포도 옛 아티팩트에 기대지 않는다 - 자동배포는 새 push 라 늘 새 아티팩트, 수동 재배포는
# 러너 빌드 fallback(deploy.yml), blue-green 롤백은 돌던 컨테이너 유지. 누적 방지 겸 짧게 둔다.
# JAR 이 없으면 즉시 실패시킨다.
- name: Upload JAR artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: app-jar
path: build/libs/*.jar
retention-days: 3
if-no-files-found: error
# JAR 은 이미 압축된 zip 이라 기본 level 6 재압축은 크기 이득 ~0 에 CPU 만 쓴다.
# store(0)로 헛수고를 없애 업로드를 줄인다. CI 는 deploy 가 workflow_run 으로 기다리는 크리티컬 패스다.
compression-level: 0
test:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
checks: write
steps:
- uses: actions/checkout@v4
# 추출 실패 code 계약(정본은 infra)을 같은 러너에 둔다 — ExtractionErrorCatalogTest 가
# shared-infra/contracts/extraction-error-codes.yaml 을 읽어 translate 매핑·메트릭 reason 과 대조한다.
# 경로가 shared-infra 인 이유: infra 의 install.sh 도 로컬에 같은 경로로 설치해 로컬과 CI 가 같은 파일을 본다.
# 체크아웃이 없으면 그 테스트가 실패한다(skip 하면 계약 강제가 조용히 사라지므로 의도된 동작).
# 옵션은 extractor 쪽 같은 스텝과 일치시킨다(extractor#32) — 같은 목적으로 같은 repo 를 받는 두 소비자가
# 갈리면 한쪽만 손보게 된다. sparse-checkout 은 필요한 디렉터리만, persist-credentials=false 는 러너에
# 자격증명을 남기지 않게, ref 는 어느 브랜치가 정본인지 명시한다.
- name: Checkout extraction contract
uses: actions/checkout@v4
with:
repository: TeamPiKi/infra
ref: main
path: shared-infra
sparse-checkout: contracts
persist-credentials: false
- uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle.kts', '**/gradle-wrapper.properties') }}
restore-keys: gradle-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test
run: ./gradlew test --no-daemon
- name: Report test results
if: always()
uses: dorny/test-reporter@v1
with:
name: Test Results
path: build/test-results/**/*.xml
reporter: java-junit
fail-on-error: false
# nginx conf 문법 검증 — 깨진 conf 가 dev 에 머지된 뒤 배포(deploy.yml)에서야 nginx -t 로
# 걸려 롤백되던 걸, PR 단계에서 미리 막는다. infra/nginx 변경이 없는 PR 도 수초면 통과하므로
# path filter 없이 항상 돌려 required check 로 걸어도 skip 함정이 없게 한다.
nginx-validate:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
steps:
- uses: actions/checkout@v4
# conf 는 http{} 안에서 include 되는 partial 이고, SSL 인증서·upstream include 가 런타임
# 의존이라 그대로는 단독 검증이 안 된다. 우회: http 컨텍스트 래퍼로 감싸고, SSL·letsencrypt
# 라인을 제거(listen 443 ssl[...] → 평문 8443: prod 는 http2, dev 는 없는 형식 둘 다 커버),
# upstream include 는 더미로 마운트한다. 실제 인증서 검증은 배포 시 deploy.yml 이 EC2 에서 한다.
- name: Validate nginx configs
run: |
set -e
for conf in infra/nginx/*.conf; do
echo "::group::validate $conf"
work=$(mktemp -d)
sed -e 's/listen 443 ssl[^;]*;/listen 8443;/' \
-e '/ssl_certificate/d' -e '/ssl_dhparam/d' -e '/include \/etc\/letsencrypt/d' \
"$conf" > "$work/site.conf"
echo 'server 127.0.0.1:8080;' > "$work/team3-upstream.conf"
printf 'events {}\nhttp {\n include /work/site.conf;\n}\n' > "$work/nginx.conf"
docker run --rm \
-v "$work/nginx.conf:/work/nginx.conf:ro" \
-v "$work/site.conf:/work/site.conf:ro" \
-v "$work/team3-upstream.conf:/etc/nginx/team3-upstream.conf:ro" \
nginx:alpine nginx -t -c /work/nginx.conf
echo "::endgroup::"
done