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