Skip to content

Commit

Permalink
feat: improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
printSANO committed Nov 9, 2024
1 parent c5b1aae commit 6c65e8b
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,62 @@ jobs:
run: |
echo "Image tag = ${{ github.event.inputs.image_tag }}"
echo "Image name = ${{ github.event.inputs.image_name }}"
echo "Replicas = ${{ github.event.inputs.replicas }}"
echo "Replicas = ${{ github.event.inputs.replicas }}"
- name: Test Success and Failures
id: test
run: |
if [ ${{ github.event.inputs.replicas }} != "3" ]; then
echo "Test Step succeeded"
else
echo "Test Step failed. 테스트중"
exit 1
fi
- name: Capture First Failure Details
if: always()
run: |
if [ "${{ steps.test.outcome }}" == "failure" ]; then
echo "FAILED_STEP=Test Step" >> $GITHUB_ENV
echo "FAILED_LOGS=${{ steps.step1.outcome }}" >> $GITHUB_ENV
elif [ "${{ steps.step2.outcome }}" == "failure" ]; then
echo "FAILED_STEP=Step 2" >> $GITHUB_ENV
echo "FAILED_LOGS=${{ steps.step2.outcome }}" >> $GITHUB_ENV
elif [ "${{ steps.step3.outcome }}" == "failure" ]; then
echo "FAILED_STEP=Step 3" >> $GITHUB_ENV
echo "FAILED_LOGS=${{ steps.step3.outcome }}" >> $GITHUB_ENV
fi
- name: Final Message To Slack
if: always()
env:
IMAGE_NAME: ${{ github.event.inputs.image_name }}
DOCKER_IMAGE_TAG: ${{ github.event.inputs.image_tag }}
SLACK_SECRET: ${{ secrets.SLACK_DEPLOY_SECRET }}
run: |
if [ "$FAILED_STEP" != "" ]; then
echo "The step '$FAILED_STEP' failed."
curl -X POST https://techeer-029051b54345.herokuapp.com/api/v1/deploy/status \
-H "Content-Type: application/json" \
-d '{
"status": "failed",
"imageName": "'"$IMAGE_NAME"'",
"imageTag": "'"$DOCKER_IMAGE_TAG"'",
"failedStep": "'"$FAILED_STEP"'",
"logs": "'"$FAILED_LOGS"'",
"secret": "'"$SLACK_SECRET"'"
"jobURL": "'"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'"
}'
else
echo "All steps succeeded!"
curl -X POST https://techeer-029051b54345.herokuapp.com/api/v1/deploy/status \
-H "Content-Type: application/json" \
-d '{
"status": "success",
"imageName": "'"$IMAGE_NAME"'",
"imageTag": "'"$DOCKER_IMAGE_TAG"'",
"failedStep": "'"$FAILED_STEP"'",
"logs": "'"$FAILED_LOGS"'",
"secret": "'"$SLACK_SECRET"'"
"jobURL": "'"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'"
}'

0 comments on commit 6c65e8b

Please sign in to comment.