# 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,-with-title
# 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.

# Runs Publish Test Results task for all Lucene.Net test projects

# The tasks can be easily re-generated (except for any special cases) using the following powershell script

#$source_directory = "F:/Projects/lucenenet" # Change to your repo location
#
#$testProjects = Get-ChildItem -Path "$source_directory/**/*.csproj" -Recurse | ? { $_.Directory.Name.Contains(".Tests") } | Sort-Object -Property FullName
#
#[string]$output = ''
#
#foreach ($testProject in $testProjects) {
#    $projectName = [System.IO.Path]::GetFileNameWithoutExtension($testProject)
#
#    $block = `
#        "- template: publish-test-results.yml`n" + `
#        "  parameters:`n" + `
#        "    testProjectName: '$projectName'`n" + `
#        "    osName: '$`{`{ parameters.osName `}`}'`n" + `
#        "    framework: '$`{`{ parameters.framework `}`}'`n" + `
#        "    vsTestPlatform: '$`{`{ parameters.vsTestPlatform `}`}'`n" + `
#        "    testResultsFormat: '$`{`{ parameters.testResultsFormat `}`}'`n" + `
#        "    testResultsArtifactName: '$`{`{ parameters.testResultsArtifactName `}`}'`n" + `
#        "    testResultsFileName: '$`{`{ parameters.testResultsFileName `}`}'`n" + `
#        "`n"
#
#    $output = "$output$block"
#}
#
#Set-Clipboard -Value $output

parameters:
  osName: '' # The name of the operating system for display purposes.
  framework: '' # The target framework to publish.
  vsTestPlatform: 'x64' # Target platform architecture used for test execution. Valid values are x86, x64, and ARM.
  testResultsFormat: VSTest # Specify the format of the results files you want to publish. The following formats are supported: JUnit, NUnit, VSTest, XUnit, CTest
  testResultsArtifactName: 'testresults' # The name of the Azure DevOps build artifact where the test results will be published. Default 'testresults'.
  testResultsFileName: 'TestResults.trx' # The name of the file (not path) of the test results. Default 'TestResults.trx'.

steps:
#- pwsh: |
#    function EnsureNotNullOrEmpty([string]$param, [string]$nameOfParam) {
#        if ([string]::IsNullOrEmpty($param)) {
#            Write-Host "##vso[task.logissue type=error;]Missing template parameter \"$nameOfParam\""
#            Write-Host "##vso[task.complete result=Failed;]"
#        }
#    }
#    EnsureNotNullOrEmpty('${{ parameters.osName }}', 'osName')
#    EnsureNotNullOrEmpty('${{ parameters.framework }}', 'framework')
#    EnsureNotNullOrEmpty('${{ parameters.vsTestPlatform }}', 'vsTestPlatform')
#    EnsureNotNullOrEmpty('${{ parameters.testResultsFormat }}', 'testResultsFormat')
#    EnsureNotNullOrEmpty('${{ parameters.testResultsArtifactName }}', 'testResultsArtifactName')
#    EnsureNotNullOrEmpty('${{ parameters.testResultsFileName }}', 'testResultsFileName')
#  displayName: 'Validate Template Parameters'


# Special case: Only supports .NET Standard 2.0
- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.CodeAnalysis'
    framework: 'netcoreapp2.1' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    osName: '${{ parameters.osName }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

# Special case: Only supports .netcoreapp3.1
- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Cli'
    framework: 'netcoreapp3.1' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    osName: '${{ parameters.osName }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

# Special case: Only supports .net48
- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Analysis.OpenNLP'
    framework: 'net48' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    osName: '${{ parameters.osName }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'


- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.ICU'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests._A-D'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests._E-I'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests._I-J'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests._J-S'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests._T-Z'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Analysis.Common'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Analysis.Kuromoji'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Analysis.Morfologik'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Analysis.Phonetic'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Analysis.SmartCn'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Analysis.Stempel'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Benchmark'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Classification'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Codecs'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Demo'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Expressions'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Facet'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Grouping'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Highlighter'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Join'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Memory'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Misc'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Queries'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.QueryParser'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Replicator'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Sandbox'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Spatial'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.Suggest'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.TestFramework.DependencyInjection'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'

- template: publish-test-results.yml
  parameters:
    testProjectName: 'Lucene.Net.Tests.TestFramework'
    osName: '${{ parameters.osName }}'
    framework: '${{ parameters.framework }}'
    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
    testResultsFormat: '${{ parameters.testResultsFormat }}'
    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
    testResultsFileName: '${{ parameters.testResultsFileName }}'
