From ba2f4b4b0610c13967e4daf59c6868c7b055f5a4 Mon Sep 17 00:00:00 2001 From: wangdefa <1+wangdefa@noreply.gitea.bcde.io> Date: Tue, 20 Oct 2026 21:54:06 -0700 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BF=AE=E5=A4=8D=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=9A=84=E4=B8=A4=E5=A4=84=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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" 直接失败,去掉该键。 --- .gitea/workflows/ci.yml | 65 +++++++++++++++++++++++++----------- .gitea/workflows/release.yml | 2 +- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index c88af7c..e381c8e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -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 diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index dd671c6..3a8eb87 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -43,7 +43,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "22" - cache: false + # cache 只接受 npm / yarn / pnpm,写 false 会直接报错。 - name: 补齐打包工具 run: |