修复 CI:slim 镜像没有 curl,网络操作改用 python 标准库
ci/fetch ok
ci/pip ok
ci/sync ok
ci/ruff ok
ci/pytest ok
代码测试 / ruff + pytest (push) Successful in 1m16s
ci/fetch ok
ci/pip ok
ci/sync ok
ci/ruff ok
ci/pytest ok
代码测试 / ruff + pytest (push) Successful in 1m16s
首轮实跑 1s 即死,日志定位 /var/run/act/workflow/0.sh: curl: command not found——python:3.13-slim 不带 curl/wget/git;SDK 仓库那份 ci.yml 的「curl 可用」是宿主机 probe 验证的,进了 container 不成立(且该 方案在 Gitea 上从未跑绿过,后来整体迁去了 GitHub)。 - archive 拉取与 commit status 上报改用 python3 urllib(容器里保证 在场的只有 python),note() 参数经 argv 传入、token 走环境变量 - 去掉 pyright 及其 apt 装 node 的兜底:多一条网络依赖链,且本地 pyright 常绿,CI 保持 ruff + pytest 即可 - 各步骤不再吞输出,日志可直接定位
This commit is contained in:
1 parent
0145b7b01a
commit
24c235c93d
1 file changed
+31
-21
+31
-21
@@ -8,7 +8,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: ruff + pyright + pytest
|
name: ruff + pytest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# 固定官方 python 镜像:保证 python3.13 + pip 在场(runner 默认镜像
|
# 固定官方 python 镜像:保证 python3.13 + pip 在场(runner 默认镜像
|
||||||
# 工具链不明,SDK 仓库实测任务曾 7s 即死);runner 不支持 container
|
# 工具链不明,SDK 仓库实测任务曾 7s 即死);runner 不支持 container
|
||||||
@@ -16,32 +16,48 @@ jobs:
|
|||||||
container: python:3.13-slim
|
container: python:3.13-slim
|
||||||
steps:
|
steps:
|
||||||
# 不用 actions/checkout、不用 git:runner 对 github 连通性不稳
|
# 不用 actions/checkout、不用 git:runner 对 github 连通性不稳
|
||||||
# (SDK 仓库 probe 实测),改走 Gitea archive 接口拉源码 tarball;
|
# (SDK 仓库 probe 实测),改走 Gitea archive 接口拉源码 tarball。
|
||||||
# 每步结果写进 commit status(日志匿名不可读,status 远程可读,
|
# slim 镜像没有 curl/wget/git,网络操作一律用容器里保证在场的
|
||||||
# GITEA_TOKEN 未配置时静默降级,不影响流程)
|
# python 标准库;每步结果写进 commit status(日志匿名不可读,
|
||||||
|
# status 远程可读;GITEA_TOKEN 未配置时静默降级,不影响流程)
|
||||||
- name: 拉源码、装依赖并执行测试
|
- name: 拉源码、装依赖并执行测试
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
UV_PYTHON_INSTALL_MIRROR: https://registry.npmmirror.com/-/binary/python-build-standalone
|
UV_PYTHON_INSTALL_MIRROR: https://registry.npmmirror.com/-/binary/python-build-standalone
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
SERVER="${GITHUB_SERVER_URL:-https://gitea.4i.hk}"
|
export SERVER="${GITHUB_SERVER_URL:-https://gitea.4i.hk}"
|
||||||
note() {
|
note() {
|
||||||
curl -s -m 10 -X POST \
|
python3 -c '
|
||||||
-H "Authorization: token $TOKEN" \
|
import sys, os, json, urllib.request
|
||||||
-H 'Content-Type: application/json' \
|
ctx, desc, state = sys.argv[1:4]
|
||||||
-d "{\"state\":\"$3\",\"context\":\"ci/$1\",\"description\":\"$2\"}" \
|
req = urllib.request.Request(
|
||||||
"$SERVER/api/v1/repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
|
os.environ["SERVER"] + "/api/v1/repos/" + os.environ["GITHUB_REPOSITORY"]
|
||||||
-o /dev/null
|
+ "/statuses/" + os.environ["GITHUB_SHA"],
|
||||||
|
data=json.dumps(
|
||||||
|
{"state": state, "context": "ci/" + ctx, "description": desc}
|
||||||
|
).encode(),
|
||||||
|
headers={
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": "token " + os.environ["TOKEN"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
urllib.request.urlopen(req, timeout=10)
|
||||||
|
except Exception:
|
||||||
|
pass # status 只是旁路:token 未配置或网络抖动都不能影响主流程
|
||||||
|
' "$1" "$2" "$3"
|
||||||
}
|
}
|
||||||
trap 'note error "步骤意外失败,详见 Actions 日志" failure' ERR
|
trap 'note error "步骤意外失败,详见 Actions 日志" failure' ERR
|
||||||
|
|
||||||
curl -sL "$SERVER/api/v1/repos/$GITHUB_REPOSITORY/archive/$GITHUB_SHA.tar.gz" -o src.tgz \
|
python3 -c "import urllib.request; urllib.request.urlretrieve(
|
||||||
|
'$SERVER/api/v1/repos/$GITHUB_REPOSITORY/archive/$GITHUB_SHA.tar.gz',
|
||||||
|
'src.tgz')" \
|
||||||
&& mkdir src && tar -xzf src.tgz -C src --strip-components=1 && cd src \
|
&& mkdir src && tar -xzf src.tgz -C src --strip-components=1 && cd src \
|
||||||
|| { note fetch "archive 拉取失败" failure; exit 1; }
|
|| { note fetch "archive 拉取失败" failure; exit 1; }
|
||||||
note fetch ok success
|
note fetch ok success
|
||||||
|
|
||||||
pip install uv >/dev/null 2>&1 \
|
pip install uv \
|
||||||
|| { note pip "pip 安装 uv 失败" failure; exit 1; }
|
|| { note pip "pip 安装 uv 失败" failure; exit 1; }
|
||||||
note pip ok success
|
note pip ok success
|
||||||
|
|
||||||
@@ -49,7 +65,7 @@ jobs:
|
|||||||
# runner 到 github 时通时不通,sync 失败自动重试
|
# runner 到 github 时通时不通,sync 失败自动重试
|
||||||
sync_ok=""
|
sync_ok=""
|
||||||
for _ in 1 2 3; do
|
for _ in 1 2 3; do
|
||||||
if uv sync >/dev/null 2>&1; then sync_ok=1; break; fi
|
if uv sync; then sync_ok=1; break; fi
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
[ -n "$sync_ok" ] || { note sync "uv sync 失败(已重试 3 次)" failure; exit 1; }
|
[ -n "$sync_ok" ] || { note sync "uv sync 失败(已重试 3 次)" failure; exit 1; }
|
||||||
@@ -59,12 +75,6 @@ jobs:
|
|||||||
|| { note ruff "ruff check 未通过" failure; exit 1; }
|
|| { note ruff "ruff check 未通过" failure; exit 1; }
|
||||||
note ruff ok success
|
note ruff ok success
|
||||||
|
|
||||||
# pyright 需要 node:镜像里没有就装 Debian 的(保底 pyright 自带下载)
|
uv run pytest \
|
||||||
command -v node >/dev/null 2>&1 || { apt-get update -qq && apt-get install -y -qq nodejs; } || true
|
|
||||||
uv run pyright \
|
|
||||||
|| { note pyright "pyright 未通过" failure; exit 1; }
|
|
||||||
note pyright ok success
|
|
||||||
|
|
||||||
uv run pytest -q \
|
|
||||||
|| { note pytest "pytest 未通过" failure; exit 1; }
|
|| { note pytest "pytest 未通过" failure; exit 1; }
|
||||||
note pytest ok success
|
note pytest ok success
|
||||||
Reference in new issue
Block a user