Skip to content

Commit 3e4135f

Browse files
committed
Sync eng/common directory with azure-sdk-tools repository
1 parent 6a7faef commit 3e4135f

File tree

3 files changed

+122
-45
lines changed

3 files changed

+122
-45
lines changed

eng/common/pipelines/templates/jobs/perf.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,34 @@ jobs:
122122
ResourceType: perf
123123
ServiceConnection: azure-sdk-tests-public
124124

125-
- script: >-
126-
dotnet run -- run
127-
--language ${{ parameters.Language }}
128-
--language-version ${{ parameters.LanguageVersion }}
129-
--repo-root $(System.DefaultWorkingDirectory)
130-
--tests-file $(System.DefaultWorkingDirectory)/sdk/${{ parameters.ServiceDirectory }}/perf-tests.yml
131-
--package-versions "${{ parameters.PackageVersions }}"
132-
--tests "${{ parameters.Tests }}"
133-
--arguments "${{ parameters.Arguments }}"
134-
--iterations ${{ parameters.Iterations }}
135-
$(Profile)
136-
${{ parameters.AdditionalArguments }}
125+
- task: AzurePowerShell@5
126+
inputs:
127+
azureSubscription: azure-sdk-tests-public
128+
azurePowerShellVersion: LatestVersion
129+
pwsh: true
130+
ScriptType: InlineScript
131+
Inline: >-
132+
$account = (Get-AzContext).Account;
133+
$env:AZURESUBSCRIPTION_CLIENT_ID = $account.Id;
134+
$env:AZURESUBSCRIPTION_TENANT_ID = $account.Tenants;
135+
136+
dotnet run -- run
137+
--language ${{ parameters.Language }}
138+
--language-version ${{ parameters.LanguageVersion }}
139+
--repo-root $(System.DefaultWorkingDirectory)
140+
--tests-file $(System.DefaultWorkingDirectory)/sdk/${{ parameters.ServiceDirectory }}/perf-tests.yml
141+
--package-versions "${{ parameters.PackageVersions }}"
142+
--tests "${{ parameters.Tests }}"
143+
--arguments "${{ parameters.Arguments }}"
144+
--iterations ${{ parameters.Iterations }}
145+
$(Profile)
146+
${{ parameters.AdditionalArguments }}
137147
workingDirectory: azure-sdk-tools/tools/perf-automation/Azure.Sdk.Tools.PerfAutomation
148+
displayName: Run perf tests
138149
env:
150+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
139151
${{ each var in parameters.EnvVars }}:
140152
${{ var.key }}: ${{ var.value }}
141-
displayName: Run perf tests
142153

143154
- pwsh: |
144155
get-content results.txt

eng/common/scripts/Helpers/Package-Helpers.ps1

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,90 @@ function CompatibleConvertFrom-Yaml {
9090
else {
9191
return ConvertFrom-Yaml $content
9292
}
93+
}
94+
95+
<#
96+
.SYNOPSIS
97+
Common function that will verify that the YmlFile being loaded exists, load the raw file and
98+
return the results of CompatibleConvertFrom-Yaml or report an exception and return null if
99+
there's a problem loading the yml file. The return is the PowerShell HashTable object.
100+
101+
.DESCRIPTION
102+
Common function that will verify that the YmlFile being loaded exists, load the raw file and
103+
return the results of CompatibleConvertFrom-Yaml or report an exception and return null if
104+
there's a problem loading the yml file. This is just to save anyone needing to load yml from
105+
having to deal with checking the file's existence and ensure that the CompatibleConvertFrom-Yaml
106+
is made within a try/catch. The return is the PowerShell HashTable object from the
107+
CompatibleConvertFrom-Yaml call or $null if there was an issue with the convert.
108+
109+
.PARAMETER YmlFile
110+
The full path of the yml file to load.
111+
112+
.EXAMPLE
113+
LoadFrom-Yaml -YmlFile path/to/file.yml
114+
#>
115+
function LoadFrom-Yaml {
116+
param(
117+
[Parameter(Mandatory=$true)]
118+
[string]$YmlFile
119+
)
120+
if (Test-Path -Path $YmlFile) {
121+
try {
122+
return Get-Content -Raw -Path $YmlFile | CompatibleConvertFrom-Yaml
123+
}
124+
catch {
125+
Write-Host "LoadFrom-Yaml::Exception while parsing yml file $($YmlFile): $_"
126+
}
127+
}
128+
else {
129+
Write-Host "LoadFrom-Yaml::YmlFile '$YmlFile' does not exist."
130+
}
131+
return $null
132+
}
133+
134+
<#
135+
.SYNOPSIS
136+
Given the Hashtable contents of a Yml file and an array of strings representing the keys
137+
return the value if it exist or null if it doesn't.
138+
139+
.DESCRIPTION
140+
The Yaml file needs to be loaded via CompatibleConvertFrom-Yaml which returns the file as
141+
as hashtable. The Keys are basically the path in the yaml file whose value to return, or
142+
null if it doesn't exist. This function safely traverses the path, outputting an error
143+
if there's an issue or returning the object representing the result if successful. This
144+
function loops through the Keys safely trying to get values, checking each piece of the
145+
path to ensure it exists. Normally one would just do
146+
$Yml["extends"]["parameters"]["artifacts"]
147+
but if something was off it would throw. Doing it this way allows more succinct error
148+
reporting if a piece of the path didn't exist
149+
150+
.PARAMETER YamlContentAsHashtable
151+
The hashtable representing the yaml file contents loaded through LoadFrom-Yaml
152+
or CompatibleConvertFrom-Yaml, which is what LoadFrom-Yaml calls.
153+
154+
.PARAMETER Keys
155+
String array representation of the path in the yaml file whose value we're trying to retrieve.
156+
157+
.EXAMPLE
158+
GetValueSafelyFrom-Yaml -YamlContentAsHashtable $YmlFileContent -Keys @("extends", "parameters", "Artifacts")
159+
#>
160+
function GetValueSafelyFrom-Yaml {
161+
param(
162+
[Parameter(Mandatory=$true)]
163+
$YamlContentAsHashtable,
164+
[Parameter(Mandatory=$true)]
165+
[string[]]$Keys
166+
)
167+
$current = $YamlContentAsHashtable
168+
foreach ($key in $Keys) {
169+
if ($current.ContainsKey($key) -or $current[$key]) {
170+
$current = $current[$key]
171+
}
172+
else {
173+
Write-Host "The '$key' part of the path $($Keys -join "/") doesn't exist or is null."
174+
return $null
175+
}
176+
}
177+
178+
return [object]$current
93179
}

eng/common/scripts/Package-Properties.ps1

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class PackageProps
1717
[string]$ReleaseStatus
1818
# was this package purely included because other packages included it as an AdditionalValidationPackage?
1919
[boolean]$IncludedForValidation
20-
# does this package include other packages that we should trigger validation for?
20+
# does this package include other packages that we should trigger validation for or
21+
# additional packages required for validation of this one
2122
[string[]]$AdditionalValidationPackages
2223
[HashTable]$ArtifactDetails
2324

@@ -83,42 +84,21 @@ class PackageProps
8384
$this.Group = $group
8485
}
8586

86-
hidden [object]GetValueSafely($hashtable, [string[]]$keys) {
87-
$current = $hashtable
88-
foreach ($key in $keys) {
89-
if ($current.ContainsKey($key) -or $current[$key]) {
90-
$current = $current[$key]
91-
}
92-
else {
93-
return $null
94-
}
95-
}
87+
hidden [HashTable]ParseYmlForArtifact([string]$ymlPath) {
9688

97-
return $current
98-
}
89+
$content = LoadFrom-Yaml $ymlPath
90+
if ($content) {
91+
$artifacts = GetValueSafelyFrom-Yaml $content @("extends", "parameters", "Artifacts")
92+
$artifactForCurrentPackage = $null
9993

100-
hidden [HashTable]ParseYmlForArtifact([string]$ymlPath) {
101-
if (Test-Path -Path $ymlPath) {
102-
try {
103-
$content = Get-Content -Raw -Path $ymlPath | CompatibleConvertFrom-Yaml
104-
if ($content) {
105-
$artifacts = $this.GetValueSafely($content, @("extends", "parameters", "Artifacts"))
106-
$artifactForCurrentPackage = $null
107-
108-
if ($artifacts) {
109-
$artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name }
110-
}
111-
112-
if ($artifactForCurrentPackage) {
113-
return [HashTable]$artifactForCurrentPackage
114-
}
115-
}
94+
if ($artifacts) {
95+
$artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name }
11696
}
117-
catch {
118-
Write-Host "Exception while parsing yml file $($ymlPath): $_"
97+
98+
if ($artifactForCurrentPackage) {
99+
return [HashTable]$artifactForCurrentPackage
119100
}
120101
}
121-
122102
return $null
123103
}
124104

0 commit comments

Comments
 (0)