【发布时间】:2018-11-17 08:54:14
【问题描述】:
如何在 Gitlab 项目中设置 CI,该项目在每个提交的 python 文件上运行 pylint? (也许 CI 也不是最好的策略,而是我能想到的第一个想法。
也许答案已经在某个地方,但我找不到。
(稍后,我还想检查存储库中已经存在的所有文件,并且我还想对 shell 和 R 脚本使用一些 linter。)
【问题讨论】:
如何在 Gitlab 项目中设置 CI,该项目在每个提交的 python 文件上运行 pylint? (也许 CI 也不是最好的策略,而是我能想到的第一个想法。
也许答案已经在某个地方,但我找不到。
(稍后,我还想检查存储库中已经存在的所有文件,并且我还想对 shell 和 R 脚本使用一些 linter。)
【问题讨论】:
这样的事情应该可以工作:
stages:
- lint
pylint:
image: "python:latest"
stage: lint
script:
- pip install pylint
- pylint src/
【讨论】:
- pylint src/ 称为特定命令?这将拉动No module named src/
src/ 目录
pylint 某个文件夹,它将检查所有 *.py 文件,无论它们是否在最后一次提交中被更改
这是你可以做的
.gitlab-ci.yml
stages:
- Lint
Lint:
stage: Lint
allow_failure: true
script:
- chmod +x lint.sh
- ./lint.sh
lint.sh
#! /bin/sh
pip install pycodestyle
current_branch="$CI_BUILD_REF_NAME"
echo $current_branch
all_changed_files=$(git diff --name-only origin/master origin/$current_branch)
echo "Checking changes!"
for each_file in $all_changed_files
do
# Checks each newly added file change with pycodestyle
pycodestyle $each_file
error_count=$(pycodestyle $each_file --count | wc -l)
if [ $error_count -ge 1 ]; then
exit 1
fi
if [ $error_count -eq 0 ]; then
exit 0
fi
done
echo "Completed checking"
【讨论】: