一、整体思路
二、本地代码分析方案
实现效果:
具体实现:
第一步:准备工作
OCLint: 22.02
XCode: 13.4.1
xpretty: 0.3.0
第二步:进入项目dapp根目录执行如下脚本
检查脚本:
#!/bin/bash
# author:gegaozhao
export LC_ALL=en_US.UTF-8
#核心扫描代码
codeDetector(){
...
#清理&&编译&&生成compile_commands.json
xcodebuild -scheme $schemeName clean
#编译生成编译日志给xcpretty 2.xcpretty根据编译日志生成compile_commands.json文件
xcodebuild -scheme $schemeName -sdk iphonesimulator15.5 \
ENABLE_BITCODE=NO COMPILER_INDEX_STORE_ENABLE=NO | \
xcpretty -r json-compilation-database -o compile_commands.json
#oclint消费compile_commands.json文件生成检测结果html文件
if [ ! -f "./compile_commands.json" ]; then
echo "compile_commands.json文件生成失败,终止后续逻辑!"
exit 1
fi
#生成报告
oclint-json-compilation-database -e Pods -- -report-type html -o $productFilePath \
-rc LONG_LINE=200 -max-priority-1=100000 -max-priority-2=100000 -max-priority-3=100000
...
}
uploadReport(){
...
#将报告上传到远程仓库
scp -P 56358 -r $reportPath root@xxx.xxx.x.xxx:/zzz/zzz/zzz/zzz
...
}
messagePush(){
...
飞书群推送
...
}
三、gitlab-ci.yml文件配置
stages:
- codeLint
ocLint-push:
stage: codeLint
script:
- sh ./xxx.sh
tags:
- lab1 #指定runner
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME == "发布分支" && $CI_COMMIT_BEFORE_SHA != "0000000000000000000000000000000000000000"
ocLint-merge:
stage: codeLint
script:
- sh ./xxx.sh
tags:
- lab1 #指定runner
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_REF_NAME == "发布分支" && $CI_MERGE_REQUEST_DIFF_BASE_SHA