|
1 | | -# This template serves as a place to upload artifacts intended to be used by LLMs |
2 | | -# that handle data from the pipeline (for example github copilot). |
| 1 | +# This template stages test result files into an "llm-artifacts" directory so they can be |
| 2 | +# uploaded as a pipeline artifact and consumed by LLM tooling (for example GitHub Copilot) |
| 3 | +# to analyze a test run. |
| 4 | +# |
| 5 | +# It is language agnostic. Every Azure SDK language repo emits test results in a different |
| 6 | +# format (.NET produces TRX, the other languages produce JUnit XML) and with a different |
| 7 | +# file name, so callers pass the appropriate leaf-name glob via TestResultsGlob: |
| 8 | +# |
| 9 | +# .NET (TRX): TestResultsGlob: '$(TestTargetFramework)*.trx' |
| 10 | +# Python (JUnit XML): TestResultsGlob: '*test*.xml' |
| 11 | +# JS (JUnit XML): TestResultsGlob: 'test-results*.xml', SearchFolder: '$(System.DefaultWorkingDirectory)/sdk' |
| 12 | +# Java (JUnit XML): TestResultsGlob: 'TEST-*.xml', SearchFolder: '$(System.DefaultWorkingDirectory)/sdk' |
| 13 | +# Go (JUnit XML): TestResultsGlob: 'report.xml' |
| 14 | +# |
| 15 | +# The staging step does not care about the file format; it only moves files. Each file is |
| 16 | +# renamed using its location relative to the repo's "sdk" directory so results from different |
| 17 | +# services/packages do not collide once flattened into a single directory. |
| 18 | +# |
| 19 | +# Example template usage, see above for per language values: |
| 20 | +# |
| 21 | +# - template: /eng/common/pipelines/templates/steps/upload-llm-artifacts.yml |
| 22 | +# parameters: |
| 23 | +# TestResultsGlob: '*test*.xml' # e.g. Python |
| 24 | +# SearchFolder: '$(System.DefaultWorkingDirectory)/sdk' |
| 25 | +# - output: pipelineArtifact |
| 26 | +# condition: eq(variables['uploadLlmArtifacts'], 'true') |
| 27 | + |
| 28 | + |
| 29 | +parameters: |
| 30 | + # One or more comma separated leaf-name globs used to locate test result files. |
| 31 | + - name: TestResultsGlob |
| 32 | + type: string |
| 33 | + default: '*.trx' |
| 34 | + # Root directory to search recursively. Scope this (for example to ".../sdk") to avoid |
| 35 | + # scanning large unrelated trees such as node_modules. |
| 36 | + - name: SearchFolder |
| 37 | + type: string |
| 38 | + default: '$(Build.SourcesDirectory)' |
3 | 39 |
|
4 | 40 | steps: |
5 | 41 | - pwsh: | |
6 | 42 | $artifactsDirectory = "$(Build.ArtifactStagingDirectory)/llm-artifacts" |
7 | | - New-Item $artifactsDirectory -ItemType directory -Force |
| 43 | + New-Item $artifactsDirectory -ItemType Directory -Force | Out-Null |
| 44 | +
|
| 45 | + $searchFolder = "${{ parameters.SearchFolder }}" |
| 46 | + $patterns = "${{ parameters.TestResultsGlob }}".Split(",", [StringSplitOptions]::RemoveEmptyEntries) ` |
| 47 | + | ForEach-Object { $_.Trim() } | Where-Object { $_ } |
| 48 | +
|
| 49 | + $testResultsFiles = @(Get-ChildItem -Path $searchFolder -Include $patterns -Recurse -File -ErrorAction SilentlyContinue) |
| 50 | +
|
8 | 51 | Write-Host "=================" |
9 | | - Get-ChildItem -Path $(TestTargetFramework)*.trx -Recurse -File |
| 52 | + Write-Host "Found $($testResultsFiles.Count) test result file(s) under '$searchFolder' matching: $($patterns -join ', ')" |
| 53 | + $testResultsFiles | ForEach-Object { Write-Host $_.FullName } |
10 | 54 | Write-Host "=================" |
11 | | - foreach($testResultsFile in (Get-ChildItem -Path $(TestTargetFramework)*.trx -Recurse -File)) |
| 55 | +
|
| 56 | + foreach ($testResultsFile in $testResultsFiles) |
12 | 57 | { |
13 | 58 | $fileFullName = $testResultsFile.FullName |
14 | | - # Convert a path like |
15 | | - # /mnt/vss/_work/1/s/sdk/template/Azure.Template/tests/TestResults/net8.0.trx |
16 | | - # to |
17 | | - # template-Azure.Template-net8.0.trx |
18 | | - $serviceAndPackage = ($fileFullName -split 'sdk[\\/]|[\\/]tests')[1] -replace '[\\/]', '-' |
19 | | - $trxFile = Split-Path $fileFullName -Leaf |
20 | | - $fileName = "$serviceAndPackage-$trxFile" |
| 59 | +
|
| 60 | + # Build a unique, traceable artifact name from the file's location. Prefer the path |
| 61 | + # relative to the language repo's "sdk" directory, for example: |
| 62 | + # <sources>/sdk/template/Azure.Template/tests/TestResults/net8.0.trx |
| 63 | + # -> template-Azure.Template-tests-TestResults-net8.0.trx |
| 64 | + # <sources>/sdk/storage/report.xml |
| 65 | + # -> storage-report.xml |
| 66 | + # Fall back to a sources-relative path for repos without an "sdk" directory. |
| 67 | + if ($fileFullName -match "[\\/]sdk[\\/]") |
| 68 | + { |
| 69 | + $relativePath = ($fileFullName -split "[\\/]sdk[\\/]", 2)[-1] |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + $relativePath = [System.IO.Path]::GetRelativePath("$(Build.SourcesDirectory)", $fileFullName) |
| 74 | + } |
| 75 | + $fileName = $relativePath -replace "^[\\/]+", "" -replace "[\\/]+", "-" |
| 76 | +
|
21 | 77 | Move-Item -Path $fileFullName -Destination "$artifactsDirectory/$fileName" -ErrorAction Continue |
22 | | - Write-Host "##vso[task.setvariable variable=uploadTestResults]true" |
| 78 | + Write-Host "##vso[task.setvariable variable=uploadLlmArtifacts]true" |
23 | 79 | } |
24 | 80 | condition: succeededOrFailed() |
25 | | - displayName: Copy test results files to llm artifacts staging directory |
| 81 | + displayName: Copy test result files to llm artifacts staging directory |
0 commit comments