mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
ci(workflow): 更新构建工作流以支持多架构编译
- 添加对 Linux ARM64 和 macOS Apple Silicon 的支持 - 重命名可执行文件以明确平台和架构 - 更新构建步骤注释和顺序 - 修改上传构件名称以匹配可执行文件 - 调整发布流程以包含新增的架构文件 - 移除冗余的 Go 模块初始化逻辑 - 优化构建脚本中的条件判断结构
This commit is contained in:
59
.github/workflows/build.yml
vendored
59
.github/workflows/build.yml
vendored
@@ -7,39 +7,53 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build for ${{ matrix.os }}
|
name: Build for ${{ matrix.os }} (${{ matrix.goarch }})
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
|
# Windows x64
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
executable: ogame-windows.exe
|
executable: ogame-windows-amd64.exe
|
||||||
goos: windows
|
goos: windows
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
|
# Linux x64
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
executable: ogame-linux
|
executable: ogame-linux-amd64
|
||||||
goos: linux
|
goos: linux
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
|
# Linux ARM64 (如树莓派、高性能 ARM 服务器)
|
||||||
|
- os: ubuntu-latest
|
||||||
|
executable: ogame-linux-arm64
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
# macOS Apple Silicon (M1/M2/M3 芯片)
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
executable: ogame-macos
|
executable: ogame-macos-arm64
|
||||||
goos: darwin
|
goos: darwin
|
||||||
goarch: arm64 # 或者 amd64,取决于你需要的 Mac 架构
|
goarch: arm64
|
||||||
|
# macOS Intel
|
||||||
|
- os: macos-latest
|
||||||
|
executable: ogame-macos-amd64
|
||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
# 1. 设置 Bun 环境构建 Vue
|
# 1. 设置 Bun 环境构建 Vue 前端
|
||||||
- name: Setup Bun
|
- name: Setup Bun
|
||||||
uses: oven-sh/setup-bun@v2
|
uses: oven-sh/setup-bun@v2
|
||||||
with:
|
with:
|
||||||
bun-version: latest
|
bun-version: latest
|
||||||
|
|
||||||
# 2. 设置 Go 环境构建后端
|
# 2. 设置 Go 环境
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.21' # 确保版本支持 //go:embed
|
go-version: '1.21'
|
||||||
|
|
||||||
|
# 3. 获取版本号
|
||||||
- name: Get version
|
- name: Get version
|
||||||
id: get_version
|
id: get_version
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -50,31 +64,28 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: bun install
|
run: bun install
|
||||||
|
|
||||||
# 3. 构建前端 Vue 项目 (生成 docs 目录)
|
# 4. 执行前端打包,生成 docs 目录
|
||||||
- name: Build Vue Frontend
|
- name: Build Vue Frontend
|
||||||
run: bun run build
|
run: bun run build
|
||||||
|
|
||||||
# 4. 初始化 Go Mod (如果你的仓库里没提交 go.mod)
|
# 5. Go 交叉编译
|
||||||
- name: Go Init
|
|
||||||
run: |
|
|
||||||
if [ ! -f go.mod ]; then
|
|
||||||
go mod init ogame-app
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
# 5. 使用 Go 编译单文件二进制程序
|
|
||||||
# 注意:我们将环境变量传给 Go 以进行交叉编译
|
|
||||||
- name: Compile Single Executable
|
- name: Compile Single Executable
|
||||||
env:
|
env:
|
||||||
GOOS: ${{ matrix.goos }}
|
GOOS: ${{ matrix.goos }}
|
||||||
GOARCH: ${{ matrix.goarch }}
|
GOARCH: ${{ matrix.goarch }}
|
||||||
run: |
|
run: |
|
||||||
|
# 初始化 go.mod (如果不存在)
|
||||||
|
if [ ! -f go.mod ]; then
|
||||||
|
go mod init ogame-app
|
||||||
|
fi
|
||||||
|
# 编译命令,保留控制台
|
||||||
go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go
|
go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go
|
||||||
|
|
||||||
|
# 6. 上传构建产物
|
||||||
- name: Upload Artifact
|
- name: Upload Artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.os }}-artifact
|
name: ${{ matrix.executable }}
|
||||||
path: ${{ matrix.executable }}
|
path: ${{ matrix.executable }}
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
@@ -95,9 +106,11 @@ jobs:
|
|||||||
tag_name: ${{ needs.build.outputs.app_version }}
|
tag_name: ${{ needs.build.outputs.app_version }}
|
||||||
name: Release ${{ needs.build.outputs.app_version }}
|
name: Release ${{ needs.build.outputs.app_version }}
|
||||||
files: |
|
files: |
|
||||||
windows-latest-artifact/ogame-windows.exe
|
ogame-windows-amd64.exe/ogame-windows-amd64.exe
|
||||||
ubuntu-latest-artifact/ogame-linux
|
ogame-linux-amd64/ogame-linux-amd64
|
||||||
macos-latest-artifact/ogame-macos
|
ogame-linux-arm64/ogame-linux-arm64
|
||||||
|
ogame-macos-arm64/ogame-macos-arm64
|
||||||
|
ogame-macos-amd64/ogame-macos-amd64
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
Reference in New Issue
Block a user