已合并
chore: add pre-commit checks #34
chore: add pre-commit checks #34
已合并
汪超创建于 28 天前
汪超成员
28 天前

Pull Request 说明

变更说明

新增precommit

  • 关联 Issue:
  • 主要改动:
  • 补充说明:

变更类型

验证

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 汪超 的贡献)
汪汪超成员
28 天前 创建了 pull request,commit 9d2af2d7
CANN-robotCANN-robot成员
28 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
28 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/cannbot-knowledge ✅ zhanghz1, wangsj0012 (2/2) ✅ zhanghz1 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

qq_41667743, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
汪超成员
28 天前 评论:

/compile

likedislike
汪汪超成员
28 天前 预合并成功(commit_id: c1dddd0eac1ec690f76b0f45ef5f9de1e12422f7)
CANN-robot
CANN-robot成员
28 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
28 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
28 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
28 天前 添加了label:ci-pipeline-passed
汪超成员
27 天前 评论:

/check-pr

likedislike
CANN-robot
CANN-robot成员
27 天前 评论:

The following labels are not ready.

approved: Please wait for committers to review the code.

lgtm: Please wait for committers to review the code.

likedislike
zhanghz1
zhanghz1成员27 天前进行代码检视1
.pre-commit-config.yaml
@@ -0,0 +42,4 @@
42+ 
43+ - repo: local
44+ hooks:
45+ - id: shell-syntax
zhanghz1
zhanghz127 天前评论:

pre-commit 会把匹配的文件批量追加到 entry 后面,实际执行形如 bash -n a.sh b.sh c.sh。Bash 只解析第一个脚本,其余路径成为该脚本的位置参数,不会被检查。因此,一次提交多个 Shell 文件时,只要错误文件没有排在某个执行批次的首位,Check shell syntax 就会错误地显示通过。

已复现: 在隔离 Git 仓库中原样使用该 hook,暂存 00.sh 至 15.sh 共 16 个 Bash 脚本;前 15 个内容合法,只有 15.sh 含非法语句 if then。使用 pre-commit 4.6.2、默认并发配置执行:

pre-commit run shell-syntax --all-files -v
→ Check shell syntax ... Passed;退出码 0

bash -n 15.sh
→ syntax error near unexpected token `then';退出码 2

这会使本 PR 新增的提交前检查无法可靠拦截 Shell 语法错误,不是单纯的提示或配置风格问题。

必须调整: 通过包装脚本逐个遍历 "$@",对每个文件执行 bash -n "$file",遇错返回非零。仅添加 require_serial: true 不能解决问题,因为串行执行仍会传入多个文件。包装逻辑可采用:

for file in "$@"; do
    bash -n "$file" || exit $?
done

增加“同批次包含合法脚本及非首位错误脚本”的回归。已在临时夹具中验证上述修正:原错误样例被拒绝,pre-commit 退出 1;将错误脚本改为合法内容后退出 0。

likedislike
汪汪超成员
27 天前 预合并成功(commit_id: 8e4c277858562e58c3b6f2283b93964ac45112f6)
此处折叠了5条事件消息 查看更多
CANN-robotCANN-robot成员
27 天前 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
27 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
汪超成员
27 天前 评论:

/compile

likedislike
汪汪超成员
27 天前 预合并成功(commit_id: de8e7b74301d1a9ad0eb70e5baaa6b36218e8a2a)
CANN-robot
CANN-robot成员
27 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
27 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
27 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
27 天前 添加了label:ci-pipeline-passed
wangshaojun
wangshaojun成员
27 天前 评论:

/lgtm

likedislike
zhanghz1
zhanghz1成员
27 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
27 天前 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
27 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
zhanghz1zhanghz1成员
27 天前 解决了最后一个问题
CANN-robotCANN-robot成员
27 天前 合入了pull request