chore(build): 优化多平台构建流程并更新依赖

- 更新 GitHub Actions 工作流名称,明确区分服务端与客户端构建
- 修改 Go 服务端构建任务命名及输出 artifact 名称
- 升级 Electron 构建环境从 Bun 到 Node.js 并调整相关指令
- 调整构建脚本以适配 npm 和标准 Electron 打包命令
- 增加 Debian 包支持并扩展上传安装包的路径规则
- 改进版本号提取逻辑,确保正确读取 package.json 中的版本
- 统一使用较旧但稳定的 GitHub Actions 版本以提高可靠性
This commit is contained in:
coolxitech
2025-12-14 12:15:45 +08:00
parent fef38d40ee
commit 37862ae7ac
2 changed files with 30 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
name: 构建多平台可执行程序 name: 构建多平台程序 (Go Server & Electron Client)
on: on:
push: push:
@@ -6,16 +6,16 @@ on:
- main - main
jobs: jobs:
# 任务 1: 专门构建 Go 服务端程序 # 1. 构建 Go 服务端 (交叉编译)
build-server: build-server:
name: Build Go Server for ${{ matrix.goos }}-${{ matrix.goarch }} name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
include: include:
- goos: windows - goos: windows
goarch: amd64 goarch: amd64
executable: ogame-server-windows-amd64.exe executable: ogame-server-win-amd64.exe
- goos: linux - goos: linux
goarch: amd64 goarch: amd64
executable: ogame-server-linux-amd64 executable: ogame-server-linux-amd64
@@ -24,29 +24,31 @@ jobs:
executable: ogame-server-linux-arm64 executable: ogame-server-linux-arm64
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v4
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v6 uses: actions/setup-go@v5
with: with:
go-version: '1.25' go-version: '1.21'
- name: Compile Server - name: Compile Server
shell: bash
run: | run: |
if [ ! -f go.mod ]; then go mod init ogame-app; fi [ -f go.mod ] || go mod init ogame-app
go mod tidy go mod tidy
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go
- name: Upload Server Artifact - name: Upload Server Artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ matrix.executable }} name: server-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ matrix.executable }} path: ${{ matrix.executable }}
# 任务 2: 专门构建 Electron 客户端 # 2. 构建 Electron 客户端 (Node.js 环境)
build-electron: build-electron:
name: Build Electron for ${{ matrix.os }} name: Build Electron (${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false
matrix: matrix:
include: include:
- os: windows-latest - os: windows-latest
@@ -57,21 +59,23 @@ jobs:
platform: linux platform: linux
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v4
- name: Setup Bun - name: Setup Node.js
uses: oven-sh/setup-bun@v2 uses: actions/setup-node@v4
with: with:
bun-version: latest node-version: 20
cache: 'npm' # 如果用 yarn 或 pnpm 请修改此处
- name: Install Dependencies - name: Install Dependencies
run: bun install run: npm install
- name: Build Vue Frontend - name: Build Vue Frontend
run: bun run build run: npm run build
- name: Build Electron App - name: Build Electron App
run: bun run build:electron --${{ matrix.platform }} # 确保 package.json 里的脚本能接收参数,或直接运行打包命令
run: npm run build:electron -- --${{ matrix.platform }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -79,14 +83,15 @@ jobs:
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: electron-${{ matrix.platform }} name: electron-${{ matrix.platform }}
# 仅上传 pkg 目录下的安装包产物 # 指向你要求的 pkg 目录
path: | path: |
pkg/*.exe pkg/*.exe
pkg/*.dmg pkg/*.dmg
pkg/*.AppImage pkg/*.AppImage
pkg/*.zip pkg/*.zip
pkg/*.deb
# 任务 3: 汇总发布 # 3. 发布 Release
release: release:
needs: [build-server, build-electron] needs: [build-server, build-electron]
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -98,19 +103,18 @@ jobs:
with: with:
path: ./release-assets path: ./release-assets
- name: Get version - name: Get Version from package.json
id: get_version id: get_version
run: |
# 假设版本号仍在 package.json 中
echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
shell: bash shell: bash
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
- name: Create GitHub Release - name: Create GitHub Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
tag_name: ${{ steps.get_version.outputs.VERSION }} tag_name: ${{ steps.get_version.outputs.VERSION }}
name: Release ${{ steps.get_version.outputs.VERSION }} name: Release ${{ steps.get_version.outputs.VERSION }}
# 收集所有子目录下的文件
files: ./release-assets/**/* files: ./release-assets/**/*
generate_release_notes: true generate_release_notes: true
env: env:

View File

@@ -13,7 +13,7 @@
"dev": "vite --port 25121", "dev": "vite --port 25121",
"build": "vue-tsc -b && vite build && node update-build-date.js", "build": "vue-tsc -b && vite build && node update-build-date.js",
"preview": "vite preview", "preview": "vite preview",
"build:electron": "pnpm build && electron-builder" "build:electron": "npm build && electron-builder"
}, },
"dependencies": { "dependencies": {
"@tailwindcss/vite": "^4.1.17", "@tailwindcss/vite": "^4.1.17",