fix(cicd): capture actual build/deploy logs in failure report
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m14s
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 1m14s
Replace docker/build-push-action with shell command to capture stdout/stderr. Include real error output in Log Center report so repair agent can diagnose CI/CD failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7603b15ffb
commit
ebe555216b
@ -28,12 +28,15 @@ jobs:
|
|||||||
password: ${{ secrets.SWR_PASSWORD }}
|
password: ${{ secrets.SWR_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and Push Backend
|
- name: Build and Push Backend
|
||||||
uses: docker/build-push-action@v4
|
id: build
|
||||||
with:
|
run: |
|
||||||
context: .
|
docker buildx build \
|
||||||
push: true
|
--push \
|
||||||
provenance: false
|
--provenance=false \
|
||||||
tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-backend:latest
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-backend:latest \
|
||||||
|
. 2>&1 | tee /tmp/build.log
|
||||||
|
echo "build_exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
|
||||||
|
exit ${PIPESTATUS[0]}
|
||||||
|
|
||||||
- name: Setup Kubectl
|
- name: Setup Kubectl
|
||||||
run: |
|
run: |
|
||||||
@ -48,6 +51,7 @@ jobs:
|
|||||||
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
|
||||||
- name: Update K8s Manifests
|
- name: Update K8s Manifests
|
||||||
|
id: deploy
|
||||||
run: |
|
run: |
|
||||||
# 1. 判断分支,决定使用哪个配置文件
|
# 1. 判断分支,决定使用哪个配置文件
|
||||||
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
|
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
|
||||||
@ -65,15 +69,40 @@ jobs:
|
|||||||
# 2. 替换镜像地址
|
# 2. 替换镜像地址
|
||||||
sed -i "s|\${CI_REGISTRY_IMAGE}/backend:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-backend:latest|g" $DEPLOY_FILE
|
sed -i "s|\${CI_REGISTRY_IMAGE}/backend:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-backend:latest|g" $DEPLOY_FILE
|
||||||
|
|
||||||
# 3. 应用配置
|
# 3. 应用配置并捕获输出
|
||||||
|
{
|
||||||
kubectl apply -f $DEPLOY_FILE
|
kubectl apply -f $DEPLOY_FILE
|
||||||
kubectl apply -f $INGRESS_FILE
|
kubectl apply -f $INGRESS_FILE
|
||||||
|
|
||||||
kubectl rollout restart deployment/$DEPLOY_NAME
|
kubectl rollout restart deployment/$DEPLOY_NAME
|
||||||
|
} 2>&1 | tee /tmp/deploy.log
|
||||||
|
|
||||||
- name: Report failure to Log Center
|
- name: Report failure to Log Center
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
|
# 收集构建和部署日志(取最后 50 行)
|
||||||
|
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
|
||||||
|
|
||||||
|
# 如果构建日志为空(action 级别失败),标记步骤
|
||||||
|
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" \
|
curl -s -X POST "https://qiyuan-log-center-api.airlabs.art/api/v1/logs/report" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{
|
-d "{
|
||||||
@ -85,19 +114,15 @@ jobs:
|
|||||||
\"repo_url\": \"https://gitea.airlabs.art/zyc/rtc_backend.git\",
|
\"repo_url\": \"https://gitea.airlabs.art/zyc/rtc_backend.git\",
|
||||||
\"error\": {
|
\"error\": {
|
||||||
\"type\": \"CICDFailure\",
|
\"type\": \"CICDFailure\",
|
||||||
\"message\": \"Build and Deploy failed on branch ${{ github.ref_name }}\",
|
\"message\": \"[${FAILED_STEP}] Build and Deploy failed on branch ${{ github.ref_name }}\",
|
||||||
\"stack_trace\": [
|
\"stack_trace\": [\"${ERROR_LOG}\"]
|
||||||
\"Repository: ${{ github.repository }}\",
|
|
||||||
\"Branch: ${{ github.ref_name }}\",
|
|
||||||
\"Commit: ${{ github.sha }}\",
|
|
||||||
\"Run ID: ${{ github.run_id }}\",
|
|
||||||
\"Actor: ${{ github.actor }}\"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
\"context\": {
|
\"context\": {
|
||||||
\"workflow\": \"${{ github.workflow }}\",
|
\"workflow\": \"${{ github.workflow }}\",
|
||||||
\"run_id\": \"${{ github.run_id }}\",
|
\"run_id\": \"${{ github.run_id }}\",
|
||||||
\"branch\": \"${{ github.ref_name }}\",
|
\"branch\": \"${{ github.ref_name }}\",
|
||||||
\"actor\": \"${{ github.actor }}\"
|
\"actor\": \"${{ github.actor }}\",
|
||||||
|
\"failed_step\": \"${FAILED_STEP}\",
|
||||||
|
\"commit\": \"${{ github.sha }}\"
|
||||||
}
|
}
|
||||||
}" || true
|
}" || true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user