使静态分析失败导致Travis构建失败

Zev*_*erg 6 xcode continuous-integration static-analysis travis-ci

我有一个基于Travis CI的Objective-C iOS库.我刚刚在我的.travis.yml文件中启用了静态分析,它发现了一个问题(一个死的存储),但它并没有使Travis的构建失败.这是我的相关行.travis.yml(为了可读性而换行):

- set -o pipefail && xcodebuild analyze
    -workspace Example/BonMot.xcworkspace
    -scheme BonMot-Example
    -destination 'name=iPhone 6' ONLY_ACTIVE_ARCH=NO | xcpretty
Run Code Online (Sandbox Code Playgroud)

我需要做什么才能在此行中发出警告以使Travis CI上的构建失败?您可以在此处查看我项目中的相关拉取请求.

Rob*_*ert 6

我可以使它起作用的唯一方法是使用此处详述的方法

将这两个参数添加到您的xcodebuildor scan -x命令中

CLANG_ANALYZER_OUTPUT=plist-html \
CLANG_ANALYZER_OUTPUT_DIR="$(pwd)/clang"
Run Code Online (Sandbox Code Playgroud)

如果有叮当警告,这将产生一个HTML文件。因此,请检查该文件是否存在。

if [[ -z `find clang -name "*.html"` ]]; then
    echo "Static Analyzer found no issues"
else
    echo "Static Analyzer found some issues"
    exit 123
fi
Run Code Online (Sandbox Code Playgroud)


Zev*_*erg 1

在这篇博文的帮助下,我设法找到了一种方法来完成这项工作。以下是示例文件的相关部分.travis.yml

language: objective-c
rvm:
 - 2.2.4
osx_image: xcode7.3
install:
 - gem install xcpretty --no-rdoc --no-ri --no-document --quiet
 - export PYTHONUSERBASE=~/.local
 - easy_install --user scan-build
script:
 # use scan-build with --status-bugs to fail the build for static analysis warnings per http://jonboydell.blogspot.ca/2013/02/clang-static-analysis.html
 - export PATH="${HOME}/.local/bin:${PATH}" # I forget whether this was necessary. Try omitting it and see what happens!
 - set -o pipefail && scan-build --status-bugs xcodebuild analyze -workspace MyWorkspace.xcworkspace -scheme MyScheme -destination 'name=iPhone 6' ONLY_ACTIVE_ARCH=NO | xcpretty
Run Code Online (Sandbox Code Playgroud)