Files
patbond-ai/.gitea/workflows/ci.yml
T
lixi db87d66403
CI / ai-gates (push) Successful in 31s
fix(ai): 修 ruff lint 三处错误——CI 由红转绿
`4762358` 与 `86d63ab` 两次 CI 均因 `ruff check` 失败而红。

**根因是我的门禁自查方法错了**:用 `ruff check . | tail -1; echo $?` 读到的是
`tail` 的退出码而不是 ruff 的,于是把一次真实的 lint 失败读成了通过——先前声称
的「四道门禁全绿」是基于这个坏掉的检查得出的。已在 ci.yml 的 Gates 步骤就地注明
此坑,并改为逐条分开跑读各自退出码。

三处都是实际问题,非误报:
- `client.py:138` PYI034:`__enter__` 的返回注解硬编码为类名,应为 `Self`
  (子类化后注解会失准)
- `test_video.py:58` C408:`dict()` 调用改字面量
- `test_layering.py:85` PIE810:两次 `endswith` 合并为一次元组调用

修复后在与 CI 同构的隔离 venv(同镜像源、同 requirements-dev.txt,实测 ruff
版本与本地一致 0.16.8)逐道复验:secret-scan / format / lint / pytest 四道
退出码均为 0,100 测试全过。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-20 12:36:17 +08:00

66 lines
2.8 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Gitea Actions 门禁:与本地门禁同一套命令(规范见 patbond-doc
# docs/development/git-workflow.md)。零外部 action / 零 GitHub 依赖,
# 原因见 patbond-api 的 ci.yml 头注释。
# pip 与 PyPI 走腾讯云镜像,与 patbond-doc 的 mkdocs 安装同一策略。
#
# 本仓是唯一存放 AI 服务商凭证的仓库,因此 Secret scan 是第一个 step,
# 且先于任何依赖安装执行(ADR-021、ADR-023 §12)。
name: CI
on:
push:
branches: [dev]
pull_request:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
ai-gates:
runs-on: ubuntu-latest
steps:
- name: Checkout (manual)
run: |
git init -q .
AUTH_URL=$(echo "${{ github.server_url }}" | sed "s#https://#https://oauth2:${{ github.token }}@#")
git remote add origin "$AUTH_URL/${{ github.repository }}.git"
git fetch -q --depth 1 origin "+${{ github.ref }}:refs/ci-head"
git checkout -q refs/ci-head
# 凭证防泄漏兜底(ADR-021):与本地 pre-commit 同一脚本、同一规则表,
# 四仓副本内容同构,扫全部已跟踪文件(本次 push 变更的超集)。
- name: Secret scan
run: sh scripts/check-secrets.sh --all
- name: Set up Python
run: |
apt-get update -qq
apt-get install -y -qq --no-install-recommends python3 python3-venv python3-pip
python3 -m venv .venv
echo "$PWD/.venv/bin" >> "$GITHUB_PATH"
echo "PIP_INDEX_URL=https://mirrors.cloud.tencent.com/pypi/simple" >> "$GITHUB_ENV"
- name: Install dependencies
run: |
python -m pip install -q --upgrade pip
# requirements-dev.txt 落地前,门禁只装 lint/test 工具本身,
# 使 CI 从建仓第一天就是绿的而非「等代码来了再配」。
if [ -f requirements-dev.txt ]; then
pip install -q -r requirements-dev.txt
else
pip install -q ruff pytest
fi
if [ -f requirements.txt ]; then pip install -q -r requirements.txt; fi
# 与本地门禁同一套命令。ruff 兼任 format 检查与 lint,
# 对应 patbond-flutter 的 dart format + flutter analyze 两步。
#
# 本地自查时注意:`ruff check . | tail -1; echo $?` 读到的是 **tail** 的
# 退出码,不是 ruff 的——这样会把一次真实的 lint 失败读成通过(本仓已因此
# 红过一次)。逐条分开跑,或用 ${PIPESTATUS[0]}。
- name: Gates
run: |
python --version
ruff format --check .
ruff check .
# 尚无测试文件时 pytest 退出码为 5(no tests collected),
# 该情形视为通过;真实失败仍会以非 0/5 退出。
pytest -q || [ $? -eq 5 ]