ci(build): 更新构建流程以包含前端资源

- 修改服务器构建步骤以嵌入前端静态资源
- 添加 Node.js 设置和前端依赖安装
- 更新 Electron 构建脚本和输出路径
- 调整 package.json 中的构建命令
- 优化构建注释和版本获取方式
This commit is contained in:
coolxitech
2025-12-14 12:18:56 +08:00
parent 37862ae7ac
commit 9fc76ff6c1
2 changed files with 22 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ on:
- main - main
jobs: jobs:
# 1. 构建 Go 服务端 (交叉编译) # 1. 构建 Go 服务端 (包含前端静态资源)
build-server: build-server:
name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }}) name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }})
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -25,12 +25,26 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.21' go-version: '1.21'
- name: Compile Server # 构建服务端前先构建前端
- name: Install Frontend Dependencies
run: npm install
- name: Build Frontend (for Go Embed)
run: npm run build
- name: Compile Go Server
shell: bash shell: bash
run: | run: |
[ -f go.mod ] || go mod init ogame-app [ -f go.mod ] || go mod init ogame-app
@@ -43,7 +57,7 @@ jobs:
name: server-${{ matrix.goos }}-${{ matrix.goarch }} name: server-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ matrix.executable }} path: ${{ matrix.executable }}
# 2. 构建 Electron 客户端 (Node.js 环境) # 2. 构建 Electron 客户端 (输出到 pkg)
build-electron: build-electron:
name: Build Electron (${{ matrix.os }}) name: Build Electron (${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@@ -65,16 +79,15 @@ jobs:
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 20
cache: 'npm' # 如果用 yarn 或 pnpm 请修改此处 cache: 'npm'
- name: Install Dependencies - name: Install Dependencies
run: npm install run: npm install
- name: Build Vue Frontend - name: Build Frontend (for Electron)
run: npm run build run: npm run build
- name: Build Electron App - name: Build Electron App
# 确保 package.json 里的脚本能接收参数,或直接运行打包命令
run: npm run build:electron -- --${{ matrix.platform }} run: npm run build:electron -- --${{ matrix.platform }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -83,7 +96,6 @@ jobs:
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: electron-${{ matrix.platform }} name: electron-${{ matrix.platform }}
# 指向你要求的 pkg 目录
path: | path: |
pkg/*.exe pkg/*.exe
pkg/*.dmg pkg/*.dmg
@@ -103,7 +115,7 @@ jobs:
with: with:
path: ./release-assets path: ./release-assets
- name: Get Version from package.json - name: Get Version
id: get_version id: get_version
shell: bash shell: bash
run: | run: |

View File

@@ -13,7 +13,8 @@
"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": "npm build && electron-builder" "build:server": "npm run build && go build",
"build:electron": "npm run build && electron-builder"
}, },
"dependencies": { "dependencies": {
"@tailwindcss/vite": "^4.1.17", "@tailwindcss/vite": "^4.1.17",