ngal-gui 0.3.0

一个用 Rust 编写的galgame引擎,ngal引擎的egui版本
name: Build and Release

on:
  push:
    tags:
      - 'ngal-gui-*'
  workflow_dispatch:

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build ${{ matrix.target_name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # ---------- Linux (glibc 动态) ----------
          - os: ubuntu-22.04-arm
            target: aarch64-unknown-linux-gnu
            target_name: linux-arm64
            bin_name: ngal-gui
            ext: ''
            
          - os: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
            target_name: linux-amd64
            bin_name: ngal-gui
            ext: ''

          # ---------- Windows ----------
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            target_name: win-amd64
            bin_name: ngal-gui.exe
            ext: '.exe'
            
          - os: windows-latest
            target: aarch64-pc-windows-msvc
            target_name: win-arm64
            bin_name: ngal-gui.exe
            ext: '.exe'

          # ---------- macOS ----------
          - os: macos-latest
            target: x86_64-apple-darwin
            target_name: macos-amd64
            bin_name: ngal-gui
            ext: ''
            
          - os: macos-latest
            target: aarch64-apple-darwin
            target_name: macos-arm64
            bin_name: ngal-gui
            ext: ''

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: 安装 Rust 工具链
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: 安装 Linux GUI 依赖 (gnu)
        if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libx11-dev libxcursor-dev libxrandr-dev libxi-dev \
            libxkbcommon-dev libxkbcommon-x11-dev \
            libwayland-dev libgl1-mesa-dev pkg-config libasound2-dev

      - name: 缓存 cargo 构建
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      - name: 获取软件包版本
        id: version
        shell: bash
        run: |
          VERSION=$(awk -F'"' '/^version[[:space:]]*=/{print $2; exit}' Cargo.toml)
          if [ -z "$VERSION" ]; then
            echo "❌ 无法读取版本号"
            exit 1
          fi
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"
          echo "Package version: $VERSION"

      - name: 验证标签是否匹配版本
        if: startsWith(github.ref, 'refs/tags/')
        shell: bash
        run: |
          TAG="${GITHUB_REF#refs/tags/ngal-gui-}"
          VERSION="${{ steps.version.outputs.version }}"
          if [ "$TAG" != "$VERSION" ]; then
            echo "❌ Tag (ngal-gui-$TAG) 与 Cargo.toml 版本 ($VERSION) 不一致"
            exit 1
          fi
          echo "✅ 版本号一致"

      - name: 构建(原生)
        run: cargo build --release --locked --target ${{ matrix.target }}

      - name: 二进制包
        shell: bash
        run: |
          mkdir -p dist
          SRC="target/${{ matrix.target }}/release/${{ matrix.bin_name }}"
          DST="dist/ngal-gui-${{ steps.version.outputs.version }}-${{ matrix.target_name }}${{ matrix.ext }}"
          cp "$SRC" "$DST"
          if [ "${{ runner.os }}" != "Windows" ]; then
            chmod +x "$DST"
          fi
          echo "=== 文件信息 ==="
          ls -la dist/
          if command -v file >/dev/null 2>&1; then
            file "$DST"
          fi

      - name: 上传文件
        uses: actions/upload-artifact@v4
        with:
          name: ngal-gui-${{ matrix.target_name }}
          path: dist/*
          if-no-files-found: error

  release:
    name: 创建版本
    needs: build
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: List artifacts
        run: ls -laR artifacts/

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          name: ${{ github.ref_name }}
          files: artifacts/*
          generate_release_notes: true
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}