chore(workflow): 优化构建与发布流程

- 统一可执行文件命名规则,去除架构后缀
- 合并 Node 与 Go 环境设置步骤
- 简化前端与服务端构建流程
- 显式指定 Electron 安装包上传路径
- 优化 Release Assets 下载与合并方式
- 修复版本号获取逻辑并显式声明发布文件类型
- 排除 package.json 文件被误上传至 Release 页面
This commit is contained in:
coolxitech
2025-12-14 12:36:15 +08:00
parent 10071f5e54
commit ec77a0656a

View File

@@ -15,10 +15,10 @@ jobs:
include: include:
- goos: windows - goos: windows
goarch: amd64 goarch: amd64
executable: ogame-server-win-amd64.exe executable: ogame-server-win.exe
- goos: linux - goos: linux
goarch: amd64 goarch: amd64
executable: ogame-server-linux-amd64 executable: ogame-server-linux
- goos: linux - goos: linux
goarch: arm64 goarch: arm64
executable: ogame-server-linux-arm64 executable: ogame-server-linux-arm64
@@ -27,26 +27,22 @@ jobs:
- uses: pnpm/action-setup@v3 - uses: pnpm/action-setup@v3
with: with:
version: 8 version: 8
- name: Setup Node.js - name: Setup Node & Go
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 20
cache: 'pnpm' cache: 'pnpm'
- name: Setup Go - uses: actions/setup-go@v5
uses: actions/setup-go@v5
with: with:
go-version: '1.21' go-version: '1.21'
- name: Install & Build Frontend - name: Build Frontend & Server
run: | run: |
pnpm install pnpm install
pnpm run build pnpm run build
- name: Compile Go Server
shell: bash
run: |
[ -f go.mod ] || go mod init ogame-app [ -f go.mod ] || go mod init ogame-app
go mod tidy go mod tidy
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go
- name: Upload Server Artifact - name: Upload
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: server-${{ matrix.goos }}-${{ matrix.goarch }} name: server-${{ matrix.goos }}-${{ matrix.goarch }}
@@ -71,23 +67,28 @@ jobs:
- uses: pnpm/action-setup@v3 - uses: pnpm/action-setup@v3
with: with:
version: 8 version: 8
- name: Setup Node.js - name: Setup Node
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: 20 node-version: 20
cache: 'pnpm' cache: 'pnpm'
- name: Install & Build Electron - name: Build Electron
run: | run: |
pnpm install pnpm install
pnpm run build pnpm run build
pnpm run build:electron --${{ matrix.platform }} pnpm run build:electron --${{ matrix.platform }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Electron Artifact - name: Upload
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: electron-${{ matrix.platform }} name: electron-${{ matrix.platform }}
path: pkg/ # 仅上传 pkg 下的安装包,忽略 unpacked 目录
path: |
pkg/*.exe
pkg/*.dmg
pkg/*.AppImage
pkg/*.zip
# 3. 发布 Release # 3. 发布 Release
release: release:
@@ -96,29 +97,30 @@ jobs:
permissions: permissions:
contents: write contents: write
steps: steps:
# 必须先检出代码,否则 release 步骤里没有 package.json 可供读取版本号
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Download all artifacts - name: Download Artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
path: ./release-assets path: ./assets-to-release
merge-multiple: true # 将所有文件平铺在一个目录下
- name: Get Version - name: Get Version for Tagging
id: get_version id: get_version
shell: bash run: echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
run: |
# 确保在项目根目录下执行
VERSION=$(node -e "console.log(require('./package.json').version)")
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
- name: Create GitHub Release - name: Create GitHub Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
tag_name: ${{ steps.get_version.outputs.VERSION }} tag_name: ${{ steps.get_version.outputs.VERSION }}
name: Release ${{ steps.get_version.outputs.VERSION }} name: Release ${{ steps.get_version.outputs.VERSION }}
# 收集所有下载回来的产物 # 核心修复:显式指定要上传的文件后缀,彻底排除 package.json
files: ./release-assets/**/* files: |
./assets-to-release/*.exe
./assets-to-release/*.dmg
./assets-to-release/*.AppImage
./assets-to-release/*.zip
./assets-to-release/ogame-server-*
generate_release_notes: true generate_release_notes: true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}