diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40ddbba..cb9b50d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,17 +43,31 @@ jobs: - name: 安装依赖 run: npm ci + # 下载完整日志需要仓库管理员权限,失败详情转成注解才能在提交页直接看到 - name: 单元测试 - run: npm test + shell: bash + run: | + set -o pipefail + npm test 2>&1 | tee /tmp/unit.log && exit 0 + echo "::error title=单元测试失败::$(grep -A 15 '^not ok' /tmp/unit.log \ + | head -150 | sed 's/%/%25/g; s/\r//g' | awk '{printf "%s%%0A", $0}')" + exit 1 # Electron 集成测试要开真实窗口,无头环境靠 xvfb 提供 X server - name: Electron 集成测试 + shell: bash run: | + set -o pipefail sudo apt-get update sudo apt-get install -y xvfb libnss3 libatk1.0-0t64 libatk-bridge2.0-0t64 libcups2t64 libgbm1 libasound2t64 libgtk-3-0t64 for suite in startup download cover annotation reader-features library-notes ai-scope; do echo "::group::$suite" - xvfb-run -a npx electron "src/_test/electron/$suite.integration.js" + if ! xvfb-run -a npx electron "src/_test/electron/$suite.integration.js" 2>&1 | tee "/tmp/$suite.log"; then + echo "::endgroup::" + echo "::error title=集成测试失败 $suite::$(grep -iE 'FAIL|Error|失败' "/tmp/$suite.log" \ + | head -60 | sed 's/%/%25/g; s/\r//g' | awk '{printf "%s%%0A", $0}')" + exit 1 + fi echo "::endgroup::" done