name: 构建多平台可执行程序 on: push: branches: - main jobs: # 任务 1: 专门构建 Go 服务端程序 build-server: name: Build Go Server for ${{ matrix.goos }}-${{ matrix.goarch }} runs-on: ubuntu-latest strategy: matrix: include: - goos: windows goarch: amd64 executable: ogame-server-windows-amd64.exe - goos: linux goarch: amd64 executable: ogame-server-linux-amd64 - goos: linux goarch: arm64 executable: ogame-server-linux-arm64 steps: - uses: actions/checkout@v6 - name: Setup Go uses: actions/setup-go@v6 with: go-version: '1.25' - name: Compile Server run: | if [ ! -f go.mod ]; then go mod init ogame-app; fi go mod tidy GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go - name: Upload Server Artifact uses: actions/upload-artifact@v4 with: name: ${{ matrix.executable }} path: ${{ matrix.executable }} # 任务 2: 专门构建 Electron 客户端 build-electron: name: Build Electron for ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: include: - os: windows-latest platform: win - os: macos-latest platform: mac - os: ubuntu-latest platform: linux steps: - uses: actions/checkout@v6 - name: Setup Bun uses: oven-sh/setup-bun@v2 with: bun-version: latest - name: Install Dependencies run: bun install - name: Build Vue Frontend run: bun run build - name: Build Electron App run: bun run build:electron --${{ matrix.platform }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Upload Electron Artifact uses: actions/upload-artifact@v4 with: name: electron-${{ matrix.platform }} # 仅上传 pkg 目录下的安装包产物 path: | pkg/*.exe pkg/*.dmg pkg/*.AppImage pkg/*.zip # 任务 3: 汇总发布 release: needs: [build-server, build-electron] runs-on: ubuntu-latest permissions: contents: write steps: - name: Download all artifacts uses: actions/download-artifact@v4 with: path: ./release-assets - name: Get version id: get_version run: | # 假设版本号仍在 package.json 中 echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT shell: bash - name: Create GitHub Release uses: softprops/action-gh-release@v1 with: tag_name: ${{ steps.get_version.outputs.VERSION }} name: Release ${{ steps.get_version.outputs.VERSION }} # 收集所有子目录下的文件 files: ./release-assets/**/* generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}