我正在尝试仅对更改的Python文件运行pylint,但我的构建一直失败。我通过git diff提取了更改的文件并将它们保存在一个变量中,但是当我将该变量注入到pylint调用中时,它会失败。然而,使用硬编码的文件名可以正常工作。这是我的yaml:
pylint:
stage: test
before_script:
- pip install pylint pylint-exit anybadge
script:
- echo CI_COMMIT_SHA=${CI_COMMIT_SHA}
- echo CI_MERGE_REQUEST_TARGET_BRANCH_NAME=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
- git fetch origin ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
- FILES=$(git diff --name-only ${CI_COMMIT_SHA} origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} | grep '\.py'$)
- echo "Changed files are $FILES"
- pylint --output-format=text $(find -type f -name "$FILES" ! -path "**/.venv/**") | tee ./pylint/pylint.log || pylint-exit $?
- PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log)
- anybadge --label=Pylint --file=pylint/pylint.svg --value=$PYLINT_SCORE 2=red 4=orange 8=yellow 10=green
- echo "Pylint score is $PYLINT_SCORE"
artifacts:
paths:
- ./pylint/
when: always
only:
refs:
- merge_requests
changes:
- "**/*.py"