From 37862ae7ac9ef6211e00dcb9bb863c8531745f5e Mon Sep 17 00:00:00 2001 From: coolxitech Date: Sun, 14 Dec 2025 12:15:45 +0800 Subject: [PATCH] =?UTF-8?q?chore(build):=20=E4=BC=98=E5=8C=96=E5=A4=9A?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 GitHub Actions 工作流名称,明确区分服务端与客户端构建 - 修改 Go 服务端构建任务命名及输出 artifact 名称 - 升级 Electron 构建环境从 Bun 到 Node.js 并调整相关指令 - 调整构建脚本以适配 npm 和标准 Electron 打包命令 - 增加 Debian 包支持并扩展上传安装包的路径规则 - 改进版本号提取逻辑,确保正确读取 package.json 中的版本 - 统一使用较旧但稳定的 GitHub Actions 版本以提高可靠性 --- .github/workflows/build.yml | 54 ++++++++++++++++++++----------------- package.json | 2 +- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e646e2e..f4040ac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: 构建多平台可执行程序 +name: 构建多平台程序 (Go Server & Electron Client) on: push: @@ -6,16 +6,16 @@ on: - main jobs: - # 任务 1: 专门构建 Go 服务端程序 + # 1. 构建 Go 服务端 (交叉编译) build-server: - name: Build Go Server for ${{ matrix.goos }}-${{ matrix.goarch }} + name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }}) runs-on: ubuntu-latest strategy: matrix: include: - goos: windows goarch: amd64 - executable: ogame-server-windows-amd64.exe + executable: ogame-server-win-amd64.exe - goos: linux goarch: amd64 executable: ogame-server-linux-amd64 @@ -24,29 +24,31 @@ jobs: executable: ogame-server-linux-arm64 steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 - name: Setup Go - uses: actions/setup-go@v6 + uses: actions/setup-go@v5 with: - go-version: '1.25' + go-version: '1.21' - name: Compile Server + shell: bash run: | - if [ ! -f go.mod ]; then go mod init ogame-app; fi + [ -f go.mod ] || go mod init ogame-app go mod tidy GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go - name: Upload Server Artifact uses: actions/upload-artifact@v4 with: - name: ${{ matrix.executable }} + name: server-${{ matrix.goos }}-${{ matrix.goarch }} path: ${{ matrix.executable }} - # 任务 2: 专门构建 Electron 客户端 + # 2. 构建 Electron 客户端 (Node.js 环境) build-electron: - name: Build Electron for ${{ matrix.os }} + name: Build Electron (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: include: - os: windows-latest @@ -57,21 +59,23 @@ jobs: platform: linux steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 - - name: Setup Bun - uses: oven-sh/setup-bun@v2 + - name: Setup Node.js + uses: actions/setup-node@v4 with: - bun-version: latest + node-version: 20 + cache: 'npm' # 如果用 yarn 或 pnpm 请修改此处 - name: Install Dependencies - run: bun install + run: npm install - name: Build Vue Frontend - run: bun run build + run: npm run build - name: Build Electron App - run: bun run build:electron --${{ matrix.platform }} + # 确保 package.json 里的脚本能接收参数,或直接运行打包命令 + run: npm run build:electron -- --${{ matrix.platform }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -79,14 +83,15 @@ jobs: uses: actions/upload-artifact@v4 with: name: electron-${{ matrix.platform }} - # 仅上传 pkg 目录下的安装包产物 + # 指向你要求的 pkg 目录 path: | pkg/*.exe pkg/*.dmg pkg/*.AppImage pkg/*.zip + pkg/*.deb - # 任务 3: 汇总发布 + # 3. 发布 Release release: needs: [build-server, build-electron] runs-on: ubuntu-latest @@ -98,19 +103,18 @@ jobs: with: path: ./release-assets - - name: Get version + - name: Get Version from package.json id: get_version - run: | - # 假设版本号仍在 package.json 中 - echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT shell: bash + run: | + VERSION=$(node -p "require('./package.json').version") + echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT - name: Create GitHub Release uses: softprops/action-gh-release@v1 with: tag_name: ${{ steps.get_version.outputs.VERSION }} name: Release ${{ steps.get_version.outputs.VERSION }} - # 收集所有子目录下的文件 files: ./release-assets/**/* generate_release_notes: true env: diff --git a/package.json b/package.json index dabf9ac..6e212ef 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dev": "vite --port 25121", "build": "vue-tsc -b && vite build && node update-build-date.js", "preview": "vite preview", - "build:electron": "pnpm build && electron-builder" + "build:electron": "npm build && electron-builder" }, "dependencies": { "@tailwindcss/vite": "^4.1.17",