fix(cicd): capture actual build/deploy logs in failure report
All checks were successful
Build and Deploy Web / build-and-deploy (push) Successful in 3m0s

Replace docker/build-push-action with shell command + tee to capture
build logs. Failure step now includes actual error output in Log Center report.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
repair-agent 2026-02-24 13:33:05 +08:00
parent 784ca17072
commit b72b376fcd

View File

@ -28,12 +28,13 @@ jobs:
password: ${{ secrets.SWR_PASSWORD }}
- name: Build and Push Web
uses: docker/build-push-action@v4
with:
context: .
push: true
provenance: false
tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest
run: |
docker buildx build \
--push \
--provenance=false \
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest \
. 2>&1 | tee /tmp/build.log
exit ${PIPESTATUS[0]}
- name: Setup Kubectl
run: |
@ -54,29 +55,49 @@ jobs:
echo "Environment: Production"
DEPLOY_FILE="k8s/web-deployment-prod.yaml"
INGRESS_FILE="k8s/ingress.yaml"
RESTART_NAME="rtc-web"
else
echo "Environment: Development"
DEPLOY_FILE="k8s/web-deployment-dev.yaml"
INGRESS_FILE="k8s/ingress-dev.yaml"
RESTART_NAME="rtc-web-dev"
fi
# 2. 替换镜像地址
sed -i "s|\${CI_REGISTRY_IMAGE}/web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest|g" $DEPLOY_FILE
# 3. 应用配置
# 3. 应用配置并捕获输出
{
kubectl apply -f $DEPLOY_FILE
kubectl apply -f $INGRESS_FILE
# 4. 根据分支重启对应服务
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
kubectl rollout restart deployment/rtc-web
else
kubectl rollout restart deployment/rtc-web-dev
fi
kubectl rollout restart deployment/$RESTART_NAME
} 2>&1 | tee /tmp/deploy.log
- name: Report failure to Log Center
if: failure()
run: |
BUILD_LOG=""
DEPLOY_LOG=""
FAILED_STEP="unknown"
if [ -f /tmp/build.log ]; then
BUILD_LOG=$(tail -50 /tmp/build.log | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
FAILED_STEP="build"
fi
if [ -f /tmp/deploy.log ]; then
DEPLOY_LOG=$(tail -50 /tmp/deploy.log | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
if [ -n "$DEPLOY_LOG" ]; then
FAILED_STEP="deploy"
fi
fi
if [ -z "$BUILD_LOG" ] && [ -z "$DEPLOY_LOG" ]; then
BUILD_LOG="No captured output. Check Gitea Actions UI for details."
FAILED_STEP="pre-build"
fi
ERROR_LOG="${BUILD_LOG}${DEPLOY_LOG}"
curl -s -X POST "https://qiyuan-log-center-api.airlabs.art/api/v1/logs/report" \
-H "Content-Type: application/json" \
-d "{
@ -88,19 +109,15 @@ jobs:
\"repo_url\": \"https://gitea.airlabs.art/zyc/rtc_web.git\",
\"error\": {
\"type\": \"CICDFailure\",
\"message\": \"Build and Deploy failed on branch ${{ github.ref_name }}\",
\"stack_trace\": [
\"Repository: ${{ github.repository }}\",
\"Branch: ${{ github.ref_name }}\",
\"Commit: ${{ github.sha }}\",
\"Run ID: ${{ github.run_id }}\",
\"Actor: ${{ github.actor }}\"
]
\"message\": \"[${FAILED_STEP}] Build and Deploy failed on branch ${{ github.ref_name }}\",
\"stack_trace\": [\"${ERROR_LOG}\"]
},
\"context\": {
\"workflow\": \"${{ github.workflow }}\",
\"run_id\": \"${{ github.run_id }}\",
\"branch\": \"${{ github.ref_name }}\",
\"actor\": \"${{ github.actor }}\"
\"actor\": \"${{ github.actor }}\",
\"failed_step\": \"${FAILED_STEP}\",
\"commit\": \"${{ github.sha }}\"
}
}" || true