CI:自动输出可视化测试报告(markdown 摘要 + JUnit XML + 自包含 HTML),并推送到 test-reports 分支
build-test-deploy / ci (push) Successful in 8m13s
build-test-deploy / ci (push) Successful in 8m13s
This commit is contained in:
+37
-6
@@ -77,19 +77,50 @@ jobs:
|
||||
- name: Build & test inside arm64 container
|
||||
timeout-minutes: 30
|
||||
run: |
|
||||
set -euo pipefail
|
||||
CID="h100-ci-test"
|
||||
docker rm -f "$CID" >/dev/null 2>&1 || true
|
||||
docker create --name "$CID" --platform linux/arm64 "$CI_IMAGE" /bin/sh -c 'sleep 7200' >/dev/null
|
||||
docker cp "$PWD/." "$CID:/src/"
|
||||
docker start "$CID" >/dev/null
|
||||
# Run build + tests (capture exit code, don't fail the step here so
|
||||
# we can still collect the report on failure)
|
||||
docker exec "$CID" /src/ci/build-test.sh
|
||||
mkdir -p bin
|
||||
docker cp "$CID:/src/bin/pPowerManger" bin/pPowerManger
|
||||
docker cp "$CID:/src/bin/pPMtest" bin/pPMtest
|
||||
docker cp "$CID:/src/bin/SQLiteTest" bin/SQLiteTest
|
||||
TEST_RC=$?
|
||||
mkdir -p bin reports
|
||||
docker cp "$CID:/src/bin/pPowerManger" bin/pPowerManger 2>/dev/null || true
|
||||
docker cp "$CID:/src/bin/pPMtest" bin/pPMtest 2>/dev/null || true
|
||||
docker cp "$CID:/src/bin/SQLiteTest" bin/SQLiteTest 2>/dev/null || true
|
||||
docker cp "$CID:/src/reports/." reports/ 2>/dev/null || true
|
||||
docker rm -f "$CID" >/dev/null 2>&1 || true
|
||||
ls -la bin/
|
||||
echo "--- bin/ ---"; ls -la bin/ 2>/dev/null || true
|
||||
echo "--- reports/ ---"; ls -la reports/ 2>/dev/null || true
|
||||
exit "$TEST_RC"
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Publish visual test report (runs even if tests failed)
|
||||
#-------------------------------------------------------------------
|
||||
- name: Publish test report
|
||||
if: always()
|
||||
run: |
|
||||
SUMMARY_FILE="${GITHUB_STEP_SUMMARY:-/tmp/step_summary.md}"
|
||||
if [ -f reports/test-report.md ]; then
|
||||
cat reports/test-report.md >> "$SUMMARY_FILE"
|
||||
else
|
||||
echo "## H100PowerManger CI" >> "$SUMMARY_FILE"
|
||||
echo "测试报告未生成(构建阶段失败)" >> "$SUMMARY_FILE"
|
||||
fi
|
||||
|
||||
# Persist reports to a dedicated branch (main push only)
|
||||
if [ "${GITHUB_REF:-}" = "refs/heads/main" ] && [ -d reports ]; then
|
||||
git config user.name "CI Bot"
|
||||
git config user.email "ci@localhost"
|
||||
git checkout --orphan test-reports >/dev/null 2>&1 || git checkout test-reports >/dev/null 2>&1 || true
|
||||
git rm -rf . >/dev/null 2>&1 || true
|
||||
cp -f reports/test-report.md reports/test-report.html reports/junit.xml . 2>/dev/null || true
|
||||
git add -A >/dev/null 2>&1 || true
|
||||
git commit -m "CI test report ${GITHUB_SHA:-}" >/dev/null 2>&1 || true
|
||||
git push -f origin test-reports >/dev/null 2>&1 || echo "WARN: failed to push test-reports branch"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Deploy the cross-built binary to the RK3588 board (push only)
|
||||
|
||||
@@ -250,3 +250,6 @@ bin/ccuState.txt
|
||||
bin/pPowerManger
|
||||
bin/SQLiteTest
|
||||
bin/pPMtest
|
||||
|
||||
# CI test reports
|
||||
reports/
|
||||
|
||||
+132
-32
@@ -1,14 +1,30 @@
|
||||
#!/bin/bash
|
||||
#=======================================================================
|
||||
# FILE: ci/build-test.sh
|
||||
# DESC: Build the project, run unit tests and a startup smoke test.
|
||||
# DESC: Build the project, run unit tests + a startup smoke test, and
|
||||
# generate a visual test report (markdown + junit.xml + html).
|
||||
# Executed INSIDE the aarch64 build container (ci/Dockerfile).
|
||||
#=======================================================================
|
||||
set -euo pipefail
|
||||
set -uo pipefail
|
||||
|
||||
SRC_DIR="${SRC_DIR:-/src}"
|
||||
cd "${SRC_DIR}"
|
||||
|
||||
REPORT_DIR="${SRC_DIR}/reports"
|
||||
mkdir -p "${REPORT_DIR}"
|
||||
|
||||
ARCH="$(uname -m)"
|
||||
COMMIT="${GITHUB_SHA:-unknown}"
|
||||
BUILD_DATE="$(date -u +'%Y-%m-%d %H:%M:%S UTC')"
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Result trackers
|
||||
#-----------------------------------------------------------------------
|
||||
BUILD_OK=0; SQLITE_OK=0; SMOKE_OK=0
|
||||
BUILD_TIME=0; SQLITE_TIME=0; SMOKE_TIME=0
|
||||
|
||||
now_ms() { date +%s; }
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# 1. Build
|
||||
#-----------------------------------------------------------------------
|
||||
@@ -16,37 +32,50 @@ echo ">>> Building (aarch64, Release)..."
|
||||
rm -rf build
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
make -j"$(nproc)"
|
||||
t0=$(now_ms)
|
||||
if cmake -DCMAKE_BUILD_TYPE=Release .. > /tmp/cmake.log 2>&1 \
|
||||
&& make -j"$(nproc)" > /tmp/make.log 2>&1; then
|
||||
BUILD_OK=1
|
||||
else
|
||||
echo "--- build failed ---" >&2
|
||||
tail -40 /tmp/make.log >&2
|
||||
fi
|
||||
BUILD_TIME=$(( $(now_ms) - t0 ))
|
||||
cd "${SRC_DIR}"
|
||||
|
||||
BIN_DIR="${SRC_DIR}/bin"
|
||||
if [ "${BUILD_OK}" = "1" ]; then
|
||||
echo ">>> Build artifacts:"
|
||||
ls -la "${BIN_DIR}"
|
||||
fi
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# 2. Unit test (SQLiteTest)
|
||||
#-----------------------------------------------------------------------
|
||||
if [ "${BUILD_OK}" = "1" ]; then
|
||||
echo ">>> Running unit test: SQLiteTest"
|
||||
"${BIN_DIR}/SQLiteTest"
|
||||
t0=$(now_ms)
|
||||
if "${BIN_DIR}/SQLiteTest" > /tmp/sqlitetest.log 2>&1; then
|
||||
SQLITE_OK=1
|
||||
echo ">>> SQLiteTest passed"
|
||||
else
|
||||
echo ">>> SQLiteTest FAILED" >&2
|
||||
tail -40 /tmp/sqlitetest.log >&2
|
||||
fi
|
||||
SQLITE_TIME=$(( $(now_ms) - t0 ))
|
||||
fi
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# 3. Startup smoke test: MOOSDB + pPowerManger liveness
|
||||
#-----------------------------------------------------------------------
|
||||
if [ "${BUILD_OK}" = "1" ]; then
|
||||
echo ">>> Smoke test: launch MOOSDB + pPowerManger"
|
||||
|
||||
# Locate MOOSDB (installed by MOOS build)
|
||||
MOOSDB="$(command -v MOOSDB || true)"
|
||||
if [ -z "${MOOSDB}" ]; then
|
||||
MOOSDB="$(ls /opt/moos-ivp/bin/MOOSDB 2>/dev/null || true)"
|
||||
fi
|
||||
if [ -z "${MOOSDB}" ] || [ ! -x "${MOOSDB}" ]; then
|
||||
echo "ERROR: MOOSDB not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Using MOOSDB: ${MOOSDB}"
|
||||
|
||||
# Minimal mission file for MOOSDB + pPowerManger
|
||||
MISSION_FILE="/tmp/smoke.moos"
|
||||
cat > "${MISSION_FILE}" <<EOF
|
||||
ServerHost = localhost
|
||||
@@ -63,36 +92,107 @@ ProcessConfig = pPowerManger
|
||||
EOF
|
||||
|
||||
cd "${BIN_DIR}"
|
||||
t0=$(now_ms)
|
||||
|
||||
echo ">>> Smoke diagnostics"
|
||||
getent protocols tcp >/dev/null 2>&1 && echo "getprotobyname(tcp) OK" || echo "getprotobyname(tcp) FAILED"
|
||||
getent hosts localhost >/dev/null 2>&1 && echo "gethostbyname(localhost) OK" || echo "gethostbyname(localhost) FAILED"
|
||||
echo "ulimit -n: $(ulimit -n)"
|
||||
|
||||
"${MOOSDB}" --moos_suicide_disable --moos_no_colour "${MISSION_FILE}" > /tmp/moosdb_smoke.log 2>&1 &
|
||||
"${MOOSDB}" --moos_suicide_disable --moos_no_colour "${MISSION_FILE}" \
|
||||
> /tmp/moosdb_smoke.log 2>&1 &
|
||||
MOOSDB_PID=$!
|
||||
sleep 3
|
||||
|
||||
if ! kill -0 "${MOOSDB_PID}" 2>/dev/null; then
|
||||
echo "--- MOOSDB crashed at startup; log: ---"
|
||||
cat /tmp/moosdb_smoke.log
|
||||
fi
|
||||
|
||||
./pPowerManger "${MISSION_FILE}" > /tmp/pm_smoke.log 2>&1 &
|
||||
PM_PID=$!
|
||||
sleep 5
|
||||
|
||||
if kill -0 "${PM_PID}" 2>/dev/null; then
|
||||
SMOKE_OK=1
|
||||
echo ">>> Smoke test PASSED (pPowerManger alive after 5s)"
|
||||
kill "${PM_PID}" "${MOOSDB_PID}" 2>/dev/null || true
|
||||
wait "${PM_PID}" "${MOOSDB_PID}" 2>/dev/null || true
|
||||
exit 0
|
||||
else
|
||||
echo ">>> Smoke test FAILED (pPowerManger exited)" >&2
|
||||
echo "--- pPowerManger log ---" >&2
|
||||
cat /tmp/pm_smoke.log >&2 || true
|
||||
echo "--- MOOSDB log ---" >&2
|
||||
cat /tmp/moosdb_smoke.log >&2 || true
|
||||
kill "${MOOSDB_PID}" 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill "${PM_PID}" "${MOOSDB_PID}" 2>/dev/null || true
|
||||
wait "${PM_PID}" "${MOOSDB_PID}" 2>/dev/null || true
|
||||
SMOKE_TIME=$(( $(now_ms) - t0 ))
|
||||
cd "${SRC_DIR}"
|
||||
fi
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# 4. Generate visual test report
|
||||
#-----------------------------------------------------------------------
|
||||
mark() { [ "$1" = "1" ] && echo "✅ 通过" || echo "❌ 失败"; }
|
||||
ALL_OK=0
|
||||
[ "${BUILD_OK}" = "1" ] && [ "${SQLITE_OK}" = "1" ] && [ "${SMOKE_OK}" = "1" ] && ALL_OK=1
|
||||
|
||||
# --- Markdown report ---
|
||||
cat > "${REPORT_DIR}/test-report.md" <<EOF
|
||||
## H100PowerManger CI 测试报告
|
||||
|
||||
| 步骤 | 结果 | 耗时 |
|
||||
| :--- | :--- | :--- |
|
||||
| 构建 (${ARCH}) | $(mark ${BUILD_OK}) | ${BUILD_TIME}s |
|
||||
| 单元测试 SQLiteTest | $(mark ${SQLITE_OK}) | ${SQLITE_TIME}s |
|
||||
| 冒烟测试 MOOSDB+pPowerManger | $(mark ${SMOKE_OK}) | ${SMOKE_TIME}s |
|
||||
|
||||
**总体结论: $([ "${ALL_OK}" = "1" ] && echo "✅ 全部通过" || echo "❌ 存在失败")**
|
||||
|
||||
- 架构: \`${ARCH}\`
|
||||
- Commit: \`${COMMIT}\`
|
||||
- 时间: ${BUILD_DATE}
|
||||
EOF
|
||||
|
||||
# --- JUnit XML report (for Gitea test-report rendering) ---
|
||||
cat > "${REPORT_DIR}/junit.xml" <<EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites name="H100PowerManger" tests="3" failures="$([ "${ALL_OK}" = "1" ] && echo 0 || echo 1)" time="$((BUILD_TIME+SQLITE_TIME+SMOKE_TIME))">
|
||||
<testsuite name="H100PowerManger CI" tests="3" failures="$([ "${ALL_OK}" = "1" ] && echo 0 || echo 1)" time="$((BUILD_TIME+SQLITE_TIME+SMOKE_TIME))">
|
||||
<testcase name="build_${ARCH}" classname="ci.build" time="${BUILD_TIME}">
|
||||
$([ "${BUILD_OK}" = "1" ] || echo "<failure message=\"build failed\"/>")
|
||||
</testcase>
|
||||
<testcase name="SQLiteTest" classname="ci.unit" time="${SQLITE_TIME}">
|
||||
$([ "${SQLITE_OK}" = "1" ] || echo "<failure message=\"SQLiteTest failed\"/>")
|
||||
</testcase>
|
||||
<testcase name="SmokeTest_MOOSDB_pPowerManger" classname="ci.smoke" time="${SMOKE_TIME}">
|
||||
$([ "${SMOKE_OK}" = "1" ] || echo "<failure message=\"smoke test failed\"/>")
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
EOF
|
||||
|
||||
# --- Self-contained HTML report ---
|
||||
status_html() {
|
||||
[ "$1" = "1" ] && echo '<span style="color:#1a7f37;font-weight:600">✔ PASS</span>' \
|
||||
|| echo '<span style="color:#cf222e;font-weight:600">✖ FAIL</span>'
|
||||
}
|
||||
cat > "${REPORT_DIR}/test-report.html" <<EOF
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN"><head><meta charset="utf-8"><title>H100PowerManger 测试报告</title>
|
||||
<style>
|
||||
body{font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;max-width:720px;margin:40px auto;color:#1f2328;line-height:1.6}
|
||||
h1{font-size:22px} h2{font-size:16px;border-bottom:1px solid #d0d7de;padding-bottom:6px}
|
||||
table{border-collapse:collapse;width:100%;margin:12px 0}
|
||||
th,td{border:1px solid #d0d7de;padding:8px 12px;text-align:left}
|
||||
th{background:#f6f8fa}
|
||||
.ok{background:#e6ffec} .fail{background:#ffebe9}
|
||||
.meta{color:#57606a;font-size:13px}
|
||||
.badge{display:inline-block;padding:4px 12px;border-radius:20px;font-weight:700}
|
||||
.badge.ok{background:#1a7f37;color:#fff} .badge.fail{background:#cf222e;color:#fff}
|
||||
</style></head><body>
|
||||
<h1>H100PowerManger CI 测试报告</h1>
|
||||
<p class="meta">架构 <code>${ARCH}</code> · Commit <code>${COMMIT}</code> · ${BUILD_DATE}</p>
|
||||
<p>$([ "${ALL_OK}" = "1" ] && echo '<span class="badge ok">全部通过</span>' || echo '<span class="badge fail">存在失败</span>')</p>
|
||||
<table>
|
||||
<tr><th>步骤</th><th>结果</th><th>耗时</th></tr>
|
||||
<tr class="$([ "${BUILD_OK}" = "1" ] && echo ok || echo fail)"><td>构建 (${ARCH})</td><td>$(status_html ${BUILD_OK})</td><td>${BUILD_TIME}s</td></tr>
|
||||
<tr class="$([ "${SQLITE_OK}" = "1" ] && echo ok || echo fail)"><td>单元测试 SQLiteTest</td><td>$(status_html ${SQLITE_OK})</td><td>${SQLITE_TIME}s</td></tr>
|
||||
<tr class="$([ "${SMOKE_OK}" = "1" ] && echo ok || echo fail)"><td>冒烟测试 MOOSDB+pPowerManger</td><td>$(status_html ${SMOKE_OK})</td><td>${SMOKE_TIME}s</td></tr>
|
||||
</table>
|
||||
</body></html>
|
||||
EOF
|
||||
|
||||
echo ">>> Reports generated in ${REPORT_DIR}:"
|
||||
ls -la "${REPORT_DIR}"
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# 5. Exit status
|
||||
#-----------------------------------------------------------------------
|
||||
[ "${ALL_OK}" = "1" ]
|
||||
|
||||
Reference in New Issue
Block a user