# Gitea Actions 集成示例 - 构建失败时自动上报到 Log Center # # 将以下步骤添加到你的 .gitea/workflows/deploy.yaml 中 # 放在可能失败的构建步骤之后 name: Build and Deploy on: push: branches: [main] env: LOG_CENTER_URL: https://qiyuan-log-center-api.airlabs.art jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 # ===== 你的构建步骤 ===== - name: Build Docker Image id: build run: | docker build -t myapp:latest . - name: Run Tests id: test run: | docker run myapp:latest python -m pytest # ===== 失败上报步骤 ===== - name: Report Build Failure if: failure() && steps.build.outcome == 'failure' run: | curl -s -X POST "${LOG_CENTER_URL}/api/v1/logs/report" \ -H "Content-Type: application/json" \ -d '{ "project_id": "'"${GITHUB_REPOSITORY##*/}"'", "environment": "cicd", "level": "ERROR", "source": "cicd", "commit_hash": "'"$GITHUB_SHA"'", "error": { "type": "DockerBuildError", "message": "Docker build failed", "file_path": null, "line_number": null, "stack_trace": ["Build step failed. Check CI logs for details."] }, "context": { "workflow_name": "'"$GITHUB_WORKFLOW"'", "job_name": "'"$GITHUB_JOB"'", "step_name": "Build Docker Image", "run_id": "'"$GITHUB_RUN_ID"'", "branch": "'"$GITHUB_REF_NAME"'", "repository": "'"$GITHUB_REPOSITORY"'" } }' --connect-timeout 5 --max-time 10 || true - name: Report Test Failure if: failure() && steps.test.outcome == 'failure' run: | curl -s -X POST "${LOG_CENTER_URL}/api/v1/logs/report" \ -H "Content-Type: application/json" \ -d '{ "project_id": "'"${GITHUB_REPOSITORY##*/}"'", "environment": "cicd", "level": "ERROR", "source": "cicd", "commit_hash": "'"$GITHUB_SHA"'", "error": { "type": "TestFailure", "message": "Tests failed in CI pipeline", "file_path": null, "line_number": null, "stack_trace": ["Test step failed. Check CI logs for details."] }, "context": { "workflow_name": "'"$GITHUB_WORKFLOW"'", "job_name": "'"$GITHUB_JOB"'", "step_name": "Run Tests", "run_id": "'"$GITHUB_RUN_ID"'", "branch": "'"$GITHUB_REF_NAME"'", "repository": "'"$GITHUB_REPOSITORY"'" } }' --connect-timeout 5 --max-time 10 || true