Files
ogame-vue-ts/.github/workflows/build.yml
coolxitech ec77a0656a chore(workflow): 优化构建与发布流程
- 统一可执行文件命名规则,去除架构后缀
- 合并 Node 与 Go 环境设置步骤
- 简化前端与服务端构建流程
- 显式指定 Electron 安装包上传路径
- 优化 Release Assets 下载与合并方式
- 修复版本号获取逻辑并显式声明发布文件类型
- 排除 package.json 文件被误上传至 Release 页面
2025-12-14 12:36:15 +08:00

126 lines
3.6 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.exe
- goos: linux
goarch: amd64
executable: ogame-server-linux
- goos: linux
goarch: arm64
executable: ogame-server-linux-arm64
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node & Go
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Build Frontend & Server
run: |
pnpm install
pnpm run build
[ -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
uses: actions/upload-artifact@v4
with:
name: server-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ matrix.executable }}
# 2. 构建 Electron 客户端
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
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Build Electron
run: |
pnpm install
pnpm run build
pnpm run build:electron --${{ matrix.platform }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload
uses: actions/upload-artifact@v4
with:
name: electron-${{ matrix.platform }}
# 仅上传 pkg 下的安装包,忽略 unpacked 目录
path: |
pkg/*.exe
pkg/*.dmg
pkg/*.AppImage
pkg/*.zip
# 3. 发布 Release
release:
needs: [build-server, build-electron]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ./assets-to-release
merge-multiple: true # 将所有文件平铺在一个目录下
- name: Get Version for Tagging
id: get_version
run: echo "VERSION=v$(node -p "require('./package.json').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 }}
# 核心修复:显式指定要上传的文件后缀,彻底排除 package.json
files: |
./assets-to-release/*.exe
./assets-to-release/*.dmg
./assets-to-release/*.AppImage
./assets-to-release/*.zip
./assets-to-release/ogame-server-*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}