8585 runs-on : ubuntu-latest
8686 environment : develop
8787 needs : terraform-apply-dev
88+ outputs :
89+ outcome : ${{ job.status }}
90+ has_version : ${{ steps.get_version.outputs.HAS_VERSION }}
91+ version : ${{ steps.get_version.outputs.VERSION }}
8892 steps :
8993 - uses : actions/checkout@v4
94+ with :
95+ fetch-depth : 0
9096
9197 - name : Parse Terraform Outputs and Set Environment Variables
9298 run : |
@@ -107,12 +113,12 @@ jobs:
107113 - name : Update MYSQL_URL in Parameter Store
108114 run : |
109115 MYSQL_URL="jdbc:mysql://${PRIVATE_IP}:3306/eatda?useUnicode=true&characterEncoding=UTF-8"
110-
116+
111117 aws ssm put-parameter \
112- --name "/dev/MYSQL_URL" \
113- --type "SecureString" \
114- --value "$MYSQL_URL" \
115- --overwrite
118+ --name "/dev/MYSQL_URL" \
119+ --type "SecureString" \
120+ --value "$MYSQL_URL" \
121+ --overwrite
116122
117123 - name : Set up Node.js
118124 uses : actions/setup-node@v4
@@ -131,18 +137,27 @@ jobs:
131137 - name : Semantic Release
132138 id : get_version
133139 run : |
134- OUTPUT=$(./node_modules/.bin/ semantic-release --no-ci)
140+ OUTPUT=$(npm exec --no -- semantic-release --no-ci)
135141 echo "$OUTPUT"
136- VERSION=$(echo "$OUTPUT" | grep -oP 'Published (?:pre)?release \K[0-9.a-z-]+')
137- if [ -z "$VERSION" ]; then
142+ VERSION=$(echo "$OUTPUT" | grep -oP 'Published (?:pre)?release v?\K[0-9.a-z.-]+' | head -n 1)
143+ if [[ -z "$VERSION" ]]; then
144+ VERSION=$(echo "$OUTPUT" | grep -oP 'The next release version is \K[0-9.a-z.-]+' | head -n 1)
145+ fi
146+
147+ if [[ -z "$VERSION" ]]; then
138148 echo "릴리즈할 새로운 버전이 없습니다. 배포를 건너뜁니다."
139- exit 0
149+ echo "HAS_VERSION=false" >> $GITHUB_OUTPUT
150+ else
151+ echo "새 버전($VERSION) 릴리즈가 감지되었습니다."
152+ echo "HAS_VERSION=true" >> $GITHUB_OUTPUT
153+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
154+ echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
140155 fi
141- echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
142156 env :
143157 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
144158
145159 - name : Set up JDK 21
160+ if : steps.get_version.outputs.HAS_VERSION == 'true'
146161 uses : actions/setup-java@v4
147162 with :
148163 distribution : ' temurin'
@@ -152,17 +167,14 @@ jobs:
152167 cache : ' gradle'
153168
154169 - name : Get TEST_JWT_SECRET_KEY from SSM
170+ if : steps.get_version.outputs.HAS_VERSION == 'true'
155171 id : get-test-secret
156172 run : |
157- SECRET_VALUE=$(aws ssm get-parameter \
158- --name "/common/TEST_JWT_SECRET_KEY" \
159- --with-decryption \
160- --region "${{ env.AWS_REGION }}" \
161- --query "Parameter.Value" \
162- --output text)
173+ SECRET_VALUE=$(aws ssm get-parameter --name "/common/TEST_JWT_SECRET_KEY" --with-decryption --region "${{ env.AWS_REGION }}" --query "Parameter.Value" --output text)
163174 echo "TEST_JWT_SECRET_KEY=$SECRET_VALUE" >> $GITHUB_ENV
164175
165176 - name : Build with Gradle
177+ if : steps.get_version.outputs.HAS_VERSION == 'true'
166178 run : |
167179 cd ${{ github.workspace }}
168180 chmod +x gradlew
@@ -171,12 +183,14 @@ jobs:
171183 TEST_JWT_SECRET_KEY : ${{ env.TEST_JWT_SECRET_KEY }}
172184
173185 - name : Login to Amazon ECR
186+ if : steps.get_version.outputs.HAS_VERSION == 'true'
174187 id : login-ecr
175188 uses : aws-actions/amazon-ecr-login@v2
176189 with :
177190 mask-password : ' true'
178191
179192 - name : Build, tag, and push image to Amazon ECR
193+ if : steps.get_version.outputs.HAS_VERSION == 'true'
180194 env :
181195 ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
182196 run : |
@@ -185,57 +199,95 @@ jobs:
185199 echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION" >> $GITHUB_ENV
186200
187201 - name : Get latest ECS task definition
202+ if : steps.get_version.outputs.HAS_VERSION == 'true'
188203 id : get-latest-task-def
189204 run : |
190- TASK_DEF_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --region "${{ env.AWS_REGION }}" -- query "services[0].taskDefinition" --output text)
191- aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" --region "${{ env.AWS_REGION }}" -- query "taskDefinition" --output json > task-definition.json
205+ TASK_DEF_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --query "services[0].taskDefinition" --output text)
206+ aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" --query "taskDefinition" --output json > task-definition.json
192207
193208 - name : Fill in the new image ID in the Amazon ECS task definition
209+ if : steps.get_version.outputs.HAS_VERSION == 'true'
194210 id : task-def
195211 uses : aws-actions/amazon-ecs-render-task-definition@v1
196212 with :
197213 task-definition : task-definition.json
198214 container-name : ${{ env.CONTAINER_NAME }}
199215 image : ${{ env.image }}
200216
201- - name : Deploy Amazon ECS task definition
217+ - name : Deploy Amazon ECS task definition and wait for stability
218+ if : steps.get_version.outputs.HAS_VERSION == 'true'
219+ id : deploy-ecs
202220 uses : aws-actions/amazon-ecs-deploy-task-definition@v2
203221 with :
204222 task-definition : ${{ steps.task-def.outputs.task-definition }}
205223 service : ${{ env.ECS_SERVICE }}
206224 cluster : ${{ env.ECS_CLUSTER }}
207225 wait-for-service-stability : true
208226
227+ - name : Verify deployment by comparing Task Definition ARNs
228+ if : steps.get_version.outputs.HAS_VERSION == 'true'
229+ run : |
230+ DEPLOYED_ARN="${{ steps.deploy-ecs.outputs.task-definition-arn }}"
231+ FINAL_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --query "services[0].taskDefinition" --output text)
232+
233+ echo "배포 시도 ARN: $DEPLOYED_ARN"
234+ echo "실제 적용된 ARN: $FINAL_ARN"
235+
236+ if [[ "$DEPLOYED_ARN" == "$FINAL_ARN" ]]; then
237+ echo "✅ 검증 성공. 서비스가 올바른 새 태스크 정의로 실행 중입니다."
238+ else
239+ echo "❌ 검증 실패. 롤백이 발생했습니다."
240+ echo "서비스가 다른 태스크 정의($FINAL_ARN)로 안정화되었습니다."
241+ exit 1 # 스크립트를 실패 처리하여 워크플로우 잡을 중단시킵니다.
242+ fi
243+
244+ notify :
245+ name : Send Discord Notification
246+ runs-on : ubuntu-latest
247+ needs : deploy-service
248+ if : always()
249+ steps :
209250 - name : Prepare Notification Info
210251 id : vars
211252 run : echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
212253
213254 - name : Discord Notify (Success)
214- if : success()
255+ if : needs.deploy-service.outputs.has_version == 'true' && needs.deploy-service.outputs.outcome == ' success'
215256216257 with :
217258 webhook-url : ${{ secrets.DISCORD_WEBHOOK }}
218259 embed-title : " ✅ 개발 서버 배포 성공!"
219260 embed-color : 65280
220261 embed-description : |
221262 새로운 버전이 성공적으로 배포되었습니다.
222-
223- **버전**: [v${{ env.SEMANTIC_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ env.SEMANTIC_VERSION }})
263+ **버전**: [v${{ needs.deploy-service.outputs.version }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ needs.deploy-service.outputs.version }})
224264 **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
225265 **배포자**: ${{ github.actor }}
226266 embed-url : " ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
227267
228268 - name : Discord Notify (Failure)
229- if : failure()
269+ if : needs.deploy-service.outputs.has_version == 'true' && needs.deploy-service.outputs.outcome == ' failure'
230270231271 with :
232272 webhook-url : ${{ secrets.DISCORD_WEBHOOK }}
233273 embed-title : " ❌ 개발 서버 배포 실패!"
234274 embed-color : 16711680
235275 embed-description : |
236- 배포 과정 중 오류가 발생했습니다. 아래 링크에서 로그를 확인하세요.
237-
238- **시도 버전**: ${{ env.SEMANTIC_VERSION }}
276+ 배포 과정 중 오류가 발생했거나 롤백되었습니다. 아래 링크에서 로그를 확인하세요.
277+ **시도 버전**: v${{ needs.deploy-service.outputs.version }}
278+ **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
279+ **요청자**: ${{ github.actor }}
280+ embed-url : " ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
281+
282+ - name : Discord Notify (No Version to Release)
283+ if : needs.deploy-service.outputs.has_version == 'false'
284+ 285+ with :
286+ webhook-url : ${{ secrets.DISCORD_WEBHOOK }}
287+ embed-title : " ℹ️ 개발 서버 배포 건너뜀"
288+ embed-color : 8421504
289+ embed-description : |
290+ 릴리즈할 새로운 버전이 없어 배포를 진행하지 않았습니다.
239291 **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
240292 **요청자**: ${{ github.actor }}
241293 embed-url : " ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
0 commit comments