name: Build Bimix

on:
  push:
    branches:
      - main

jobs:
  build:
    name: Build WebAPI and WebUI
    runs-on: ubuntu-latest

    env:
      DOTNET_VERSION: '8.0.x'

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

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: ${{ env.DOTNET_VERSION }}

      - name: Restore WebAPI
        run: dotnet restore Bimix.API/Bimix.API.csproj

      - name: Restore WebUI
        run: dotnet restore Bimix.UI.Web/Bimix.UI.Web.csproj

      - name: Build WebAPI
        run: dotnet build Bimix.API/Bimix.API.csproj --configuration Release --no-restore

      - name: Build WebUI
        run: dotnet build Bimix.UI.Web/Bimix.UI.Web.csproj --configuration Release --no-restore

      - name: Publish WebAPI
        run: |
          dotnet publish Bimix.API/Bimix.API.csproj \
          --configuration Release \
          --output ./publish/Bimix-WebAPI

      - name: Publish Web (Blazor Server)
        run: |
          dotnet publish Bimix.UI.Web/Bimix.UI.Web.csproj \
          --configuration Release \
          --output ./publish/Bimix-Web

      - name: Upload publish artifact
        uses: actions/upload-artifact@v4
        with:
          name: bimix-artifacts
          path: ./publish
