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 }}