name: 构建多平台程序 (Go Server & Electron Client) on: push: branches: - main jobs: # 1. 构建 Go 服务端 build-server: name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }}) runs-on: ubuntu-latest strategy: matrix: include: - goos: windows goarch: amd64 executable: ogame-server-win.exe - goos: linux goarch: amd64 executable: ogame-server-linux - goos: linux goarch: arm64 executable: ogame-server-linux-arm64 steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v3 with: version: 8 - name: Setup Node & Go uses: actions/setup-node@v4 with: node-version: 20 cache: 'pnpm' - uses: actions/setup-go@v5 with: go-version: '1.21' - name: Build Frontend & Server run: | pnpm install pnpm run build go mod tidy GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go - name: Upload Server Binaries uses: actions/upload-artifact@v4 with: name: server-${{ matrix.goos }}-${{ matrix.goarch }} path: ${{ matrix.executable }} # 2. 构建 Electron 客户端 build-electron: name: Build Electron (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: include: - os: windows-latest platform: win - os: macos-latest platform: mac - os: ubuntu-latest platform: linux steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v3 with: version: 8 - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 cache: 'pnpm' - name: Build Electron run: | pnpm install pnpm run build pnpm run build:electron --${{ matrix.platform }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 【关键点】这里只上传安装包后缀,不上传文件夹 - name: Upload Electron Installers uses: actions/upload-artifact@v4 with: name: electron-${{ matrix.platform }} path: | pkg/*.exe pkg/*.dmg pkg/*.AppImage # 3. 发布 Release release: needs: [ build-server, build-electron ] runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v4 # 1. 获取版本号 - name: Get Version id: get_version run: echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT # 2. 下载所有 Artifact (注意这里会平铺所有文件) - name: Download All Artifacts uses: actions/download-artifact@v4 with: path: ./release-dir merge-multiple: true # 关键:将所有构建出的 .exe, .dmg 平铺到 release-dir 根目录 # 3. 清理不需要的中间产物 (排除 unpacked 等目录) - name: Prepare Assets shell: bash run: | cd ./release-dir # 只保留安装程序后缀,删除所有文件夹和杂质文件 # 这样能确保不上传 electron 产生的 win-unpacked 等目录 find . -maxdepth 1 -type d -not -path '.' -exec rm -rf {} + # 查看一下最终要上传的文件列表,方便调试 ls -R # 4. 上传到 GitHub Release - name: Create and Upload Release uses: softprops/action-gh-release@v1 with: tag_name: ${{ steps.get_version.outputs.VERSION }} name: Release ${{ steps.get_version.outputs.VERSION }} # 核心修复:直接上传目录下的所有安装包,不再手动写死文件名避免 404 files: | ./release-dir/*.exe ./release-dir/*.dmg ./release-dir/*.AppImage ./release-dir/*.zip ./release-dir/server-* ./release-dir/ogame-* generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}