一次修GitHub CI 的调试记录

465 阅读2分钟

菜狗闻星给 MMDetection 提了一个PR,链接如下,本地的pre-commit 代码审查过了,但是GitHub段的CI挂掉了,所以本文写一篇文章来记录一下修这个CI的过程。

github.com/open-mmlab/…

Untitled

点击Detail之后发现CI运行 pre-commit run --all-files 挂了,且能定位到文件 project/projects/Label-Studio/backend-template/_wsgi.py 但是不能定位到是哪一行不服务 isort 的规范。

Untitled

CI挂掉完整的日志文件如下:

#!/bin/bash -eo pipefail
pre-commit run --all-files
[INFO] Initializing environment for https://github.com/PyCQA/flake8.
[INFO] Initializing environment for https://github.com/PyCQA/isort.
[INFO] Initializing environment for https://github.com/pre-commit/mirrors-yapf.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/codespell-project/codespell.
[INFO] Initializing environment for https://github.com/executablebooks/mdformat.
[INFO] Initializing environment for https://github.com/executablebooks/mdformat:linkify-it-py,mdformat-openmmlab,mdformat_frontmatter.
[INFO] Initializing environment for https://github.com/myint/docformatter.
[INFO] Initializing environment for https://github.com/open-mmlab/pre-commit-hooks.
[INFO] Installing environment for https://github.com/PyCQA/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/PyCQA/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/mirrors-yapf.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://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 https://github.com/codespell-project/codespell.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/executablebooks/mdformat.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/myint/docformatter.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/open-mmlab/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
flake8...................................................................Passed
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Fixing /home/circleci/project/projects/Label-Studio/backend-template/_wsgi.py

yapf.....................................................................Passed
trim trailing whitespace.................................................Passed
check yaml...............................................................Passed
fix end of files.........................................................Passed
fix requirements.txt.....................................................Passed
fix double quoted strings................................................Passed
check for merge conflicts................................................Passed
fix python encoding pragma...............................................Passed
mixed line ending........................................................Passed
codespell................................................................Passed
mdformat.................................................................Passed
docformatter.............................................................Passed
check algorithm readme...................................................Passed
check copyright..........................................................Passed

Exited with code exit status 1
CircleCI received exit code 1

所以菜狗找到 MMEngine 开发者 xxx 大佬,大佬给了一个地址 github.com/mxschmitt/a… ,于是菜狗就开始研究文档怎么ssh连上CI的机器,然后运行pre-commit run --all-files 看看哪些文件被改变过了。

弄了很长一段时间没有搞定,于是问ChatGPT ,如何在CircleCI运行pre-commit 语句失败后执行 git diff 指令,chatgpt 给出了答案。

Untitled

修改了 .circleci/test.yml 文件,如下所示,重新push

pre-commit run --all-files || (git diff && exit 1) || true

Untitled

这样运行CI后就有提示修改了哪些内容,根据这个行信息,成功修复了CI错误。

Untitled

Untitled