Travis配置phpcs仅用于当前提交文件

时间:2018-05-02 06:42:18

标签: php continuous-integration travis-ci devops cd

我在travis中配置phpcs。为了在使用travis CI的提交推送中检查PHP代码标准。

我正在使用以下脚本

script:
- phpcs --standard=PSR2  $(find ./ -name
  '*.php')

但是此脚本会检查每个.php文件并对所有文件运行测试。 我需要travis应该只为当前提交的文件运行phpcs命令。

你对这种情况有什么解决方案吗?提前谢谢。

1 个答案:

答案 0 :(得分:2)

您可以尝试以下内容:

获取最后一次提交ID:(How to get the last commit ID of a remote repo using curl-like command?

git log --format="%H" -n 1

然后在最后一次提交中获取文件:(How to list all the files in a commit?

git diff-tree --no-commit-id --name-only -r `git log --format="%H" -n 1`

您可以在此处看到以前的命令。 backtits之前的第一部分需要一个提交id来列出文件。使用第一个命令找到此提交ID。

然后,如果你只想要php文件,你可以使用grep:

git diff-tree --no-commit-id --name-only -r `git log --format="%H" -n 1` | grep .php

在我的一个php项目上输出:

app/Http/Controllers/BarterController.php
app/Http/Controllers/HomeController.php
app/Talk.php
resources/views/profiles/index.blade.php
resources/views/talks/show-comments.blade.php

只需将您的命令$(find ./ -name '*.php')替换为我上面给出的命令,它应该可以正常工作。您的命令将变为以下内容:

phpcs --standard=PSR2 $(git diff-tree --no-commit-id --name-only -r `git log --format="%H" -n 1` | grep .php)
相关问题