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 [ -f go.mod ] || go mod init ogame-app go mod tidy GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go - name: Upload 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 uses: actions/upload-artifact@v4 with: name: electron-${{ matrix.platform }} # 仅上传 pkg 下的安装包,忽略 unpacked 目录 path: | pkg/*.exe pkg/*.dmg pkg/*.AppImage pkg/*.zip # 3. 发布 Release release: needs: [ build-server, build-electron ] runs-on: ubuntu-latest permissions: contents: write # 必须确保有写权限 pull-requests: read steps: - uses: actions/checkout@v4 # 1. 获取版本号 - name: Get Version id: get_version shell: bash run: | VERSION=$(node -p "require('./package.json').version") echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT # 2. 创建 Release (先创建,不上传文件) # 这一步能有效避免 404,确保 Release 实体已存在 - name: Create GitHub Release id: create_release uses: softprops/action-gh-release@v1 with: tag_name: ${{ steps.get_version.outputs.VERSION }} name: Release ${{ steps.get_version.outputs.VERSION }} draft: false prerelease: false generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 3. 下载产物并上传到已创建的 Release - name: Download and Upload Assets uses: actions/download-artifact@v4 with: path: ./downloads merge-multiple: true - name: Upload Assets to Release uses: softprops/action-gh-release@v1 with: tag_name: ${{ steps.get_version.outputs.VERSION }} append_body: true # 显式指定文件名,不带版本号 files: | ./downloads/ogame-server-win.exe ./downloads/ogame-server-linux ./downloads/ogame-server-linux-arm64 ./downloads/ogame-Setup.exe ./downloads/*.dmg ./downloads/*.AppImage ./downloads/*.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}