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,23 @@ 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
138144 echo "릴리즈할 새로운 버전이 없습니다. 배포를 건너뜁니다."
139- exit 0
145+ echo "HAS_VERSION=false" >> $GITHUB_OUTPUT
146+ else
147+ echo "새 버전($VERSION) 릴리즈가 감지되었습니다."
148+ echo "HAS_VERSION=true" >> $GITHUB_OUTPUT
149+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
150+ echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
140151 fi
141- echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
142152 env :
143153 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
144154
145155 - name : Set up JDK 21
156+ if : steps.get_version.outputs.HAS_VERSION == 'true'
146157 uses : actions/setup-java@v4
147158 with :
148159 distribution : ' temurin'
@@ -152,17 +163,14 @@ jobs:
152163 cache : ' gradle'
153164
154165 - name : Get TEST_JWT_SECRET_KEY from SSM
166+ if : steps.get_version.outputs.HAS_VERSION == 'true'
155167 id : get-test-secret
156168 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)
169+ SECRET_VALUE=$(aws ssm get-parameter --name "/common/TEST_JWT_SECRET_KEY" --with-decryption --region "${{ env.AWS_REGION }}" --query "Parameter.Value" --output text)
163170 echo "TEST_JWT_SECRET_KEY=$SECRET_VALUE" >> $GITHUB_ENV
164171
165172 - name : Build with Gradle
173+ if : steps.get_version.outputs.HAS_VERSION == 'true'
166174 run : |
167175 cd ${{ github.workspace }}
168176 chmod +x gradlew
@@ -171,12 +179,14 @@ jobs:
171179 TEST_JWT_SECRET_KEY : ${{ env.TEST_JWT_SECRET_KEY }}
172180
173181 - name : Login to Amazon ECR
182+ if : steps.get_version.outputs.HAS_VERSION == 'true'
174183 id : login-ecr
175184 uses : aws-actions/amazon-ecr-login@v2
176185 with :
177186 mask-password : ' true'
178187
179188 - name : Build, tag, and push image to Amazon ECR
189+ if : steps.get_version.outputs.HAS_VERSION == 'true'
180190 env :
181191 ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
182192 run : |
@@ -185,57 +195,95 @@ jobs:
185195 echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION" >> $GITHUB_ENV
186196
187197 - name : Get latest ECS task definition
198+ if : steps.get_version.outputs.HAS_VERSION == 'true'
188199 id : get-latest-task-def
189200 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
201+ TASK_DEF_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --query "services[0].taskDefinition" --output text)
202+ aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" --query "taskDefinition" --output json > task-definition.json
192203
193204 - name : Fill in the new image ID in the Amazon ECS task definition
205+ if : steps.get_version.outputs.HAS_VERSION == 'true'
194206 id : task-def
195207 uses : aws-actions/amazon-ecs-render-task-definition@v1
196208 with :
197209 task-definition : task-definition.json
198210 container-name : ${{ env.CONTAINER_NAME }}
199211 image : ${{ env.image }}
200212
201- - name : Deploy Amazon ECS task definition
213+ - name : Deploy Amazon ECS task definition and wait for stability
214+ if : steps.get_version.outputs.HAS_VERSION == 'true'
215+ id : deploy-ecs
202216 uses : aws-actions/amazon-ecs-deploy-task-definition@v2
203217 with :
204218 task-definition : ${{ steps.task-def.outputs.task-definition }}
205219 service : ${{ env.ECS_SERVICE }}
206220 cluster : ${{ env.ECS_CLUSTER }}
207221 wait-for-service-stability : true
208222
223+ - name : Verify deployment by comparing Task Definition ARNs
224+ if : steps.get_version.outputs.HAS_VERSION == 'true'
225+ run : |
226+ DEPLOYED_ARN="${{ steps.deploy-ecs.outputs.task-definition-arn }}"
227+ FINAL_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --query "services[0].taskDefinition" --output text)
228+
229+ echo "배포 시도 ARN: $DEPLOYED_ARN"
230+ echo "실제 적용된 ARN: $FINAL_ARN"
231+
232+ if [[ "$DEPLOYED_ARN" == "$FINAL_ARN" ]]; then
233+ echo "✅ 검증 성공. 서비스가 올바른 새 태스크 정의로 실행 중입니다."
234+ else
235+ echo "❌ 검증 실패. 롤백이 발생했습니다."
236+ echo "서비스가 다른 태스크 정의($FINAL_ARN)로 안정화되었습니다."
237+ exit 1 # 스크립트를 실패 처리하여 워크플로우 잡을 중단시킵니다.
238+ fi
239+
240+ notify :
241+ name : Send Discord Notification
242+ runs-on : ubuntu-latest
243+ needs : deploy-service
244+ if : always()
245+ steps :
209246 - name : Prepare Notification Info
210247 id : vars
211248 run : echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
212249
213250 - name : Discord Notify (Success)
214- if : success()
251+ if : needs.deploy-service.outputs.has_version == 'true' && needs.deploy-service.outputs.outcome == ' success'
215252216253 with :
217254 webhook-url : ${{ secrets.DISCORD_WEBHOOK }}
218255 embed-title : " ✅ 개발 서버 배포 성공!"
219256 embed-color : 65280
220257 embed-description : |
221258 새로운 버전이 성공적으로 배포되었습니다.
222-
223- **버전**: [v${{ env.SEMANTIC_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ env.SEMANTIC_VERSION }})
259+ **버전**: [v${{ needs.deploy-service.outputs.version }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ needs.deploy-service.outputs.version }})
224260 **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
225261 **배포자**: ${{ github.actor }}
226262 embed-url : " ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
227263
228264 - name : Discord Notify (Failure)
229- if : failure()
265+ if : needs.deploy-service.outputs.has_version == 'true' && needs.deploy-service.outputs.outcome == ' failure'
230266231267 with :
232268 webhook-url : ${{ secrets.DISCORD_WEBHOOK }}
233269 embed-title : " ❌ 개발 서버 배포 실패!"
234270 embed-color : 16711680
235271 embed-description : |
236- 배포 과정 중 오류가 발생했습니다. 아래 링크에서 로그를 확인하세요.
237-
238- **시도 버전**: ${{ env.SEMANTIC_VERSION }}
272+ 배포 과정 중 오류가 발생했거나 롤백되었습니다. 아래 링크에서 로그를 확인하세요.
273+ **시도 버전**: v${{ needs.deploy-service.outputs.version }}
274+ **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
275+ **요청자**: ${{ github.actor }}
276+ embed-url : " ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
277+
278+ - name : Discord Notify (No Version to Release)
279+ if : needs.deploy-service.outputs.has_version == 'false'
280+ 281+ with :
282+ webhook-url : ${{ secrets.DISCORD_WEBHOOK }}
283+ embed-title : " ℹ️ 개발 서버 배포 건너뜀"
284+ embed-color : 8421504
285+ embed-description : |
286+ 릴리즈할 새로운 버전이 없어 배포를 진행하지 않았습니다.
239287 **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
240288 **요청자**: ${{ github.actor }}
241289 embed-url : " ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
0 commit comments