Files
ogame-vue-ts/.github/workflows/build.yml
coolxitech 37862ae7ac chore(build): 优化多平台构建流程并更新依赖
- 更新 GitHub Actions 工作流名称,明确区分服务端与客户端构建
- 修改 Go 服务端构建任务命名及输出 artifact 名称
- 升级 Electron 构建环境从 Bun 到 Node.js 并调整相关指令
- 调整构建脚本以适配 npm 和标准 Electron 打包命令
- 增加 Debian 包支持并扩展上传安装包的路径规则
- 改进版本号提取逻辑,确保正确读取 package.json 中的版本
- 统一使用较旧但稳定的 GitHub Actions 版本以提高可靠性
2025-12-14 12:15:45 +08:00

121 lines
3.3 KiB
YAML

name: 构建多平台程序 (Go Server & Electron Client)
on:
push:
branches:
- main
jobs:
# 1. 构建 Go 服务端 (交叉编译)
build-server:
name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }})
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: windows
goarch: amd64
executable: ogame-server-win-amd64.exe
- goos: linux
goarch: amd64
executable: ogame-server-linux-amd64
- goos: linux
goarch: arm64
executable: ogame-server-linux-arm64
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Compile Server
shell: bash
run: |
[ -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: server-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ matrix.executable }}
# 2. 构建 Electron 客户端 (Node.js 环境)
build-electron:
name: Build Electron (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
platform: win
- os: macos-latest
platform: mac
- os: ubuntu-latest
platform: linux
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm' # 如果用 yarn 或 pnpm 请修改此处
- name: Install Dependencies
run: npm install
- name: Build Vue Frontend
run: npm run build
- name: Build Electron App
# 确保 package.json 里的脚本能接收参数,或直接运行打包命令
run: npm run build:electron -- --${{ matrix.platform }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Electron Artifact
uses: actions/upload-artifact@v4
with:
name: electron-${{ matrix.platform }}
# 指向你要求的 pkg 目录
path: |
pkg/*.exe
pkg/*.dmg
pkg/*.AppImage
pkg/*.zip
pkg/*.deb
# 3. 发布 Release
release:
needs: [build-server, build-electron]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./release-assets
- name: Get Version from package.json
id: get_version
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:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}