您可以更改 GitLab 管道中的代码吗?

Ale*_*ler 9 python continuous-integration gitlab

GitLab CI/CD 管道是否可以提交代码更改?

\n\n

我想运行一个阶段,每当我推动我的工作时,它都会使用黑色自动格式化我的代码。

\n\n

gitlab-ci.yml

\n\n
image: python:3.6\n\nstages:\n  - test\n\nbefore_script:\n  - python3 -m pip install -r requirements.txt\n\ntest:linting:\n    script:\n        - black ./\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

我确保包含一个需要重新格式化的文件来测试这是否有效。

\n\n

作业输出

\n\n
 $ black ./\n reformatted test.py\n All done! \xe2\x9c\xa8  \xe2\x9c\xa8\n 1 file reformatted.\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的存储库中的文件保持不变,这让我相信这可能是不可能的。

\n

小智 17

Black 不会自动提交更正后的 python 代码,除非您使用pre-commit hook

在 CI 中运行黑色的最佳方法是包含以下内容:

black . --check --verbose --diff --color
Run Code Online (Sandbox Code Playgroud)

如果 python 代码无法遵守代码格式并强制用户修复格式,这将使测试失败。

请检查black --help所有标签。

这是关于 Black 的一个很好的参考:https ://www.mattlayman.com/blog/2018/python-code-black/

仓库:https: //github.com/psf/black