####################################################################################
# DO NOT EDIT: This file was automatically generated by Generate-TestWorkflows.ps1
####################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
# 
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

name: 'Lucene.Net.Tests.CodeAnalysis'

on:
  workflow_dispatch:
  pull_request:
    paths:
    - 'src/dotnet/Lucene.Net.Tests.CodeAnalysis/**/*'
    - 'build/Dependencies.props'
    - 'build/TestReferences.Common.*'
    - 'TestTargetFrameworks.*'
    - '*.sln'
    - 'src/dotnet/Lucene.Net.Tests.CodeAnalysis/Directory.Build.*'
    - 'src/dotnet/Directory.Build.*'
    - 'src/Directory.Build.*'
    - 'Directory.Build.*'

    # Dependencies
    - 'src/Lucene.Net/**/*'
    - 'src/dotnet/Lucene.Net.CodeAnalysis.CSharp/**/*'
    - 'src/dotnet/Lucene.Net.CodeAnalysis.VisualBasic/**/*'

    - '!**/*.md'

jobs:

  Test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest]
        framework: [netcoreapp2.1]
        platform: [x64]
        configuration: [Release]
        exclude:
          - os: ubuntu-latest
            framework: net48
          - os: macos-latest
            framework: net48
    env:
      project_path: './src/dotnet/Lucene.Net.Tests.CodeAnalysis/Lucene.Net.Tests.CodeAnalysis.csproj'
      trx_file_name: 'TestResults.trx'
      md_file_name: 'TestResults.md' # Report file name for LiquidTestReports.Markdown

    steps:
      - uses: actions/checkout@v2

      - name: Setup .NET 3.1 SDK
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '3.1.404'
        if: ${{ startswith(matrix.framework, 'netcoreapp3.') }}

      - name: Setup .NET 2.1 SDK
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '2.1.811'
        if: ${{ startswith(matrix.framework, 'netcoreapp2.') }}

      - name: Setup .NET 5 SDK
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '5.0.100'

      - run: |
          $project_name = [System.IO.Path]::GetFileNameWithoutExtension($env:project_path)
          $test_results_artifact_name = "testresults_${{matrix.os}}_${{matrix.framework}}_${{matrix.platform}}_${{matrix.configuration}}"
          Write-Host "Project Name: $project_name"
          Write-Host "Results Artifact Name: $test_results_artifact_name"
          echo "project_name=$project_name" | Out-File -FilePath  $env:GITHUB_ENV -Encoding utf8 -Append
          echo "test_results_artifact_name=$test_results_artifact_name" | Out-File -FilePath  $env:GITHUB_ENV -Encoding utf8 -Append
          # Title for LiquidTestReports.Markdown
          echo "title=Test Run for $project_name - ${{matrix.framework}} - ${{matrix.platform}} - ${{matrix.os}}" | Out-File -FilePath  $env:GITHUB_ENV -Encoding utf8 -Append
        shell: pwsh
      - run: dotnet build ${{env.project_path}} --configuration ${{matrix.configuration}} --framework ${{matrix.framework}} /p:TestFrameworks=true
      - run: dotnet test ${{env.project_path}} --configuration ${{matrix.configuration}} --framework ${{matrix.framework}} --no-build --no-restore --blame-hang --blame-hang-dump-type mini --blame-hang-timeout 20minutes --logger:"console;verbosity=normal" --logger:"trx;LogFileName=${{env.trx_file_name}}" --logger:"liquid.md;LogFileName=${{env.md_file_name}};Title=${{env.title}};" --results-directory:"${{github.workspace}}/${{env.test_results_artifact_name}}/${{env.project_name}}" -- RunConfiguration.TargetPlatform=${{matrix.platform}}
      # upload reports as build artifacts
      - name: Upload a Build Artifact
        uses: actions/upload-artifact@v2
        if: ${{always()}}
        with:
          name: '${{env.test_results_artifact_name}}'
          path: '${{github.workspace}}/${{env.test_results_artifact_name}}'

