Cookiecutter Django在Run预提交时失败了Github Actions



***编辑问题已解决。在提交/推送之前,需要做几件事来在我的环境中设置预提交。

  1. "it初始化">
  2. '预提交安装'
  3. 打开新终端,激活venv
  4. '预提交运行--所有文件'

希望这对将来的某个人有所帮助。


初级Web开发人员发表他的第一篇文章!

我正在使用Cookiecutter模板建立一个PythonDjango项目https://github.com/cookiecutter/cookiecutter-django

然而,在任何对GitHub的提交之后,GitHub Actions测试在linter的Run预提交步骤中都会失败。我收到错误消息:";错误:进程"/opt/hostedtoolcache/Python/3.9.10/x64/bin/pre-commit"失败,退出代码为1";

我的研究表明,这是一个普通的python linter失败,但不清楚它失败的原因。slug repo没有任何问题,我已经在3台不同的机器(2台Mac和1台Windows(上多次设置了该项目,每次都推送到新的存储库,每次都稍微修改设置,在项目初始化后没有修改任何代码,遗憾的是收到了相同的结果。

我完全被难住了,我在这个问题上的进展也停止了。请注意,我对GitHub操作没有太多经验。使用这个项目模板的一部分是让这些漂亮的功能为未来的开发提供支持。

我感到困惑的一件事是,当命令";python3-版本";在我用来初始化项目的所有机器上,都返回python 3.9.9。在项目中简单搜索";3.9.10";不返回任何结果。

以下是我的相关项目构建设置。我尝试过很多不同的组合,但这是我想投入生产的结果。所有通过Docker构建和运行的东西都在本地组成,没有任何问题。非常感谢您的帮助和指导!由于信誉限制,代码中删除了一些看似不相关的链接。https://github.com/TElphee01/django1

版本:0.1.0

open_source_license:2-BSD

时区:EST

windows:n

使用ycharm:n

use_docker:y

postgresql_version:14.1

js_task_runner:吞下

cloud_provider:AWS

邮件服务:Mailgun

使用同步:n

Use_drf:y

custom_bootstrap_compilation:n

use_compressor:y

use_celery:y

use_mailhog:y

use_sentry:y

使用蛋白激酶:y

use_heroku:y

ci_tool:Github

Keep_cal_envs_in_vcs:y

调试:n

在以下位置找到错误消息:https://github.com/TElphee01/django1/runs/5325567134?check_suite_focus=true运行预提交步骤

Run pre-commit/action@v2.0.3
install pre-commit
/opt/hostedtoolcache/Python/3.9.10/x64/bin/pre-commit run --show-diff-on-failure --color=always --all-files
[INFO] Initializing environment for github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for github.com/psf/black.
[INFO] Initializing environment for github.com/PyCQA/isort.
[INFO] Initializing environment for github.com/PyCQA/flake8.
[INFO] Initializing environment for github.com/PyCQA/flake8:flake8-isort.
[INFO] Installing environment for github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for github.com/PyCQA/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for github.com/PyCQA/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
trim trailing whitespace.................................................Passed
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook
Fixing README.md
check yaml...............................................................Passed
black....................................................................Passed
isort....................................................................Failed
- hook id: isort
- files were modified by this hook
Fixing /home/runner/work/django1/django1/tefrontend/users/tests/test_views.py
flake8...................................................................Passed
pre-commit hook(s) made changes.
If you are seeing this message in CI, reproduce locally with: `pre-commit run --all-files`.
To run `pre-commit` as part of git workflow, use `pre-commit install`.
All changes made by hooks:
diff --git a/README.md b/README.md
index a64ec04..c4c8a44 100644
Binary files a/README.md and b/README.md differ
diff --git a/tefrontend/users/tests/test_views.py b/tefrontend/users/tests/test_views.py
index ebdc864..4fe526a 100644
--- a/tefrontend/users/tests/test_views.py
+++ b/tefrontend/users/tests/test_views.py
@@ -11,11 +11,7 @@ from django.urls import reverse
from tefrontend.users.forms import UserAdminChangeForm
from tefrontend.users.models import User
from tefrontend.users.tests.factories import UserFactory
-from tefrontend.users.views import (
-    UserRedirectView,
-    UserUpdateView,
-    user_detail_view,
-)
+from tefrontend.users.views import UserRedirectView, UserUpdateView, user_detail_view

pytestmark = pytest.mark.django_db

Error: The process '/opt/hostedtoolcache/Python/3.9.10/x64/bin/pre-commit' failed with exit code 1

提交前检查似乎在您的项目中检测到了一些特定的问题:

  • ;文件末尾";检查,确保文件为空或以一个换行符结尾,以及
  • ";isort";检查,这与import语句的顺序和格式有关

在这两种情况下,工具也在纠正问题。

如果您要在本地安装并运行pre-commit,您可以提交它所做的更改,然后在提交通过本地检查时推送代码。

如果您在存储库中安装pre-commit,然后运行pre-commit install,它将作为pre-commit挂钩安装,因此当您提交更改时,这些检查将自动为您运行。

最新更新