name: build

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build-test-publish:
    runs-on: ubuntu-24.04

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

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 8.0.x

      - name: Restore
        run: dotnet restore Ehwrj.sln

      - name: Format check
        run: dotnet format Ehwrj.sln --no-restore --verify-no-changes --verbosity minimal

      - name: Build
        run: dotnet build Ehwrj.sln -c Release --no-restore

      - name: Test
        run: dotnet run --project tests/Ehwrj.Tests/Ehwrj.Tests.csproj -c Release --no-build

      - name: Safety scan
        run: scripts/verify-safety.sh

      - name: Check local API stub
        run: dotnet run --project tools/Ehwrj.Tools.LocalApiStub/Ehwrj.Tools.LocalApiStub.csproj -c Release --no-build -- --help

      - name: Check capture tool
        run: dotnet run --project tools/Ehwrj.Tools.Capture/Ehwrj.Tools.Capture.csproj -c Release --no-build -- --help

      - name: Publish Windows x64
        run: >
          dotnet publish src/Ehwrj.App/Ehwrj.App.csproj
          -c Release
          -r win-x64
          --self-contained false
          -p:PublishSingleFile=false
          -p:PublishDir=artifacts/win-x64/

      - name: Package Windows x64
        run: scripts/package-win-x64.sh --publish-dir artifacts/win-x64 --zip artifacts/ehwrj-win-x64.zip

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ehwrj-win-x64
          path: artifacts/ehwrj-win-x64.zip
