From 9c4cfa02d8bf5cf3656660e17b79293b7eb24ad6 Mon Sep 17 00:00:00 2001 From: coolxitech Date: Sat, 13 Dec 2025 17:00:24 +0800 Subject: [PATCH] =?UTF-8?q?ci(workflow):=20=E6=9B=B4=E6=96=B0=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=B7=A5=E4=BD=9C=E6=B5=81=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E6=9E=B6=E6=9E=84=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加对 Linux ARM64 和 macOS Apple Silicon 的支持 - 重命名可执行文件以明确平台和架构 - 更新构建步骤注释和顺序 - 修改上传构件名称以匹配可执行文件 - 调整发布流程以包含新增的架构文件 - 移除冗余的 Go 模块初始化逻辑 - 优化构建脚本中的条件判断结构 --- .github/workflows/build.yml | 59 ++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fdec353..e5457ab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,39 +7,53 @@ on: jobs: build: - name: Build for ${{ matrix.os }} + name: Build for ${{ matrix.os }} (${{ matrix.goarch }}) runs-on: ${{ matrix.os }} strategy: matrix: include: + # Windows x64 - os: windows-latest - executable: ogame-windows.exe + executable: ogame-windows-amd64.exe goos: windows goarch: amd64 + # Linux x64 - os: ubuntu-latest - executable: ogame-linux + executable: ogame-linux-amd64 goos: linux 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 - executable: ogame-macos + executable: ogame-macos-arm64 goos: darwin - goarch: arm64 # 或者 amd64,取决于你需要的 Mac 架构 + goarch: arm64 + # macOS Intel + - os: macos-latest + executable: ogame-macos-amd64 + goos: darwin + goarch: amd64 steps: - uses: actions/checkout@v4 - # 1. 设置 Bun 环境构建 Vue + # 1. 设置 Bun 环境构建 Vue 前端 - name: Setup Bun uses: oven-sh/setup-bun@v2 with: bun-version: latest - # 2. 设置 Go 环境构建后端 + # 2. 设置 Go 环境 - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.21' # 确保版本支持 //go:embed + go-version: '1.21' + # 3. 获取版本号 - name: Get version id: get_version shell: bash @@ -50,31 +64,28 @@ jobs: - name: Install Dependencies run: bun install - # 3. 构建前端 Vue 项目 (生成 docs 目录) + # 4. 执行前端打包,生成 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 以进行交叉编译 + # 5. Go 交叉编译 - name: Compile Single Executable env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} run: | + # 初始化 go.mod (如果不存在) + if [ ! -f go.mod ]; then + go mod init ogame-app + fi + # 编译命令,保留控制台 go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go + # 6. 上传构建产物 - name: Upload Artifact uses: actions/upload-artifact@v4 with: - name: ${{ matrix.os }}-artifact + name: ${{ matrix.executable }} path: ${{ matrix.executable }} outputs: @@ -95,9 +106,11 @@ jobs: 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 + ogame-windows-amd64.exe/ogame-windows-amd64.exe + ogame-linux-amd64/ogame-linux-amd64 + ogame-linux-arm64/ogame-linux-arm64 + ogame-macos-arm64/ogame-macos-arm64 + ogame-macos-amd64/ogame-macos-amd64 generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file