# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# This workflow will build the TypeAgent TypeScript code

name: build-dotnet

on:
  workflow_dispatch:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
  merge_group:
    branches: ["main"]

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

permissions:
  pull-requests: read
  contents: read

jobs:
  build_dotnet:
    strategy:
      fail-fast: false
      matrix:
        configuration: ["Debug", "Release"]
    runs-on: "windows-latest"
    steps:
      - name: Setup Git LF
        run: |
          git config --global core.autocrlf false
      - uses: actions/checkout@v4
      - uses: dorny/paths-filter@v3
        id: filter
        with:
          filters: |
            dotnet:
              - "dotnet/**"
              - ".github/workflows/build-dotnet.yml"
      - name: Setup MSBuild
        if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.dotnet == 'true' }}
        uses: microsoft/setup-msbuild@v2
      - name: Setup NuGet
        if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.dotnet == 'true' }}
        uses: NuGet/setup-nuget@v2.0.0
      - name: Restore Packages
        if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.dotnet == 'true' }}
        working-directory: dotnet
        run: nuget restore autoShell/AutoShell.sln
      - name: Build Solution
        if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.dotnet == 'true' }}
        working-directory: dotnet
        run: |
          msbuild.exe autoShell/AutoShell.sln /p:platform="Any CPU" /p:configuration="${{ matrix.configuration }}"
