|
| 1 | +################################################################################# |
| 2 | +# Licensed to the .NET Foundation under one or more agreements. # |
| 3 | +# The .NET Foundation licenses this file to you under the MIT license. # |
| 4 | +# See the LICENSE file in the project root for more information. # |
| 5 | +################################################################################# |
| 6 | + |
| 7 | +# Shared build-and-test steps used by both the Windows and Linux Kerberos jobs. |
| 8 | +# |
| 9 | +# Parameters: |
| 10 | +# buildTarget — The build.proj target that builds SqlClient for the current |
| 11 | +# OS (e.g. BuildSqlClientWindows or BuildSqlClientUnix). |
| 12 | +# testFramework — The TFM to test against (e.g. net9.0, net462). |
| 13 | +# testRunTitle — Title for the published test results (displayed in the ADO |
| 14 | +# Tests tab). |
| 15 | +# artifactName — Name of the published pipeline artifact that carries the |
| 16 | +# test results and coverage files. |
| 17 | + |
| 18 | +parameters: |
| 19 | + |
| 20 | + # build.proj target to build SqlClient for the current OS. |
| 21 | + - name: buildTarget |
| 22 | + type: string |
| 23 | + |
| 24 | + # TFM to pass to the test targets (-p:TestFramework). |
| 25 | + - name: testFramework |
| 26 | + type: string |
| 27 | + |
| 28 | + # Title shown in the ADO Tests tab for this run. |
| 29 | + - name: testRunTitle |
| 30 | + type: string |
| 31 | + |
| 32 | + # Pipeline artifact name for test results and coverage. |
| 33 | + - name: artifactName |
| 34 | + type: string |
| 35 | + |
| 36 | +steps: |
| 37 | + |
| 38 | + # --------------------------------------------------------------------------- |
| 39 | + # Build |
| 40 | + # --------------------------------------------------------------------------- |
| 41 | + |
| 42 | + # Build the given target. |
| 43 | + # |
| 44 | + # The test stages build as part of their targets, but this separate step isolates build failures |
| 45 | + # so we can fail fast before running tests. Retries are enabled intentionally (1 attempt for |
| 46 | + # build, 2 attempts for test steps) to reduce transient infrastructure-related failures. |
| 47 | + # |
| 48 | + - task: DotNetCoreCLI@2 |
| 49 | + displayName: Build SqlClient |
| 50 | + retryCountOnTaskFailure: 1 |
| 51 | + inputs: |
| 52 | + command: build |
| 53 | + projects: build.proj |
| 54 | + arguments: >- |
| 55 | + -t:${{ parameters.buildTarget }} |
| 56 | + -p:Configuration=Release |
| 57 | +
|
| 58 | + # --------------------------------------------------------------------------- |
| 59 | + # Run tests in separate steps to permit focused retries. |
| 60 | + # --------------------------------------------------------------------------- |
| 61 | + |
| 62 | + # Run the Unit Test suite. |
| 63 | + - task: DotNetCoreCLI@2 |
| 64 | + displayName: Run Unit Tests (${{ parameters.testFramework }}) |
| 65 | + retryCountOnTaskFailure: 2 |
| 66 | + inputs: |
| 67 | + command: build |
| 68 | + projects: build.proj |
| 69 | + arguments: >- |
| 70 | + -t:TestSqlClientUnit |
| 71 | + -p:TestFramework=${{ parameters.testFramework }} |
| 72 | + -p:Configuration=Release |
| 73 | +
|
| 74 | + # Run the Functional Test suite. |
| 75 | + - task: DotNetCoreCLI@2 |
| 76 | + displayName: Run Functional Tests (${{ parameters.testFramework }}) |
| 77 | + retryCountOnTaskFailure: 2 |
| 78 | + inputs: |
| 79 | + command: build |
| 80 | + projects: build.proj |
| 81 | + arguments: >- |
| 82 | + -t:TestSqlClientFunctional |
| 83 | + -p:TestFramework=${{ parameters.testFramework }} |
| 84 | + -p:Configuration=Release |
| 85 | +
|
| 86 | + # Run the Manual Test suite. |
| 87 | + - task: DotNetCoreCLI@2 |
| 88 | + displayName: Run Manual Tests (${{ parameters.testFramework }}) |
| 89 | + retryCountOnTaskFailure: 2 |
| 90 | + inputs: |
| 91 | + command: build |
| 92 | + projects: build.proj |
| 93 | + arguments: >- |
| 94 | + -t:TestSqlClientManual |
| 95 | + -p:TestFramework=${{ parameters.testFramework }} |
| 96 | + -p:Configuration=Release |
| 97 | +
|
| 98 | + # --------------------------------------------------------------------------- |
| 99 | + # Publish results & coverage |
| 100 | + # --------------------------------------------------------------------------- |
| 101 | + |
| 102 | + # Publish the TRX test results to the pipeline run. |
| 103 | + - task: PublishTestResults@2 |
| 104 | + displayName: Publish Test Results |
| 105 | + condition: succeededOrFailed() |
| 106 | + inputs: |
| 107 | + testResultsFormat: VSTest |
| 108 | + # build.proj defines TestResultsFolderPath which defaults to |
| 109 | + # $(Build.SourcesDirectory)/test_results, so we look there for the results and coverage files. |
| 110 | + testResultsFiles: $(Build.SourcesDirectory)/test_results/**/*.trx |
| 111 | + mergeTestResults: true |
| 112 | + testRunTitle: ${{ parameters.testRunTitle }} |
| 113 | + buildConfiguration: Release |
| 114 | + |
| 115 | + # Azure Pipelines task conditions do not support path existence checks directly, |
| 116 | + # so compute this once and gate later steps on the variable. |
| 117 | + - pwsh: | |
| 118 | + $resultsDir = "$(Build.SourcesDirectory)/test_results" |
| 119 | + if (Test-Path -LiteralPath $resultsDir) { |
| 120 | + Write-Host "##vso[task.setvariable variable=HasTestResultsDir]true" |
| 121 | + } |
| 122 | + else { |
| 123 | + Write-Host "##vso[task.setvariable variable=HasTestResultsDir]false" |
| 124 | + } |
| 125 | + displayName: Detect test_results directory |
| 126 | + condition: succeededOrFailed() |
| 127 | +
|
| 128 | + # Give our coverage files a unique name to make it clear where they originated when we download |
| 129 | + # the artifacts from all jobs in the merge stage. |
| 130 | + - pwsh: | |
| 131 | + cd $(Build.SourcesDirectory)/test_results |
| 132 | + Get-ChildItem -Filter "*.coverage" -Recurse | |
| 133 | + Rename-Item -NewName { "${{ parameters.testFramework }}" + $_.Name } |
| 134 | + displayName: Rename coverage files |
| 135 | + condition: and(succeededOrFailed(), eq(variables['HasTestResultsDir'], 'true')) |
| 136 | +
|
| 137 | + # Publish TRX test results and coverage files as pipeline artifacts. The merge stage needs the |
| 138 | + # coverage files from all of the jobs. |
| 139 | + - task: PublishPipelineArtifact@1 |
| 140 | + displayName: Publish Test Artifacts |
| 141 | + condition: and(succeededOrFailed(), eq(variables['HasTestResultsDir'], 'true')) |
| 142 | + inputs: |
| 143 | + targetPath: $(Build.SourcesDirectory)/test_results |
| 144 | + artifact: ${{ parameters.artifactName }} |
0 commit comments