完善 Docker 发布与桌面安装包流水线

- 固定 Docker 与测试镜像使用 Node.js 24 trixie slim 基础镜像。

- 安装 Chromium 所需系统运行库,并清理 apt 索引、缓存和临时文件,降低最终镜像体积。

- 增加 Chromium 实际启动、服务健康检查以及 Go 和前端测试门禁,门禁通过后才发布镜像标签。

- 修复 v1.2.3 版本标签触发,自动构建版本镜像、各平台安装包并创建 GitHub Release。

- 完善版本产物校验、SHA256SUMS 校验和以及正式版本标签规则。

- 将 Linux、Windows、macOS 和 Docker 的 Playwright runtime 缓存改为独立恢复与立即保存。

- 修复 Chromium runtime 校验中的绝对路径问题,并补充平台与安装器源码缓存键。

- 同步更新发布文档、打包规范和前端路由测试断言。
This commit is contained in:
Christ committed 2026-08-12 23:40:52 +08:00
1 parent 70e03a8523
commit d36c357bab
8 files changed
+280 -42

No files matched your search

+138 -18
View File
@@ -5,6 +5,8 @@ on:
branches:
- main
- codex/desktop-packaging
tags:
- 'v*.*.*'
workflow_dispatch:
permissions:
@@ -14,14 +16,35 @@ concurrency:
group: desktop-cd-${{ github.ref }}
cancel-in-progress: true
env:
APP_VERSION: 0.0.0-${{ github.run_number }}
jobs:
prepare:
name: 准备发布版本
runs-on: ubuntu-24.04
outputs:
app_version: ${{ steps.version.outputs.app_version }}
steps:
- name: 解析并校验版本号
id: version
shell: bash
run: |
set -Eeuo pipefail
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
if [[ ! "$GITHUB_REF_NAME" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "版本标签必须符合 v1.2.3 格式:$GITHUB_REF_NAME" >&2
exit 1
fi
app_version="${GITHUB_REF_NAME#v}"
else
app_version="0.0.0-${GITHUB_RUN_NUMBER}"
fi
echo "app_version=$app_version" >> "$GITHUB_OUTPUT"
linux:
name: Linux 安装包 (${{ matrix.arch }})
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/codex/desktop-packaging'
needs: prepare
runs-on: ${{ matrix.runner }}
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
strategy:
fail-fast: false
matrix:
@@ -45,7 +68,7 @@ jobs:
- name: 配置 Node.js
uses: actions/setup-node@v6
with:
node-version: 22
node-version: 24
cache: npm
cache-dependency-path: frontend/package-lock.json
@@ -63,12 +86,12 @@ jobs:
go build -trimpath -ldflags='-s -w' -o "$package_dir/xianyu-server" ./cmd/server
go build -trimpath -ldflags='-s -w' -o "$package_dir/browser-install" ./cmd/browser-install
- name: 缓存 Linux Chromium runtime
- name: 恢复 Linux Chromium runtime 缓存
id: cache-linux-playwright
uses: actions/cache@v5
uses: actions/cache/restore@v5
with:
path: dist/ydisks-xianyu-helper-linux-${{ matrix.arch }}/playwright-runtime
key: ydisks-playwright-runtime-v6-linux-${{ matrix.arch }}-${{ hashFiles('go.mod', 'go.sum') }}
key: ydisks-playwright-runtime-v6-linux-${{ matrix.arch }}-${{ matrix.playwright_platform }}-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/**') }}
- name: 在原生架构 runner 预下载 Linux Chromium runtime
if: steps.cache-linux-playwright.outputs.cache-hit != 'true'
@@ -111,8 +134,8 @@ jobs:
chromium_path="$(find "$runtime_dir/playwright-browsers" -type f \
\( -name chrome -o -name headless_shell -o -name chrome-headless-shell \) -perm -111 -print -quit)"
test -n "$chromium_path"
chromium_revision="$(RUNTIME_SPEC="$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium").revision)')"
headless_revision="$(RUNTIME_SPEC="$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium-headless-shell").revision)')"
chromium_revision="$(RUNTIME_SPEC="$PWD/$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium").revision)')"
headless_revision="$(RUNTIME_SPEC="$PWD/$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium-headless-shell").revision)')"
test -d "$runtime_dir/playwright-browsers/chromium-$chromium_revision"
test -d "$runtime_dir/playwright-browsers/chromium_headless_shell-$headless_revision"
chromium_type="$(file -b "$chromium_path")"
@@ -122,6 +145,13 @@ jobs:
*) echo "Chromium 架构错误:$chromium_type" >&2; exit 1 ;;
esac
- name: 保存 Linux Chromium runtime 缓存
if: steps.cache-linux-playwright.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: dist/ydisks-xianyu-helper-linux-${{ matrix.arch }}/playwright-runtime
key: ${{ steps.cache-linux-playwright.outputs.cache-primary-key }}
- name: 组装 Linux 安装目录
run: |
set -Eeuo pipefail
@@ -140,8 +170,10 @@ jobs:
windows:
name: Windows 安装包
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/codex/desktop-packaging'
needs: prepare
runs-on: windows-latest
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
steps:
- name: 检出代码
uses: actions/checkout@v6
@@ -155,7 +187,7 @@ jobs:
- name: 配置 Node.js
uses: actions/setup-node@v6
with:
node-version: 22
node-version: 24
cache: npm
cache-dependency-path: frontend/package-lock.json
@@ -187,12 +219,12 @@ jobs:
go build -trimpath -ldflags "-s -w" -o dist/windows/browser-install.exe ./cmd/browser-install
go build -trimpath -ldflags "-s -w -H=windowsgui" -o dist/windows/xianyu-tray.exe ./cmd/tray
- name: 缓存 Windows Chromium runtime
- name: 恢复 Windows Chromium runtime 缓存
id: cache-windows-playwright
uses: actions/cache@v5
uses: actions/cache/restore@v5
with:
path: dist/windows/playwright-runtime/amd64
key: ydisks-playwright-runtime-v6-windows-amd64-${{ hashFiles('go.mod', 'go.sum') }}
key: ydisks-playwright-runtime-v6-windows-amd64-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/**') }}
- name: 预下载 Windows Chromium runtime
if: steps.cache-windows-playwright.outputs.cache-hit != 'true'
@@ -223,6 +255,13 @@ jobs:
Select-Object -First 1
if ($null -eq $chromium) { throw 'Windows Chromium runtime 缺少 Chromium 可执行文件' }
- name: 保存 Windows Chromium runtime 缓存
if: steps.cache-windows-playwright.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: dist/windows/playwright-runtime/amd64
key: ${{ steps.cache-windows-playwright.outputs.cache-primary-key }}
- name: 导入 Windows 签名证书
shell: pwsh
env:
@@ -288,8 +327,10 @@ jobs:
macos:
name: macOS 安装包
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/codex/desktop-packaging'
needs: prepare
runs-on: macos-14
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
steps:
- name: 检出代码
uses: actions/checkout@v6
@@ -303,7 +344,7 @@ jobs:
- name: 配置 Node.js
uses: actions/setup-node@v6
with:
node-version: 22
node-version: 24
cache: npm
cache-dependency-path: frontend/package-lock.json
@@ -329,7 +370,7 @@ jobs:
path: |
dist/macos/playwright-runtime/arm64
dist/macos/playwright-runtime/amd64
key: ydisks-playwright-runtime-v6-macos-universal-${{ hashFiles('go.mod', 'go.sum') }}
key: ydisks-playwright-runtime-v6-macos-mac14-universal-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/**') }}
- name: 预下载 macOS Chromium runtime
if: steps.cache-macos-playwright.outputs.cache-hit != 'true'
@@ -348,6 +389,34 @@ jobs:
-driver-dir "$PWD/dist/macos/playwright-runtime/amd64/playwright-driver" \
-browser-dir "$PWD/dist/macos/playwright-runtime/amd64/playwright-browsers"
- name: 校验 macOS Chromium runtime
run: |
set -Eeuo pipefail
for runtime_arch in arm64 amd64; do
runtime_dir="dist/macos/playwright-runtime/$runtime_arch"
node_path="$runtime_dir/playwright-driver/node"
spec_path="$PWD/$runtime_dir/playwright-driver/package/browsers.json"
test -x "$node_path"
test -f "$runtime_dir/playwright-driver/package/cli.js"
test -f "$spec_path"
chromium_revision="$(RUNTIME_SPEC="$spec_path" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium").revision)')"
headless_revision="$(RUNTIME_SPEC="$spec_path" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium-headless-shell").revision)')"
test -d "$runtime_dir/playwright-browsers/chromium-$chromium_revision"
test -d "$runtime_dir/playwright-browsers/chromium_headless_shell-$headless_revision"
chromium_path="$(find "$runtime_dir/playwright-browsers/chromium-$chromium_revision" -type f -path '*/Contents/MacOS/Google Chrome for Testing' -print -quit)"
headless_path="$(find "$runtime_dir/playwright-browsers/chromium_headless_shell-$headless_revision" -type f -name chrome-headless-shell -print -quit)"
test -n "$chromium_path"
test -n "$headless_path"
node_type="$(file -b "$node_path")"
chromium_type="$(file -b "$chromium_path")"
headless_type="$(file -b "$headless_path")"
case "$runtime_arch:$node_type:$chromium_type:$headless_type" in
arm64:*arm64*:*arm64*:*arm64*) ;;
amd64:*x86_64*:*x86_64*:*x86_64*) ;;
*) echo "macOS Playwright runtime 架构错误:$runtime_arch / $node_type / $chromium_type / $headless_type" >&2; exit 1 ;;
esac
done
- name: 保存 macOS Chromium runtime 缓存
if: steps.cache-macos-playwright.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
@@ -414,3 +483,54 @@ jobs:
name: ydisks-xianyu-helper-macos-amd64-${{ env.APP_VERSION }}
path: dist/macos/Ydisks-Xianyu-Helper-${{ env.APP_VERSION }}-amd64.pkg
if-no-files-found: error
release:
name: 发布 GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
needs:
- prepare
- linux
- windows
- macos
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: 下载全部平台安装包
uses: actions/download-artifact@v8
with:
pattern: ydisks-xianyu-helper-*
path: dist/release
merge-multiple: true
- name: 校验 Release 文件
shell: bash
run: |
set -Eeuo pipefail
test -f "dist/release/ydisks-xianyu-helper-linux-amd64-${{ needs.prepare.outputs.app_version }}.tar.gz"
test -f "dist/release/ydisks-xianyu-helper-linux-arm64-${{ needs.prepare.outputs.app_version }}.tar.gz"
test -f "dist/release/Ydisks-Xianyu-Helper-Setup.exe"
test -f "dist/release/Ydisks-Xianyu-Helper-${{ needs.prepare.outputs.app_version }}-binaries.zip"
test -f "dist/release/Ydisks-Xianyu-Helper-${{ needs.prepare.outputs.app_version }}-arm64.pkg"
test -f "dist/release/Ydisks-Xianyu-Helper-${{ needs.prepare.outputs.app_version }}-amd64.pkg"
(
cd dist/release
sha256sum * > SHA256SUMS
)
- name: 创建或更新 GitHub Release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
RELEASE_VERSION: ${{ needs.prepare.outputs.app_version }}
run: |
set -Eeuo pipefail
mapfile -t release_files < <(find dist/release -maxdepth 1 -type f -print | sort)
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
gh release upload "$GITHUB_REF_NAME" "${release_files[@]}" --clobber
else
gh release create "$GITHUB_REF_NAME" "${release_files[@]}" \
--verify-tag \
--generate-notes \
--title "Ydisks 闲鱼助手 $RELEASE_VERSION"
fi
+107 -5
View File
@@ -5,6 +5,8 @@ on:
branches:
- main
- codex/desktop-packaging
tags:
- 'v*.*.*'
workflow_dispatch:
permissions:
@@ -16,8 +18,53 @@ concurrency:
cancel-in-progress: true
jobs:
verify:
name: Docker 发布测试门禁
runs-on: ubuntu-24.04
steps:
- name: 校验版本标签
if: startsWith(github.ref, 'refs/tags/')
shell: bash
run: |
set -Eeuo pipefail
if [[ ! "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "版本标签必须符合 v1.2.3 格式:$GITHUB_REF_NAME" >&2
exit 1
fi
- name: 检出代码
uses: actions/checkout@v6
- name: 配置 Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- name: 配置 Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: 验证前端
shell: bash
run: |
set -Eeuo pipefail
npm ci --prefix frontend
npm run typecheck --prefix frontend
npm test --prefix frontend
npm run build --prefix frontend
- name: 验证 Go 服务
run: |
go vet ./...
go test ./...
build:
name: 构建镜像 (${{ matrix.arch }})
needs: verify
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
@@ -57,12 +104,17 @@ jobs:
go-version-file: go.mod
cache: true
- name: 缓存 Docker Chromium runtime
- name: 配置 Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: 恢复 Docker Chromium runtime 缓存
id: cache-docker-playwright
uses: actions/cache@v5
uses: actions/cache/restore@v5
with:
path: .docker/playwright-runtime/${{ matrix.arch }}
key: ydisks-playwright-runtime-v6-docker-${{ matrix.arch }}-${{ hashFiles('go.mod', 'go.sum') }}
key: ydisks-playwright-runtime-v6-docker-${{ matrix.arch }}-${{ matrix.playwright_platform }}-${{ hashFiles('go.mod', 'go.sum', 'cmd/browser-install/**') }}
- name: 准备 Docker Chromium runtime
if: steps.cache-docker-playwright.outputs.cache-hit != 'true'
@@ -92,11 +144,18 @@ jobs:
chromium_path="$(find "$runtime_dir/playwright-browsers" -type f \
\( -name chrome -o -name headless_shell -o -name chrome-headless-shell \) -perm -111 -print -quit)"
test -n "$chromium_path"
chromium_revision="$(RUNTIME_SPEC="$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium").revision)')"
headless_revision="$(RUNTIME_SPEC="$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium-headless-shell").revision)')"
chromium_revision="$(RUNTIME_SPEC="$PWD/$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium").revision)')"
headless_revision="$(RUNTIME_SPEC="$PWD/$runtime_dir/playwright-driver/package/browsers.json" node -e 'const b=require(process.env.RUNTIME_SPEC).browsers; console.log(b.find(x=>x.name==="chromium-headless-shell").revision)')"
test -d "$runtime_dir/playwright-browsers/chromium-$chromium_revision"
test -d "$runtime_dir/playwright-browsers/chromium_headless_shell-$headless_revision"
- name: 保存 Docker Chromium runtime 缓存
if: steps.cache-docker-playwright.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: .docker/playwright-runtime/${{ matrix.arch }}
key: ${{ steps.cache-docker-playwright.outputs.cache-primary-key }}
- name: 配置 Docker Buildx
uses: docker/setup-buildx-action@v4
@@ -125,6 +184,48 @@ jobs:
provenance: mode=max
sbom: true
- name: 验证待发布镜像中的 Chromium 与服务
shell: bash
env:
IMAGE_NAME: ${{ steps.image.outputs.name }}
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
run: |
set -Eeuo pipefail
image_ref="$IMAGE_NAME@$IMAGE_DIGEST"
docker pull "$image_ref"
docker run --rm --entrypoint sh "$image_ref" -ec '
chromium_path="$(find /ms-playwright/chromium-* -type f \
-name chrome -perm -111 -print -quit)"
test -n "$chromium_path"
timeout 45 "$chromium_path" \
--headless --no-sandbox --disable-gpu --disable-dev-shm-usage \
--dump-dom about:blank | grep -q "<html"
'
container_id="$(docker run -d -p 127.0.0.1::59188 "$image_ref")"
cleanup() {
docker logs "$container_id" || true
docker rm -f "$container_id" >/dev/null 2>&1 || true
}
trap cleanup EXIT
host_port="$(docker port "$container_id" 59188/tcp | sed -n 's/.*://p' | head -n 1)"
test -n "$host_port"
for attempt in $(seq 1 60); do
if health="$(curl --fail --silent --show-error "http://127.0.0.1:$host_port/health" 2>/dev/null)"; then
printf '%s' "$health" | grep -q '"status":"ok"'
printf '%s' "$health" | grep -q '"database":"ok"'
exit 0
fi
if ! docker inspect -f '{{.State.Running}}' "$container_id" | grep -q true; then
echo '待发布镜像中的服务提前退出。' >&2
exit 1
fi
sleep 1
done
echo '待发布镜像未能在 60 秒内通过健康检查。' >&2
exit 1
- name: 保存镜像摘要
shell: bash
env:
@@ -175,6 +276,7 @@ jobs:
with:
images: ${{ steps.image.outputs.name }}
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long