我正在使用 Jenkins 并为 merge 请求执行 PHPMD、PHPCS 和 PHP lint 检查。我们所拥有的基本上是每个功能的单独分支,如果它通过检查和测试,它应该再次 merge 到 master 分支。
我们正在使用此命令检查项目中的所有 php 文件:
echo "php syntax checks are started"
find ./ -type f -name \*.php -exec php -l '{}' \; | grep -v "No syntax errors detected" && echo "PHP Syntax error(s) detected" && exit 1;
对所有 php 文件使用“php -l”大约需要几分钟。
我想知道是否有办法加快速度并提出解决方案。请检查下面我的回答。
最佳答案
考虑到只有少数 php 文件会被更改,这只需要几秒钟。
echo "php syntax checks for only changed files"
( ( (git diff --name-only origin/master $GIT_COMMIT ) | grep .php$ ) | xargs -n1 echo php -l | bash ) | grep -v "No syntax errors detected" && echo "PHP Syntax error(s) detected" && exit 1;
如果你在 Jenkins 中使用 git 插件,你可以保留 $GIT_COMMIT 否则用提交号或分支名称更改它。
这也可以用于 css 和 js lints。根据您的需要更改“php -l”部分。
关于php - 如何仅对分支中已更改的文件进行 lint 或静态分析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44819412/