mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
- 修改服务器构建步骤以嵌入前端静态资源 - 添加 Node.js 设置和前端依赖安装 - 更新 Electron 构建脚本和输出路径 - 调整 package.json 中的构建命令 - 优化构建注释和版本获取方式
133 lines
3.4 KiB
YAML
133 lines
3.4 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 Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
cache: 'npm'
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.21'
|
|
|
|
# 构建服务端前先构建前端
|
|
- name: Install Frontend Dependencies
|
|
run: npm install
|
|
|
|
- name: Build Frontend (for Go Embed)
|
|
run: npm run build
|
|
|
|
- name: Compile Go 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 客户端 (输出到 pkg)
|
|
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'
|
|
|
|
- name: Install Dependencies
|
|
run: npm install
|
|
|
|
- name: Build Frontend (for Electron)
|
|
run: npm run build
|
|
|
|
- name: Build Electron App
|
|
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 }}
|
|
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
|
|
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 }} |