节点在线、应用在线、配置在线使用令牌查询
大石头 authored at 2021-12-16 19:49:30
4.61 KiB
Stardust
name: test

on:
  push:
    branches: ["*"]
  pull_request:
    branches: ["*"]
  workflow_dispatch:

jobs:
  # 测试统一跑在 Ubuntu:四个测试工程都只面向 net10.0,Linux 构建与执行更快;
  # Windows 侧差异由 build-solution 的整解决方案编译兜底(net45/net461 目标无法在 Linux 编译)
  test:
    name: test (${{ matrix.name }})
    runs-on: ubuntu-latest
    timeout-minutes: 45
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: core
            project: Stardust.Tests/Stardust.Tests.csproj
          - name: server
            project: Stardust.ServerTests/ServerTest.csproj
          - name: webapi
            project: Stardust.WebApiTests/Stardust.WebApiTests.csproj
          - name: client
            project: ClientTest/ClientTest.csproj

    steps:
    - uses: actions/checkout@v4
    - name: Setup dotNET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: 10.x
    - name: Test
      run: |
        dotnet test ${{ matrix.project }} -c Release --nologo \
          --logger "trx;LogFileName=${{ matrix.name }}.trx" --results-directory TestResults
    - name: Upload Test Results
      if: always()
      uses: actions/upload-artifact@v4
      with:
        name: test-results-${{ matrix.name }}
        path: TestResults/*.trx
        if-no-files-found: ignore

  # 整解决方案编译:覆盖 net45/net461 等仅 Windows 可编译的目标,以及移动端以外的全部工程
  build-solution:
    name: build solution (windows)
    runs-on: windows-latest
    timeout-minutes: 30

    steps:
      - uses: actions/checkout@v4
      - name: Setup dotNET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: |
            6.x
            7.x
            8.x
            9.x
            10.x
      # 仓库仅保留 星尘.slnx(XML 方案格式)一个解决方案文件,显式指定以保证解析目标明确
      - name: Build
        run: |
          dotnet build 星尘.slnx -c Release

  localization:
    name: localization checks
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
    - uses: actions/checkout@v4
    - name: Check English messages
      shell: pwsh
      run: |
        $failed = $false
        foreach ($dir in @('Stardust', 'Stardust.Extensions', 'Stardust.Server', 'Stardust.Web', 'Stardust.WebApi', 'Stardust.Data', 'StarAgent', 'StarGateway', 'Plugins/AgentExpansion', 'Plugins/NetworkDetect', 'DeployAgent', 'StarAgent.Mobile')) {
          pwsh -File ./check-english-exceptions.ps1 -Root . -Dir $dir
          if ($LASTEXITCODE -ne 0) { $failed = $true }
        }
        if ($failed) { exit 1 }
    - name: Check locales
      shell: pwsh
      run: |
        $failed = $false
        Get-ChildItem -Path . -Recurse -Directory -Filter Locales | ForEach-Object {
          if (Test-Path (Join-Path $_.FullName 'zh-Hans.yml')) {
            $src = Split-Path $_.FullName -Parent
            $proj = Split-Path $src -Leaf
            # Web/WebApi 通过 Compile Include 复用 Stardust.Server 源码,孤儿键扫描需同时覆盖
            if ($proj -in @('Stardust.Web', 'Stardust.WebApi')) { $src = "$src,Stardust.Server" }
            # 界面元数据(菜单名、实体字段描述)以中文源文为键,允许部分语言缺失并回退源文
            $meta = Join-Path $_.FullName 'metadata-keys.json'
            $extra = @()
            if (Test-Path $meta) { $extra = @('-MetadataKeys', $meta) }
            pwsh -File ./check-locales.ps1 -LocaleDir $_.FullName -Baseline zh-Hans.yml -SourceDir $src @extra
            if ($LASTEXITCODE -ne 0) { $failed = $true }
          }
        }
        if ($failed) { exit 1 }
    - name: Check README languages
      shell: pwsh
      run: pwsh -File ./sync-readme-languages.ps1 -Check

  # 多平台单元测试矩阵:Linux x64 / arm64 观察期,逐步转为阻断(与 Core 观察期约定一致)
  # 多架构观察期:x64 已由 test 矩阵常驻覆盖,这里只保留 arm64,稳定后转为阻断
  test-arm64:
    name: test (linux-arm64)
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 90
    continue-on-error: true

    steps:
    - uses: actions/checkout@v4
    - name: Setup dotNET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: 10.x
    - name: Test
      run: dotnet test Stardust.Tests/Stardust.Tests.csproj -c Release --nologo --logger "trx;LogFileName=linux-arm64.trx" --results-directory TestResults
    - name: Upload Test Results
      if: always()
      uses: actions/upload-artifact@v4
      with:
        name: test-results-linux-arm64
        path: TestResults/*.trx
        if-no-files-found: ignore