为什么静态分析器问题不会使我的 CI 构建失败?

Why are static analyzer issues not failing my CI build?

我有一个项目on GitHub with an automated build on Travis CI。我的代码的当前修订版(buildfix 分支,提交 3ebc41a8b4738bce926b39cc3869c6dce8bed9bc)正在成功,即使我有一个静态分析器问题。这是 xcodebuild 命令:

xcodebuild -workspace UnrarKit.xcworkspace -scheme UnrarKit -sdk macosx -configuration Release analyze test

我还为整个项目(对于发布版本)将 "Treat Warnings as Errors" 设置为 YES。我从 xcodebuild:

得到这个输出
The following commands produced analyzer issues:
  Analyze Classes/URKArchive.mm
(1 command with analyzer issues)

我在我的本地终端中用 xcodebuild 复制了这个,结果相同。

为什么 xcodebuild 仍然 return 0 并允许我的构建成功?如果结果不能使用,为什么要让 xcodebuild 首先进行分析?如果它是一个错误,我会向 Apple 提交它,但目前我对我做错事的可能性持开放态度。

我认为这是 return 0 的预期行为。毕竟最后一条日志是 ** 分析成功 **。 您可以使用

获得 html 报告
xcodebuild -workspace UnrarKit.xcworkspace -scheme UnrarKit -sdk macosx -configuration Release analyze test CLANG_ANALYZER_OUTPUT=html CLANG_ANALYZER_OUTPUT_DIR=analyzer
find analyzer -name *.html

我也在想办法让它 return 不是 0,我唯一想到的是:

xcodebuild analyze ... && [[ -z `find analyzer -name "*.html"` ]]

对于 Gitlab CI/CD,我使用以下 bash 语句实现了类似的功能:

echo "failOnWarnings" | exit `find analyzer -name "*.html" -print -quit | wc -l`

如果 analyzer 文件夹中有任何 html 文件,退出代码将为 1(表示失败),否则退出代码将为 0(表示成功) .

它在 GitLab MacOS runner 11.11.3 (darwin/amd64) 上测试并且有效。 \o/