Files
ogame-vue-ts/.github/workflows/build.yml
coolxitech e4f7b20882 refactor(server): 将后端从 Node.js 迁移至 Go
- 移除对 Express 和相关中间件的依赖
- 新增 Go 编写的 HTTP 服务,支持嵌入前端资源
- 更新构建流程以使用 Go 编译跨平台可执行文件
- 配置 GitHub Actions 工作流以适应新的构建方式
- 实现自动打开浏览器和显示局域网访问地址功能
- 清理 package.json 中不再需要的脚本和依赖项
- 更新 pnpm-lock.yaml 文件以反映依赖变化
2025-12-13 15:50:41 +08:00

103 lines
2.8 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: 构建多平台可执行程序
on:
push:
branches:
- main
jobs:
build:
name: Build for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-latest
executable: ogame-windows.exe
goos: windows
goarch: amd64
- os: ubuntu-latest
executable: ogame-linux
goos: linux
goarch: amd64
- os: macos-latest
executable: ogame-macos
goos: darwin
goarch: arm64 # 或者 amd64取决于你需要的 Mac 架构
steps:
- uses: actions/checkout@v4
# 1. 设置 Bun 环境构建 Vue
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
# 2. 设置 Go 环境构建后端
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21' # 确保版本支持 //go:embed
- name: Get version
id: get_version
shell: bash
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
- name: Install Dependencies
run: bun install
# 3. 构建前端 Vue 项目 (生成 docs 目录)
- name: Build Vue Frontend
run: bun run build
# 4. 初始化 Go Mod (如果你的仓库里没提交 go.mod)
- name: Go Init
run: |
if [ ! -f go.mod ]; then
go mod init ogame-app
fi
shell: bash
# 5. 使用 Go 编译单文件二进制程序
# 注意:我们将环境变量传给 Go 以进行交叉编译
- name: Compile Single Executable
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-artifact
path: ${{ matrix.executable }}
outputs:
app_version: ${{ steps.get_version.outputs.VERSION }}
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.build.outputs.app_version }}
name: Release ${{ needs.build.outputs.app_version }}
files: |
windows-latest-artifact/ogame-windows.exe
ubuntu-latest-artifact/ogame-linux
macos-latest-artifact/ogame-macos
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}