Files
nps/.github/workflows/gui.yml
T
2026-01-23 13:53:54 +08:00

161 lines
5.0 KiB
YAML

name: Gui
on:
workflow_dispatch:
release:
types: [published]
env:
GUI_DIR: cmd/npc/npc-gui
FRONTEND_DIR: cmd/npc/npc-gui/frontend
jobs:
build_npc_gui:
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
platform: windows/amd64
artifact_name: npc-gui-windows-amd64
- os: windows-latest
platform: windows/arm64
artifact_name: npc-gui-windows-arm64
- os: macos-latest # GitHub 已下线 macos-13,统一使用最新 ARM 运行器
platform: darwin/amd64
artifact_name: npc-gui-macos-amd64
- os: macos-latest
platform: darwin/arm64
artifact_name: npc-gui-macos-arm64
- os: ubuntu-latest
platform: linux/amd64
artifact_name: npc-gui-linux-amd64
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: true
cache-dependency-path: |
go.sum
${{ env.GUI_DIR }}/go.sum
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
cache-dependency-path: ${{ env.FRONTEND_DIR }}/yarn.lock
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
for i in {1..3}; do
sudo apt-get update && \
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev build-essential pkg-config && break || \
(echo "Retry $i..." && sleep 5)
done
- name: Enable corepack for Yarn
run: corepack enable
- name: Install frontend dependencies
working-directory: ${{ env.FRONTEND_DIR }}
run: yarn install --frozen-lockfile
- name: Build frontend
working-directory: ${{ env.FRONTEND_DIR }}
run: yarn build
- name: Install Wails CLI
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
- name: Build Wails application
working-directory: ${{ env.GUI_DIR }}
env:
CGO_ENABLED: 1
shell: bash
run: |
# 提取架构信息
ARCH=${{ matrix.platform }}
ARCH=${ARCH#*/}
# 针对 macOS 的特殊处理:即使在 ARM 运行器上,也强制通过环境变量指定架构
if [[ "${{ runner.os }}" == "macOS" ]]; then
export GOARCH=$ARCH
fi
# 使用数组处理参数,防止空格导致的参数拆分错误
BUILD_ARGS=(-platform "${{ matrix.platform }}" -clean -trimpath -ldflags "-s -w")
if [[ "${{ runner.os }}" == "Windows" ]]; then
BUILD_ARGS+=(-webview2 embed)
fi
# 执行构建
wails build "${BUILD_ARGS[@]}"
- name: Package (Windows)
if: runner.os == 'Windows'
working-directory: ${{ env.GUI_DIR }}
shell: pwsh
run: |
$exeFile = Get-ChildItem -Path "build/bin/*.exe" | Select-Object -First 1
if ($exeFile) {
Compress-Archive -Path $exeFile.FullName -DestinationPath "build/bin/${{ matrix.artifact_name }}.zip" -Force
} else {
Write-Error "No exe found in build/bin"
exit 1
}
- name: Package (macOS/Linux)
if: runner.os != 'Windows'
working-directory: ${{ env.GUI_DIR }}
run: |
cd build/bin
if [ "${{ runner.os }}" == "macOS" ]; then
# macOS 打包:寻找 .app 目录
APP_PATH=$(find . -maxdepth 1 -name "*.app" -type d | head -n 1)
if [ -n "$APP_PATH" ]; then
zip -r "${{ matrix.artifact_name }}.zip" "$APP_PATH"
else
echo "Error: No .app directory found in $(pwd)"
ls -la
exit 1
fi
else
# Linux 打包:寻找二进制文件
BINARY_NAME=$(find . -maxdepth 1 -type f -executable | head -n 1)
if [ -n "$BINARY_NAME" ]; then
zip "${{ matrix.artifact_name }}.zip" "$BINARY_NAME"
else
echo "Error: No executable binary found in $(pwd)"
ls -la
exit 1
fi
fi
- name: Upload to GitHub Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ env.GUI_DIR }}/build/bin/${{ matrix.artifact_name }}.zip
retention-days: 5
- name: Upload to GitHub Release
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
uses: softprops/action-gh-release@v2
with:
files: ${{ env.GUI_DIR }}/build/bin/${{ matrix.artifact_name }}.zip
tag_name: ${{ github.event.release.tag_name || github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}