mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
chore(workflow): 优化 GitHub Actions 构建流程
- 合并前端安装与构建步骤以提高效率 - 移除重复的 checkout 和 setup 步骤 - 简化 artifact 上传路径配置 - 调整 release 步骤中的版本号获取逻辑 - 更新注释说明以反映最新改动 - 统一 Electron 构建命令执行方式
This commit is contained in:
56
.github/workflows/build.yml
vendored
56
.github/workflows/build.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# 1. 构建 Go 服务端 (包含前端静态资源)
|
# 1. 构建 Go 服务端
|
||||||
build-server:
|
build-server:
|
||||||
name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }})
|
name: Build Server (${{ matrix.goos }}-${{ matrix.goarch }})
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -22,47 +22,37 @@ jobs:
|
|||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
executable: ogame-server-linux-arm64
|
executable: ogame-server-linux-arm64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
# 安装 pnpm
|
|
||||||
- uses: pnpm/action-setup@v3
|
- uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 8
|
version: 8
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
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
|
- 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
|
||||||
# 构建服务端前先构建前端
|
run: |
|
||||||
- name: Install Frontend Dependencies
|
pnpm install
|
||||||
run: pnpm install
|
pnpm run build
|
||||||
|
|
||||||
- name: Build Frontend (for Go Embed)
|
|
||||||
run: pnpm run build
|
|
||||||
|
|
||||||
- name: Compile Go Server
|
- name: Compile Go Server
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
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 Server Artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: server-${{ matrix.goos }}-${{ matrix.goarch }}
|
name: server-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
path: ${{ matrix.executable }}
|
path: ${{ matrix.executable }}
|
||||||
|
|
||||||
# 2. 构建 Electron 客户端 (输出到 pkg)
|
# 2. 构建 Electron 客户端
|
||||||
build-electron:
|
build-electron:
|
||||||
name: Build Electron (${{ matrix.os }})
|
name: Build Electron (${{ matrix.os }})
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -76,43 +66,28 @@ jobs:
|
|||||||
platform: mac
|
platform: mac
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
platform: linux
|
platform: linux
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
# 安装 pnpm
|
|
||||||
- uses: pnpm/action-setup@v3
|
- uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 8
|
version: 8
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
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: Install Dependencies
|
run: |
|
||||||
run: pnpm install
|
pnpm install
|
||||||
|
pnpm run build
|
||||||
- name: Build Frontend (for Electron)
|
pnpm run build:electron --${{ matrix.platform }}
|
||||||
run: pnpm run build
|
|
||||||
|
|
||||||
- name: Build Electron App
|
|
||||||
# 注意: pnpm 传参不需要额外的 --
|
|
||||||
run: pnpm run build:electron --${{ matrix.platform }}
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Upload Electron Artifact
|
- name: Upload Electron Artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: electron-${{ matrix.platform }}
|
name: electron-${{ matrix.platform }}
|
||||||
path: |
|
path: pkg/
|
||||||
pkg/*.exe
|
|
||||||
pkg/*.dmg
|
|
||||||
pkg/*.AppImage
|
|
||||||
pkg/*.zip
|
|
||||||
pkg/*.deb
|
|
||||||
|
|
||||||
# 3. 发布 Release
|
# 3. 发布 Release
|
||||||
release:
|
release:
|
||||||
@@ -121,6 +96,9 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
|
# 必须先检出代码,否则 release 步骤里没有 package.json 可供读取版本号
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Download all artifacts
|
- name: Download all artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
@@ -130,7 +108,8 @@ jobs:
|
|||||||
id: get_version
|
id: get_version
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
VERSION=$(node -p "require('./package.json').version")
|
# 确保在项目根目录下执行
|
||||||
|
VERSION=$(node -e "console.log(require('./package.json').version)")
|
||||||
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
|
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
@@ -138,6 +117,7 @@ jobs:
|
|||||||
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 }}
|
||||||
|
# 收集所有下载回来的产物
|
||||||
files: ./release-assets/**/*
|
files: ./release-assets/**/*
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
env:
|
env:
|
||||||
|
|||||||
Reference in New Issue
Block a user