name: Build And Create Nuget Package

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  workflow_dispatch:
  schedule:
    - cron: '3 0 * * 0'

jobs:
  main:
    runs-on: ${{ matrix.environment }}
    strategy:
      matrix:
        environment:
          - macos-latest
          - ubuntu-latest
          - windows-latest
    env:
      DOTNET_NOLOGO: 1
      DOTNET_CLI_TELEMETRY_OPTOUT: 1
      NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
      UNIT_TEST_PROJECT: QuestPDF.UnitTests/QuestPDF.UnitTests.csproj

    steps:
      - name: 📝 Fetch Sources 📝
        uses: actions/checkout@v2

      - name: ⚙ Setup .NET 6.0 SDK ⚙
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '6.0.x'
          
      - name: 🔄 Restore Nuget Packages 🔄
        shell: bash
        run: dotnet restore
        working-directory: ./Source

      - name: 🛠 Build Solution 🛠
        shell: bash
        run: dotnet build -c Release --no-restore
        working-directory: ./Source
        
      - name: Upload build artifacts
        uses: actions/upload-artifact@v3
        if: ${{ matrix.environment == 'windows-latest' }}
        with:
          name: Build Package
          path: |
            **/*.nupkg
            **/*.snupkg
            !.nuget
