Skip to content

Commit b91be48

Browse files
Sync eng/common directory with azure-sdk-tools for PR 16054 (#7187)
* Add pipeline step template to upload test result or llm-facing artifacts * Make common llm-artifacts template support junit emitting repos * Only set upload flag when artifacts are found --------- Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
1 parent 9b2ead9 commit b91be48

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
# Root directory to search recursively. Scope this (for example to ".../sdk") to avoid
34+
# scanning large unrelated trees such as node_modules.
35+
- name: SearchFolder
36+
type: string
37+
default: '$(Build.SourcesDirectory)'
38+
39+
steps:
40+
- pwsh: |
41+
$artifactsDirectory = "$(Build.ArtifactStagingDirectory)/llm-artifacts"
42+
New-Item $artifactsDirectory -ItemType Directory -Force | Out-Null
43+
44+
$searchFolder = "${{ parameters.SearchFolder }}"
45+
$patterns = "${{ parameters.TestResultsGlob }}".Split(",", [StringSplitOptions]::RemoveEmptyEntries) `
46+
| ForEach-Object { $_.Trim() } | Where-Object { $_ }
47+
48+
$testResultsFiles = @(Get-ChildItem -Path $searchFolder -Include $patterns -Recurse -File -ErrorAction SilentlyContinue)
49+
50+
Write-Host "================="
51+
Write-Host "Found $($testResultsFiles.Count) test result file(s) under '$searchFolder' matching: $($patterns -join ', ')"
52+
$testResultsFiles | ForEach-Object { Write-Host $_.FullName }
53+
Write-Host "================="
54+
55+
$stagedCount = 0
56+
foreach ($testResultsFile in $testResultsFiles)
57+
{
58+
$fileFullName = $testResultsFile.FullName
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+
77+
$destination = "$artifactsDirectory/$fileName"
78+
Move-Item -Path $fileFullName -Destination $destination -ErrorAction Continue
79+
if (Test-Path -Path $destination)
80+
{
81+
$stagedCount++
82+
}
83+
}
84+
85+
# Only signal an upload when test result files were actually staged.
86+
if ($stagedCount -gt 0)
87+
{
88+
Write-Host "Staged $stagedCount test result file(s) into '$artifactsDirectory'."
89+
Write-Host "##vso[task.setvariable variable=uploadLlmArtifacts]true"
90+
}
91+
else
92+
{
93+
Write-Host "No test result files were staged; skipping llm-artifacts upload."
94+
}
95+
condition: succeededOrFailed()
96+
displayName: Copy test result files to llm artifacts staging directory

0 commit comments

Comments
 (0)