完善版本发布流程并处理会话失效场景

This commit is contained in:
Christ committed 2026-08-13 20:04:45 +08:00
1 parent 36798dcced
commit 1833020caf
52 files changed
+1129 -265

No files matched your search

+31 -72
View File
@@ -5,10 +5,13 @@ on:
branches:
- main
- dev
- codex/desktop-packaging
tags:
- 'v*.*.*'
workflow_dispatch:
workflow_call:
inputs:
app_version:
description: 正式发布版本号(不含 v)
required: true
type: string
permissions:
contents: read
@@ -23,22 +26,28 @@ jobs:
runs-on: ubuntu-24.04
outputs:
app_version: ${{ steps.version.outputs.app_version }}
build_version: ${{ steps.version.outputs.build_version }}
build_time: ${{ steps.version.outputs.build_time }}
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}"
if [ -n "${{ inputs.app_version }}" ]; then
app_version="${{ inputs.app_version }}"
build_version="$app_version"
else
app_version="0.0.0-${GITHUB_RUN_NUMBER}"
app_version="0.0.${GITHUB_RUN_NUMBER}"
build_version="${GITHUB_REF_NAME}-${GITHUB_SHA::12}"
fi
if [[ ! "$app_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "安装包版本必须符合 1.2.3 格式:$app_version" >&2
exit 1
fi
echo "app_version=$app_version" >> "$GITHUB_OUTPUT"
echo "build_version=$build_version" >> "$GITHUB_OUTPUT"
echo "build_time=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
linux:
name: Linux 安装包 (${{ matrix.arch }})
@@ -46,6 +55,8 @@ jobs:
runs-on: ${{ matrix.runner }}
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
BUILD_VERSION: ${{ needs.prepare.outputs.build_version }}
BUILD_TIME: ${{ needs.prepare.outputs.build_time }}
strategy:
fail-fast: false
matrix:
@@ -84,7 +95,8 @@ jobs:
run: |
package_dir="dist/ydisks-xianyu-helper-linux-${GOARCH}"
mkdir -p "$package_dir"
go build -trimpath -ldflags='-s -w' -o "$package_dir/xianyu-server" ./cmd/server
version_ldflags="-s -w -X xianyu-go/internal/version.Version=$BUILD_VERSION -X xianyu-go/internal/version.Commit=$GITHUB_SHA -X xianyu-go/internal/version.BuildTime=$BUILD_TIME"
go build -trimpath -ldflags="$version_ldflags" -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 缓存
@@ -175,6 +187,8 @@ jobs:
runs-on: windows-latest
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
BUILD_VERSION: ${{ needs.prepare.outputs.build_version }}
BUILD_TIME: ${{ needs.prepare.outputs.build_time }}
steps:
- name: 检出代码
uses: actions/checkout@v6
@@ -225,7 +239,8 @@ jobs:
run: |
& packaging/windows/build-resources.ps1
New-Item -ItemType Directory -Force -Path dist/windows | Out-Null
go build -trimpath -ldflags "-s -w" -o dist/windows/xianyu-server.exe ./cmd/server
$versionLdflags = "-s -w -X xianyu-go/internal/version.Version=$env:BUILD_VERSION -X xianyu-go/internal/version.Commit=$env:GITHUB_SHA -X xianyu-go/internal/version.BuildTime=$env:BUILD_TIME"
go build -trimpath -ldflags $versionLdflags -o dist/windows/xianyu-server.exe ./cmd/server
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
@@ -584,6 +599,8 @@ jobs:
runs-on: macos-14
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
BUILD_VERSION: ${{ needs.prepare.outputs.build_version }}
BUILD_TIME: ${{ needs.prepare.outputs.build_time }}
steps:
- name: 检出代码
uses: actions/checkout@v6
@@ -610,8 +627,9 @@ jobs:
- name: 编译 macOS 桌面程序
run: |
mkdir -p dist/macos/arm64 dist/macos/amd64
version_ldflags="-s -w -X xianyu-go/internal/version.Version=$BUILD_VERSION -X xianyu-go/internal/version.Commit=$GITHUB_SHA -X xianyu-go/internal/version.BuildTime=$BUILD_TIME"
for arch in arm64 amd64; do
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/xianyu-server" ./cmd/server
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags="$version_ldflags" -o "dist/macos/$arch/xianyu-server" ./cmd/server
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/browser-install" ./cmd/browser-install
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/xianyu-tray" ./cmd/tray
done
@@ -736,62 +754,3 @@ 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 }}-arm64.pkg"
test -f "dist/release/Ydisks-Xianyu-Helper-${{ needs.prepare.outputs.app_version }}-amd64.pkg"
test "$(find dist/release -maxdepth 1 -type f | wc -l)" -eq 5
test -z "$(find dist/release -maxdepth 1 -type f -name '*.zip' -print -quit)"
(
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
while IFS= read -r asset_name; do
case "$asset_name" in
Ydisks-Xianyu-Helper-*-binaries.zip)
gh release delete-asset "$GITHUB_REF_NAME" "$asset_name" --yes
;;
esac
done < <(gh release view "$GITHUB_REF_NAME" --json assets --jq '.assets[].name')
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
+28 -15
View File
@@ -4,10 +4,14 @@ on:
push:
branches:
- main
- codex/desktop-packaging
tags:
- 'v*.*.*'
- dev
workflow_dispatch:
workflow_call:
inputs:
app_version:
description: 正式发布版本号(不含 v)
required: true
type: string
permissions:
contents: read
@@ -21,17 +25,26 @@ jobs:
verify:
name: Docker 发布测试门禁
runs-on: ubuntu-24.04
outputs:
app_version: ${{ steps.version.outputs.app_version }}
build_time: ${{ steps.version.outputs.build_time }}
steps:
- name: 校验版本标签
if: startsWith(github.ref, 'refs/tags/')
- name: 准备构建版本
id: version
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
if [ -n "${{ inputs.app_version }}" ]; then
app_version="${{ inputs.app_version }}"
else
app_version="${GITHUB_REF_NAME}-${GITHUB_SHA::12}"
fi
if [ -n "${{ inputs.app_version }}" ] && [[ ! "$app_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "正式版本必须符合 1.2.3 格式:$app_version" >&2
exit 1
fi
echo "app_version=$app_version" >> "$GITHUB_OUTPUT"
echo "build_time=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
- name: 检出代码
uses: actions/checkout@v6
@@ -178,6 +191,10 @@ jobs:
context: .
file: Dockerfile.debian13
platforms: ${{ matrix.platform }}
build-args: |
APP_VERSION=${{ needs.verify.outputs.app_version }}
VCS_REF=${{ github.sha }}
BUILD_TIME=${{ needs.verify.outputs.build_time }}
outputs: type=image,name=${{ steps.image.outputs.name }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=ydisks-docker-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=ydisks-docker-${{ matrix.arch }}
@@ -241,10 +258,11 @@ jobs:
name: ydisks-docker-digest-${{ matrix.arch }}
path: dist/digests/*
if-no-files-found: error
retention-days: 1
retention-days: 30
publish:
name: 合并多架构镜像
if: inputs.app_version == ''
needs: build
runs-on: ubuntu-24.04
steps:
@@ -276,14 +294,9 @@ 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
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=desktop-packaging,enable=${{ github.ref == 'refs/heads/codex/desktop-packaging' }}
type=raw,value=alpha,enable=${{ github.ref == 'refs/heads/codex/desktop-packaging' }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
- name: 创建并推送多架构 manifest
shell: bash
+149
View File
@@ -0,0 +1,149 @@
name: 发布正式版本
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
packages: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare:
name: 校验正式版本
runs-on: ubuntu-24.04
outputs:
app_version: ${{ steps.version.outputs.app_version }}
steps:
- name: 检出完整 Git 历史
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 校验标签、来源与版本顺序
id: version
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
git fetch origin main --no-tags
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "正式版本标签必须指向 main 已包含的提交。" >&2
exit 1
fi
newest_tag="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)"
if [ "$newest_tag" != "$GITHUB_REF_NAME" ]; then
echo "拒绝用旧版本 $GITHUB_REF_NAME 覆盖 latest;当前最高版本是 $newest_tag。" >&2
exit 1
fi
echo "app_version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
desktop:
name: 构建桌面端安装包
needs: prepare
uses: ./.github/workflows/desktop-cd.yml
with:
app_version: ${{ needs.prepare.outputs.app_version }}
secrets: inherit
docker:
name: 构建 Docker 镜像
needs: prepare
uses: ./.github/workflows/docker-publish.yml
with:
app_version: ${{ needs.prepare.outputs.app_version }}
secrets: inherit
publish:
name: 审批并发布正式版本
needs:
- prepare
- desktop
- docker
runs-on: ubuntu-24.04
environment:
name: production-release
steps:
- name: 下载全部构建产物
uses: actions/download-artifact@v8
with:
pattern: ydisks-*
path: dist/artifacts
merge-multiple: true
- name: 校验桌面产物并生成校验和
shell: bash
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
run: |
set -Eeuo pipefail
mkdir -p dist/release dist/digests
find dist/artifacts -maxdepth 1 -type f -name '*.tar.gz' -exec cp {} dist/release/ \;
find dist/artifacts -maxdepth 1 -type f -name '*.exe' -exec cp {} dist/release/ \;
find dist/artifacts -maxdepth 1 -type f -name '*.pkg' -exec cp {} dist/release/ \;
find dist/artifacts -maxdepth 1 -type f -regex '.*/[0-9a-f]\{64\}' -exec cp {} dist/digests/ \;
test -f "dist/release/ydisks-xianyu-helper-linux-amd64-$APP_VERSION.tar.gz"
test -f "dist/release/ydisks-xianyu-helper-linux-arm64-$APP_VERSION.tar.gz"
test -f "dist/release/Ydisks-Xianyu-Helper-Setup.exe"
test -f "dist/release/Ydisks-Xianyu-Helper-$APP_VERSION-arm64.pkg"
test -f "dist/release/Ydisks-Xianyu-Helper-$APP_VERSION-amd64.pkg"
test "$(find dist/release -maxdepth 1 -type f | wc -l)" -eq 5
test "$(find dist/digests -maxdepth 1 -type f | wc -l)" -eq 2
(cd dist/release && sha256sum * > SHA256SUMS)
- name: 配置 Docker Buildx
uses: docker/setup-buildx-action@v4
- name: 登录 GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 发布正式 Docker manifest
shell: bash
env:
APP_VERSION: ${{ needs.prepare.outputs.app_version }}
run: |
set -Eeuo pipefail
image_name="ghcr.io/${GITHUB_REPOSITORY,,}"
minor_version="${APP_VERSION%.*}"
digest_args=()
while IFS= read -r digest_file; do
digest_args+=("$image_name@sha256:$(basename "$digest_file")")
done < <(find dist/digests -maxdepth 1 -type f -print | sort)
docker buildx imagetools create \
--tag "$image_name:$GITHUB_REF_NAME" \
--tag "$image_name:$APP_VERSION" \
--tag "$image_name:$minor_version" \
--tag "$image_name:latest" \
--tag "$image_name:sha-$GITHUB_SHA" \
"${digest_args[@]}"
docker buildx imagetools inspect "$image_name:$GITHUB_REF_NAME"
docker buildx imagetools inspect "$image_name:latest"
- name: 创建或更新 GitHub Release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
APP_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 闲鱼助手 $APP_VERSION"
fi