Files
ClassHelper/.github/workflows/release-linux-server.yml
T
LoveChengke 67e3961e55 ci(workflow): 修 Linux 出包 —— 补 Prisma Client 生成,SHA256SUMS 不再排序打乱
首次在 tag push 上跑就挂了(run 37294579347,失败在"构建 Linux 安装包")。两处都是我的问题:

1. 漏了 `pnpm --filter @classhelper/server db:generate`。`packages/server/src/generated/prisma`
   是 gitignored 的,CI 全新检出来没有它,于是 Prisma 类型解析不到、回调参数全被推成 any,
   `tsc` 报出一大片 TS7006 / TS2339 —— 看着像代码写错了,其实只是缺生成物。
   本机因为早就生成过,永远踩不到这个坑;deploy/Dockerfile 的构建阶段本来就有这一步,
   workflow 里漏抄了(同一条注释在那边写着)。
2. 更新 SHA256SUMS 时用了 `sort -u -k2` 去重,会把那份人读的清单(表头 + 体积 + 说明行)打散。
   改成只替换/追加本包那一行,其余原样保留。
2026-10-05 18:10:29 +08:00

125 lines
4.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.
name: 发布 Linux 服务端安装包
# 为什么单独有这个 workflow:
# Linux 包的依赖(@libsql/linux-x64-gnu、@prisma/adapter-libsql 等)是平台相关的,
# 在 Windows 开发机上 npm install 出来的 node_modules 装到 Linux 跑不起来,
# 所以 Linux 包必须在 Linux 上构建。这个 workflow 用 ubuntu runner 产出
# classhelper-server-linux-x64-<版本>.tar.gz 并挂到 GitHub Release 上,
# 服务器上的 `classhelper upgrade` 就是从这里下载 + 校验 sha256 的。
#
# 用法:
# 1. 先在本地按惯例打出 Windows 包并发 Release(vX.Y.Z);
# 2. 到 Actions 页面手动运行本 workflow,填 tag(例如 v1.1.0);
# 3. 跑完 Release 里会多出 Linux 包与更新后的 SHA256SUMS-<版本>.txt。
#
# 也可以只跑构建不挂 Release(attach=false),产物在 workflow 的 Artifacts 里。
on:
workflow_dispatch:
inputs:
tag:
description: '要构建并挂载的 Release tag(例如 v1.1.0)'
required: true
type: string
attach:
description: '构建后上传到该 Release'
required: false
default: true
type: boolean
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build-linux-package:
runs-on: ubuntu-22.04
timeout-minutes: 40
steps:
- name: 确定 tag
id: ref
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
echo "attach=${{ inputs.attach }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
echo "attach=true" >> "$GITHUB_OUTPUT"
fi
- name: 检出代码
uses: actions/checkout@v4
with:
ref: ${{ steps.ref.outputs.tag }}
- name: 安装 Node 22
uses: actions/setup-node@v4
with:
node-version: '22'
- name: 安装 pnpm
uses: pnpm/action-setup@v4
with:
version: 11.8.0
run_install: false
- name: 安装依赖
run: pnpm install --frozen-lockfile
- name: 生成 Prisma Client
# 必须显式生成:packages/server/src/generated/prisma 是 gitignored 的,CI 上全新检出没有它。
# 少了这一步,`tsc` 会因为 Prisma 类型解析不到而把回调参数全推成 any,报出一大片
# "TS7006 Parameter 'item' implicitly has an 'any' type" / "TS2339 Property 'id' does not exist
# on type '{}'" —— 看着像代码写错了,实际是缺生成物(本机因为早就生成过,永远踩不到)。
# deploy/Dockerfile 的构建阶段有同样的步骤与注释。
run: pnpm --filter @classhelper/server db:generate
- name: 构建 Linux 安装包
run: pnpm dist:server:linux
- name: 展示产物
run: ls -la release-server/
- name: 上传构建产物(Artifacts)
uses: actions/upload-artifact@v4
with:
name: classhelper-server-linux-x64
path: |
release-server/classhelper-server-linux-x64-*.tar.gz
release-server/classhelper-server-linux-x64-*.tar.gz.sha256
if-no-files-found: error
retention-days: 30
- name: 挂到 Release 并更新 SHA256SUMS
if: steps.ref.outputs.attach == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.ref.outputs.tag }}
run: |
set -euo pipefail
VERSION="${TAG#v}"
TARBALL="release-server/classhelper-server-linux-x64-${VERSION}.tar.gz"
SUMS="release-server/SHA256SUMS-${VERSION}.txt"
if [ ! -f "$TARBALL" ]; then
echo "::error::没有找到 $TARBALL(tag 与 package.json 的版本号对得上吗?)"
exit 1
fi
# 取回已有的校验清单(Windows 包那几行),只替换/追加本包这一行,其余内容原样保留。
# 注意**不要**用 `sort -u` 去重:那份文件是人读的(表头 + 体积 + 说明),排序会把它们打散。
gh release download "$TAG" --pattern "SHA256SUMS-*.txt" --dir release-server --clobber || true
DOWNLOADED="$(ls release-server/SHA256SUMS-*.txt 2>/dev/null | head -n 1 || true)"
if [ -n "$DOWNLOADED" ] && [ "$DOWNLOADED" != "$SUMS" ]; then mv "$DOWNLOADED" "$SUMS"; fi
touch "$SUMS"
grep -v "^[0-9a-f]\{64\} classhelper-server-linux-" "$SUMS" > "${SUMS}.new" || true
printf '%s %s\n' "$(sha256sum "$TARBALL" | awk '{print $1}')" "$(basename "$TARBALL")" >> "${SUMS}.new"
mv "${SUMS}.new" "$SUMS"
gh release upload "$TAG" "$TARBALL" "$SUMS" --clobber
echo "已上传:"
cat "$SUMS"