From 6c17acf8ff95f088018f552ebe5d32e80e275985 Mon Sep 17 00:00:00 2001 From: ksee1230 Date: Thu, 19 Jun 2025 16:34:10 +0900 Subject: [PATCH] =?UTF-8?q?ci:=20CI=20=EC=84=A4=EC=A0=95=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-cd.yml | 84 +++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 1c9e77f..cf72102 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,4 +1,4 @@ -name: CI/CD Pipeline with Dual Approval Gates +name: CI/CD Pipeline for frontend-service on: push: @@ -66,40 +66,41 @@ jobs: with: name: build-log-${{ needs.build.outputs.version_tag }} - # ▼▼▼ [1단계] 로그를 필터링하여 보낼 메시지를 준비하는 단계 ▼▼▼ - - name: Prepare Notification Message - id: prepare_message # 이 스텝의 출력을 참조하기 위해 id 지정 + - name: Send Discord Notification with Correctly Formatted Log run: | + # 1. 이전과 같이 로그에서 문제 라인을 필터링합니다. KEYWORDS="error|failed|warning|deprecated" LOG_ISSUES=$(grep -i -E -C 2 "$KEYWORDS" build_log.txt || true) + # 2. 결과에 따라 요약 메시지를 준비합니다. if [[ -z "$LOG_ISSUES" ]]; then - SUMMARY="✅ 빌드 로그에서 특별한 경고나 에러가 발견되지 않았습니다." + SUMMARY_CONTENT="✅ 빌드 로그에서 특별한 경고나 에러가 발견되지 않았습니다." else - TRUNCATED_LOGS=$(echo "$LOG_ISSUES" | head -c 1500) - SUMMARY="⚠️ 빌드 로그에서 잠재적인 문제가 발견되었습니다. 아래 요약을 확인해주세요.\\n\\n**Log Issues Summary:**\\n\`\`\`\\n${TRUNCATED_LOGS}\\n\`\`\`" + # JSON에 넣기 전에 " 와 \ 문자만 이스케이프 처리합니다. (줄바꿈 \n은 처리하지 않음) + ESCAPED_LOGS=$(echo "$LOG_ISSUES" | head -c 1500 | sed 's/\\/\\\\/g' | sed 's/"/\\"/g') + SUMMARY_CONTENT="⚠️ 빌드 로그에서 잠재적인 문제가 발견되었습니다. 아래 요약을 확인해주세요.\n\n**Log Issues Summary:**\n\`\`\`\n${ESCAPED_LOGS}\n\`\`\`" fi - # 다음 스텝에서 사용할 수 있도록 summary 내용을 output으로 설정 - # EOF를 사용하여 여러 줄의 문자열을 안정적으로 전달 - { - echo "summary<> "$GITHUB_OUTPUT" + # 3. 최종 description 내용을 만듭니다. + FINAL_DESCRIPTION="${SUMMARY_CONTENT}\n\n[➡️ 전체 로그 및 승인 페이지로 이동](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" - # ▼▼▼ [2단계] 준비된 메시지를 담아 Discord 알림을 보내는 단계 ▼▼▼ - - name: Send Discord Notification for ECR Push Approval - uses: sarisia/actions-status-discord@v1 - with: - webhook: ${{ secrets.DISCORD_WEBHOOK_URL }} - title: "🔎 [1차 승인] ECR Push 승인 요청: ${{ needs.build.outputs.version_tag }}" - # description에 바로 앞 스텝의 'summary' output을 사용 - description: | - ${{ steps.prepare_message.outputs.summary }} - - [➡️ 전체 로그 및 승인 페이지로 이동](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - color: 49151 # 16진수 0x00BFFF + # 4. JSON에 넣기 위해 다시 한번 전체 description의 특수문자를 이스케이프 합니다. + JSON_FRIENDLY_DESCRIPTION=$(echo "$FINAL_DESCRIPTION" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g') + + # 5. heredoc을 사용하여 JSON 페이로드를 생성하고 curl로 바로 전송합니다. + curl -X POST -H "Content-Type: application/json" \ + -d @- \ + "${{ secrets.DISCORD_WEBHOOK_URL }}" <