ci: 修复首次运行的两处失败
- backend:日志显示服务名 postgres 无法解析(runner 为 host 网络,services 只 发布端口、不提供容器别名)。给 service 加 55432:5432 端口映射,并改为依次 探测 postgres:5432 与 127.0.0.1:55432,连上后写入 PG* 与 ARTEX_PG_DSN; 都不通时打印解析结果,便于判断网络模式。 - frontend/release:setup-node 的 cache 只接受 npm/yarn/pnpm,之前的 cache: false 会导致 "Caching for 'false' is not supported" 直接失败,去掉该键。
This commit is contained in:
1 parent
cadc8af05d
commit
ba2f4b4b06
2 files changed
+46
-21
No files matched your search
+45
-20
@@ -1,15 +1,12 @@
|
||||
# Gitea Actions:push 到 main 时跑后端测试与前端构建。
|
||||
# 刻意不接 pull_request:solo 开发时同一提交会跑两遍,浪费 CI 时间。
|
||||
#
|
||||
# 前置条件(缺一不可):
|
||||
# 前置条件:
|
||||
# 1. 仓库 Settings → Actions 勾选 “Enable Repository Actions”
|
||||
# 2. 已注册带 ubuntu-latest-amd64 标签、且以 Docker 模式运行的 Gitea Runner
|
||||
# (services 容器只在 Docker 模式下可用)
|
||||
# 现有 Runner:runner-amd64 → ubuntu-latest-amd64 / ubuntu-22.04-amd64 / ubuntu-20.04-amd64
|
||||
# runner-arm64 → ubuntu-latest-arm64 / ubuntu-22.04-arm64 / ubuntu-20.04-arm64
|
||||
# 想跑在 arm64 上把下面的 runs-on 换成 ubuntu-latest-arm64 即可。
|
||||
# 3. Runner 能出网:actions/checkout 与 actions/setup-go 默认从 github.com 拉取,
|
||||
# setup-go 还要从 go.dev 下载工具链
|
||||
# 2. 已注册带 ubuntu-latest-amd64 标签的 Gitea Runner
|
||||
# runner-amd64 → ubuntu-latest-amd64 / ubuntu-22.04-amd64 / ubuntu-20.04-amd64
|
||||
# runner-arm64 → ubuntu-latest-arm64 / ubuntu-22.04-arm64 / ubuntu-20.04-arm64
|
||||
# 3. Runner 能出网:actions/checkout 从 github.com 拉 action,setup-go 从 go.dev 下工具链
|
||||
name: ci
|
||||
|
||||
on:
|
||||
@@ -30,20 +27,17 @@ jobs:
|
||||
POSTGRES_USER: artex
|
||||
POSTGRES_PASSWORD: artex
|
||||
POSTGRES_DB: artex
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U artex"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 30
|
||||
env:
|
||||
ARTEX_PG_DSN: postgres://artex:artex@postgres:5432/artex?sslmode=disable
|
||||
# 同时声明端口映射:runner 是 host 网络时服务名解析不了,
|
||||
# 只能靠发布到 127.0.0.1:55432 连进去。用高位端口避免撞宿主机的 postgres。
|
||||
ports:
|
||||
- "55432:5432"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26"
|
||||
# Runner 没开缓存服务时 actions/cache 会失败,这里先关掉保稳。
|
||||
# setup-go 的 cache 是布尔输入,false 表示不做缓存(依赖 Runner 的缓存服务)。
|
||||
cache: false
|
||||
|
||||
- name: 安装 psql 客户端
|
||||
@@ -52,10 +46,39 @@ jobs:
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq postgresql-client
|
||||
|
||||
- name: 探测 postgres 并确定连接串
|
||||
run: |
|
||||
# 两种网络模式都要兼容:
|
||||
# bridge 模式 → 服务名 postgres 可解析
|
||||
# host 模式 → 服务名不解析,走发布到宿主机的 127.0.0.1:55432
|
||||
for hp in "postgres:5432" "127.0.0.1:55432"; do
|
||||
host="${hp%:*}"
|
||||
port="${hp#*:}"
|
||||
echo "== 探测 ${host}:${port}"
|
||||
for _ in $(seq 1 15); do
|
||||
if pg_isready -h "$host" -p "$port" -U artex >/dev/null 2>&1; then
|
||||
echo "已连上 ${host}:${port}"
|
||||
{
|
||||
echo "PGHOST=${host}"
|
||||
echo "PGPORT=${port}"
|
||||
echo "PGUSER=artex"
|
||||
echo "PGDATABASE=artex"
|
||||
echo "PGPASSWORD=artex"
|
||||
echo "ARTEX_PG_DSN=postgres://artex:artex@${host}:${port}/artex?sslmode=disable"
|
||||
} >> "$GITHUB_ENV"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
done
|
||||
echo "postgres 不可达:postgres:5432 与 127.0.0.1:55432 都没连上" >&2
|
||||
echo "域名解析结果:$(getent hosts postgres 2>/dev/null || echo '未解析')" >&2
|
||||
exit 1
|
||||
|
||||
- name: 初始化数据库 schema
|
||||
env:
|
||||
PGPASSWORD: artex
|
||||
run: psql -h postgres -U artex -d artex -v ON_ERROR_STOP=1 -q -f db/schema.sql
|
||||
run: |
|
||||
psql -v ON_ERROR_STOP=1 -q -f db/schema.sql
|
||||
echo "schema 应用完成,表数:$(psql -tAc "select count(*) from information_schema.tables where table_schema='public'")"
|
||||
|
||||
- name: 初始化运行时表(llm_usage)
|
||||
run: |
|
||||
@@ -106,7 +129,9 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: false
|
||||
# 注意:这里不能写 cache: false —— setup-node 的 cache 只接受
|
||||
# npm / yarn / pnpm,传布尔值会报 "Caching for 'false' is not supported"。
|
||||
# 需要缓存时改成 cache: npm(要求 Runner 开了缓存服务)。
|
||||
|
||||
- name: 安装依赖
|
||||
working-directory: web
|
||||
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: false
|
||||
# cache 只接受 npm / yarn / pnpm,写 false 会直接报错。
|
||||
|
||||
- name: 补齐打包工具
|
||||
run: |
|
||||
|
||||
Reference in new issue
Block a user