已合并
catlass仓上gitcode action #1036
han zhang创建于 8月4日
catlass仓上gitcode action #1036
已合并
han zhang创建于 8月4日
han zhang
han zhang成员
8月4日

描述

catlass仓上gitcode action

关联的Issue

原因

catlass仓上gitcode action,暂时不影响门禁待陪跑完成后切换。

测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 han zhang 的贡献)
han zhanghan zhang成员
8月4日 创建了 pull request,commit e013c4e3
atomgit-bot
atomgit-bot
8月4日 评论:

变更摘要

此 PR 为 catlass 仓库新增了基于 gitcode 平台的 CI/CD 流水线配置,包含 ARM 编译、预冒烟测试、代码检查及静态检查等全套自动化工作流。主工作流 catlass_action.yml 通过 PR 评论中的 /compile 命令触发,协调多个子工作流按阶段执行,各作业间通过华为云 OBS 进行制品传递。

主要改动

  • 新增主工作流 catlass_action.yml:作为顶层编排入口,定义了 PR 触发条件(/compile 评论)、并发控制(最大 5 个、按 mr_id 抢占),并按 stage1(镜像选择、PR 文件获取)和 stage2(编译、冒烟、各类检查)两个阶段串联执行。
  • 新增 ARM 编译工作流 arm_compile_action.yml 及脚本 arm_compile.sh:在 ARM64 专用节点上通过 build-accelerate 插件执行 tests/test_compile.sh 完成 ARM 平台编译,编译产物和编译脚本均通过 OBS 传递。
  • 新增 ARM 预冒烟工作流 arm_pre_smoke.yml 及脚本 pre_smoke.sh:通过 manifest-management-plugin 在 ARM 自托管节点上部署冒烟环境,执行 tests/run_all_test.sh,并在完成后清理资源。
  • 新增代码检查工作流 codecheck_action.yml:包含 precommitcheck-prscaantiposion(反病毒)、codecheck 五个并行作业,分别进行提交规范检查、PR 内容校验、软件成分分析、病毒扫描和代码规范扫描。
  • 新增静态检查工作流 staticcheck_action.yml:通过 cann/.gitcode/actions/staticcheck 复用动作支持多种检查类型(markdowncodespell_checktag_closed_checkresource_existence_checklink_validity_check),检查结果以 CSV/JSON 格式上传至 OBS。
likedislike
atomgit-bot
atomgit-bot
8月4日 评论:

代码审查

审查结果汇总

文件 审查结论
.gitcode/scripts/arm_compile.sh 发现 2 个问题(P2 × 2)
.gitcode/scripts/pre_smoke.sh 发现 2 个问题(P2 × 1, P3 × 1)
.gitcode/workflows/arm_compile_action.yml 发现 1 个问题(P2 × 1);其余无问题
.gitcode/workflows/arm_pre_smoke.yml 发现 2 个问题(P1 × 1, P3 × 1);其余无问题
.gitcode/workflows/catlass_action.yml 发现 1 个问题(P2 × 1);其余无问题
.gitcode/workflows/codecheck_action.yml 发现 3 个问题(P1 × 2, P2 × 1);其余无问题
.gitcode/workflows/staticcheck_action.yml 发现 2 个问题(P2 × 1, P3 × 1);其余无问题

共计 13 个发现:P1 × 2、P2 × 7、P3 × 4。

整体风险评估:中高风险

本次变更为 catlass 仓库新增了完整的 CI/CD pipeline(7 个文件,+595 行)。最严重的问题是:

  1. codecheck_action.yml 中两处 obs-download 缺少鉴权凭证(P1)——将导致 JOB_precommitJOB_check_pr 必然失败。
  2. arm_pre_smoke.yml 的 outputs 引用了不存在的 job(P1)——复制粘贴错误,输出永远为空。
  3. 两个 Shell 脚本中 set -eret=$? 的错误处理模式冲突(P2)——自定义错误消息永远不会被打印。
  4. catlass_action.yml 中 env 块变量自引用(P2)——可能因平台差异导致 OBS 路径异常。
  5. staticcheck_action.ymlcommit_id 硬编码为 '0'(P2)——可能导致静态检查结果不可靠。

建议在启用门禁前修复所有 P1 和 P2 问题。

类型 数量
🔴 阻塞 3
🟡 建议 5

⛔ 需要修改

likedislike
CANN-robotCANN-robot成员
8月4日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月4日 评论:

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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
.gitcode 宋常霞, tanghaoran7 (2/2) 宋常霞 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robot成员
8月4日 评论:

CLA Signature Pass

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

likedislike
han zhang
han zhang成员
8月4日 评论:

compile

likedislike
CANN-robotCANN-robot成员
8月4日 添加了label:ci-pipeline-running
atomgit-bot
atomgit-bot8月4日进行代码检视1
.gitcode/scripts/pre_smoke.sh
@@ -0,0 +10,4 @@
10+if [ $ret -ne 0 ]; then
11+ echo "build catlass_examples fail"
12+ exit 1
13+fi
atomgit-bot
atomgit-bot8月4日评论:

🟡 Medium Priority

arm_compile.sh 完全相同的问题:pre_smoke.sh 第 2 行 set -e 使得第 8 行 bash -x tests/run_all_test.sh 失败时脚本立即退出,第 9-13 行的 ret=$? 捕获和错误处理逻辑永远不可达。

此外,第 11 行的错误消息 "build catlass_examples fail" 与脚本实际行为不匹配——这是从 arm_compile.sh 原样复制过来的。pre_smoke.sh 执行的是 tests/run_all_test.sh(冒烟测试),不是编译。错误消息应该反映实际失败的步骤。

证据链:新增第 2 行 set -e + 第 8 行 bash -x tests/run_all_test.sh → 失败时 -e 立即终止 → 第 9-13 行错误处理永远不可达 + 第 11 行错误消息内容不匹配。

建议:将错误处理改为 bash -x tests/run_all_test.sh || { echo "run_all_test fail"; exit 1; },同时修正错误消息以匹配实际执行的测试脚本。

likedislike
atomgit-bot
atomgit-bot8月4日进行代码检视1
.gitcode/scripts/arm_compile.sh
@@ -0,0 +11,4 @@
11+ret=$?
12+if [ $ret -ne 0 ]; then
13+ echo "build catlass_examples fail"
14+ exit 1
atomgit-bot
atomgit-bot8月4日评论:

🟡 Medium Priority

arm_compile.sh 第 2 行设置了 set -e,这意味着任何非零退出的命令会导致脚本立即终止。第 10 行 bash -x tests/test_compile.sh 是一个独立的简单命令,不在 if/while/&&/|| 等抑制 -e 的上下文中。

因此当 tests/test_compile.sh 失败(退出码非零)时,set -e 会使脚本在第 10 行立即退出,永远执行不到第 11 行 ret=$? 和第 12-14 行的错误处理逻辑。第 13 行的自定义错误消息 "build catlass_examples fail" 永远不会被打印。

tests/test_compile.sh 成功(退出码 0)时,ret=0,跳过 if 块,执行 exit 0。所以第 11-15 行的代码只在成功路径上有意义(纯属冗余),在失败路径上完全是死代码。

同样的问题也存在于 pre_smoke.sh 第 8-13 行。

证据链:新增第 2 行 set -e + 第 10 行 bash -x tests/test_compile.sh → 失败时 -e 立即终止 → 第 11-14 行错误处理永远不可达 → 自定义错误消息不会输出。

建议:将 bash -x tests/test_compile.sh 和后续的 ret=$? + if 块合并为一行:bash -x tests/test_compile.sh || { echo "build catlass_examples fail"; exit 1; }。或者移除 set -e 中对简单命令的退出行为(改用 set -e 仅配合显式错误处理),让 ret=$? 能够被捕获。

likedislike
atomgit-bot
atomgit-bot8月4日进行代码检视2
.gitcode/workflows/arm_pre_smoke.yml
已过期
@@ -0,0 +13,4 @@
13+ arm_run_url:
14+ value: ${{jobs.JOB_compile.outputs.primary-url}}
15+ arm_run_key:
16+ value: ${{jobs.JOB_compile.outputs.primary-key}}
atomgit-bot
atomgit-bot8月4日评论:

🟠 High Priority

arm_pre_smoke.ymlworkflow_call.outputs 中(第 14、16 行),arm_run_urlarm_run_key 的值引用了 jobs.JOB_compile.outputs.primary-urljobs.JOB_compile.outputs.primary-key。但此 workflow 中唯一定义的 job 是第 19 行的 JOB_pre_smoke,根本不存在 JOB_compile

这是从 arm_compile_action.yml(其中 job 确实叫 JOB_compile)复制粘贴过来的错误。调用方 catlass_action.ymlJOB_arm_pre_smoke 没有引用这些 outputs,所以当前不会直接导致调用方失败,但 outputs 永远为空,任何依赖这些 outputs 的下游消费者都将收到空值。

证据链:diff 中新增的第 14 行 → JOB_compile 在本文件中不存在 → outputs 永远为空 → 下游消费者拿到空值。

建议:将 JOB_compile 改为 JOB_pre_smoke,与第 19 行定义的 job id 保持一致。同时确认 JOB_pre_smoke(manifest-management-plugin)确实会产出 primary-urlprimary-key 这两个 outputs。

likedislike
System
系统消息系统
8月4日 评论:

changed this line on c62fb3c6 view diff detail

atomgit-bot
atomgit-bot8月4日进行代码检视1
.gitcode/workflows/codecheck_action.yml
@@ -0,0 +70,4 @@
70+ key: |
71+ ${{ env.obs_path }}/pr_filelist.txt
72+ ${{ env.obs_path }}/pr_filelist_mod.txt
73+ path: ${{ steps.process_checkout.outputs.path }}
atomgit-bot
atomgit-bot8月4日评论:

🟠 High Priority

codecheck_action.ymlJOB_check_probs-download 步骤(第 65-73 行)同样缺少 access-keysecret-key 参数。这是同一文件中第二个有此问题的 obs-download 步骤(第一个在 JOB_precommit 第 25-31 行)。其他所有 workflow 文件中的每个 OBS 操作都明确提供了凭证。

证据链:新增第 65-73 行 → 缺少 access-key/secret-key → OBS 下载鉴权失败 → check-pr 无法获取 pr_filelist.txtpr_filelist_mod.txt → job 失败。

建议:在 JOB_check_probs-download 步骤中补充 access-key: ${{ secrets.AK }}secret-key: ${{ secrets.SK }}

改动建议
73
+ -
74
+ name: download
75
+ uses: obs-download
76
+ with:
77
+ endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
78
+ bucket: "ascend-cann-open"
79
+ access-key: ${{ secrets.AK }}
80
+ secret-key: ${{ secrets.SK }}
81
+ key: |
82
+ ${{ env.obs_path }}/pr_filelist.txt
83
+ ${{ env.obs_path }}/pr_filelist_mod.txt
73
84
  path: ${{ steps.process_checkout.outputs.path }}
应用建议
likedislike
atomgit-bot
atomgit-bot8月4日进行代码检视1
.gitcode/workflows/codecheck_action.yml
@@ -0,0 +28,4 @@
28+ endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
29+ bucket: "ascend-cann-open"
30+ key: "${{ env.obs_path }}/pr_filelist_precommit.txt"
31+ path: ${{ steps.process_checkout.outputs.path }}
atomgit-bot
atomgit-bot8月4日评论:

🟠 High Priority

codecheck_action.ymlJOB_precommitobs-download 步骤(第 25-31 行)和 JOB_check_probs-download 步骤(第 65-73 行)缺少 access-keysecret-key 参数。

与此形成对比:同一文件中的 obs-upload 步骤(第 41-49 行)以及所有其他 workflow 文件(arm_compile_action.yml 第 35-36 行、arm_pre_smoke.yml 第 43-44 行、staticcheck_action.yml 第 30-31 行、catlass_action.yml 第 76-77 行)中的每个 obs-download / obs-upload 步骤都明确提供了 access-keysecret-key

缺少凭证会导致从 OBS 下载文件时鉴权失败,JOB_precommitJOB_check_pr 两个 job 将无法获取所需的 pr_filelist_precommit.txt / pr_filelist.txt / pr_filelist_mod.txt 文件。

证据链:新增第 25-31 行和 65-73 行 → 缺少 access-key/secret-key → 与其他所有 OBS 步骤不一致 → OBS 下载鉴权失败 → job 失败。

建议:在 JOB_precommitJOB_check_probs-download 步骤中补充 access-key: ${{ secrets.AK }}secret-key: ${{ secrets.SK }}。如果 OBS bucket 是公开读取的可以不需要凭证,但为了与其他步骤保持一致并防止 bucket 策略变更,建议统一加上。

改动建议
31
+ -
32
+ name: download
33
+ uses: obs-download
34
+ with:
35
+ endpoint: "https://obs.cn-north-4.myhuaweicloud.com"
36
+ bucket: "ascend-cann-open"
37
+ access-key: ${{ secrets.AK }}
38
+ secret-key: ${{ secrets.SK }}
39
+ key: "${{ env.obs_path }}/pr_filelist_precommit.txt"
31
40
  path: ${{ steps.process_checkout.outputs.path }}
应用建议
likedislike
atomgit-bot
atomgit-bot8月4日进行代码检视2
.gitcode/workflows/arm_compile_action.yml
已过期
@@ -0,0 +49,4 @@
49+ export WORKSPACE=${{ steps.process_checkout.outputs.path }}
50+ cd ${{ steps.process_checkout.outputs.path }}
51+ export task_name=${{ inputs.task_name }}
52+ export target_branch=${{ env.target_branch }}
atomgit-bot
atomgit-bot8月4日评论:

🟡 Medium Priority

arm_compile_action.yml 第 52 行:
引用的是 env.target_branch(全小写)。但调用方 catlass_action.yml 第 24 行定义的 env 变量名为 TARGET_BRANCH(全大写):

两者大小写不一致。环境变量名区分大小写,env.target_branchenv.TARGET_BRANCH 是不同的变量。因此 export target_branch=... 会被设置为空字符串。虽然后续 arm_compile.sh 脚本中并未直接使用 target_branch 变量,但如果将来脚本中需要用到或 build-accelerate 框架依赖此变量,将获取不到正确的目标分支。

证据链:新增第 52 行 → env.target_branch(小写)→ 对应 catlass_action.yml 第 24 行 TARGET_BRANCH(大写)→ 大小写不匹配 → 变量为空。

建议:将 env.target_branch 改为 env.TARGET_BRANCH,与 catlass_action.yml 中的定义保持一致。

改动建议
52
- export target_branch=${{ env.target_branch }}
52
+ export target_branch=${{ env.TARGET_BRANCH }}
应用建议
likedislike
System
系统消息系统
8月4日 评论:

changed this line on c62fb3c6 view diff detail

atomgit-bot
atomgit-bot8月4日进行代码检视2
.gitcode/scripts/arm_compile.sh
已过期
@@ -0,0 +1,3 @@
1+#!/bin/bash
2+set -ex
3+ 
4+cd ${WORKSPACE}
atomgit-bot
atomgit-bot8月4日评论:

🟡 Medium Priority

arm_compile.sh 第 4 行 cd ${WORKSPACE} 存在两个问题:

  1. 变量未加引号${WORKSPACE} 未用双引号包裹。如果 WORKSPACE 的值包含空格或特殊字符,会导致路径解析错误或潜在的 glob 展开。

  2. 空值不报错:当 WORKSPACE 未设置或为空时,cd 不带参数执行(等同于 cd),会静默跳转到 $HOME 目录。由于 set -ecd 成功时不会触发退出,后续所有 pip3 installsourcebash tests/test_compile.sh 都将在错误的目录($HOME)下执行——要么找不到文件而失败,要么在错误位置运行。

WORKSPACE 由外部 arm_compile_action.yml 第 49 行通过 export WORKSPACE=${{ steps.process_checkout.outputs.path }} 设置,正常情况下不会为空。但如果 build-accelerate 传递环境变量失败或 checkout 步骤异常,此防护缺失将成为隐患。

证据链:新增第 4 行 → cd ${WORKSPACE} 未加引号且无空值检测 → WORKSPACE 为空时静默跳转 HOME → 后续命令在错误目录执行。

建议:将 cd ${WORKSPACE} 改为 cd "${WORKSPACE}"。如果业务上要求 WORKSPACE 不能为空,可以在此之前加上 : "${WORKSPACE:?WORKSPACE is not set}" 进行防御性检查。

改动建议
4
- cd ${WORKSPACE}
4
+ cd "${WORKSPACE}"
应用建议
likedislike
System
系统消息系统
8月4日 评论:

changed this line on c62fb3c6 view diff detail

atomgit-bot
atomgit-bot8月4日进行代码检视1
.gitcode/workflows/staticcheck_action.yml
@@ -0,0 +43,4 @@
43+ target_branch: ${{ env.TARGET_BRANCH }}
44+ repo_name: ${{ env.repo_name }}
45+ merge_id: ${{ env.MERGE_ID }}
46+ commit_id: '0'
atomgit-bot
atomgit-bot8月4日评论:

🟡 Medium Priority

staticcheck_action.yml 第 46 行将 commit_id 硬编码为字符串 '0'
commit_id: '0'

而该 workflow 在第 22 行已经 checkout 了正确的 commit(${{ atomgit.event.pull_request.merge_commit_sha || atomgit.sha }}),表明实际 commit SHA 是可获取的。commit_id: '0' 看起来是一个未完成的占位符。cann/.gitcode/actions/staticcheck@master 这个 action 如果使用 commit_id 做基线对比或追踪,传 '0' 会导致检查结果不可靠(例如无法正确确定变更范围,或将所有文件标记为新增)。

证据链:新增第 46 行 → commit_id: '0' 硬编码 → 未使用实际的 merge_commit_sha → staticcheck action 可能产生错误的检查结果。

建议:将 commit_id: '0' 替换为实际的 commit SHA:${{ atomgit.event.pull_request.merge_commit_sha || atomgit.sha }},与同文件中 checkout 步骤(第 22 行)使用的 ref 保持一致。如果 '0' 在该 action 中确实有特殊语义(如表示"不使用基线"),请添加注释说明。

likedislike
han zhanghan zhang成员
8月4日 update merge request[project id: 7631999, iid: 1036, commit_id: 78550fe9afbb3108a062a7ac18d2b90c5254cdf4] virtual merging success
此处折叠了5条事件消息 查看更多
CANN-robotCANN-robot成员
8月4日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月4日 评论:
流水线 PR-pipeline_catlass#2354 [ commitID:ebb84647 ] 已终止运行
⚠️ 流水线执行结果已过期,当前 PR 最新 commit 为 c62fb3c6,请重新运行流水线
阶段 任务名 状态 详情
编译构建 Build_arm >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck_pre-commit >>>
开源片段检查 SCA >>>
pre-commit pre-commit >>>
static_check_markdownlint >>>
static_check_link_validity >>>
static_check_resource_check >>>
static_check_codespell_check >>>
static_check_tag_closed_check >>>
开发者测试 UT_arm 🟨 >>>
流水线 PR-pipeline_catlass 🟨 >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[Zhang, Haobo, init__zhb__]评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
han zhang
han zhang成员
8月4日 评论:

compile

likedislike
CANN-robotCANN-robot成员
8月4日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月4日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月4日 添加了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
8月4日 评论:
流水线 PR-pipeline_catlass#2356 [ commitID:c62fb3c6 ] 已完成
阶段 任务名 状态 详情
编译构建 Build_arm >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck_pre-commit >>>
开源片段检查 SCA >>>
pre-commit pre-commit >>>
static_check_markdownlint >>>
static_check_link_validity >>>
static_check_resource_check >>>
static_check_codespell_check >>>
static_check_tag_closed_check >>>
开发者测试 UT_arm >>>
流水线 PR-pipeline_catlass >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[Zhang, Haobo, init__zhb__]评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
tanghaoran
tanghaoran成员
8月5日 评论:

/lgtm

likedislike
songchangxia成员
8月5日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月5日 添加了label:lgtmapproved
CANN-robotCANN-robot成员
8月5日 解决了最后一个问题
CANN-robotCANN-robot成员
8月5日 合入了pull request
CANN-robot
CANN-robot成员
8月5日 评论:

Pull Request 已合并或已关闭。

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

likedislike
CANN-robot
CANN-robot成员
8月5日 评论:

Pull Request 已合并或已关闭。

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

likedislike