Skip to content

Commit d4a6cb3

Browse files
azure-sdkscbedd
andauthored
Sync eng/common directory with azure-sdk-tools for PR 10038 (#6494)
* add a category to parse triggerPaths when there is no artifact present (this is the go use-case) * add integration tests for Save-Package-Properties scenarios * bugfixes around various situations in new PackageProps class --------- Co-authored-by: Scott Beddall <[email protected]>
1 parent a9d94e3 commit d4a6cb3

File tree

2 files changed

+58
-27
lines changed

2 files changed

+58
-27
lines changed

eng/common/pipelines/templates/stages/archetype-sdk-tool-pwsh.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ parameters:
1010
- name: TargetTags
1111
type: string
1212
default: ''
13+
- name: PreTestSteps
14+
type: object
15+
default: []
1316

1417
variables:
1518
- template: /eng/pipelines/templates/variables/globals.yml
@@ -36,6 +39,8 @@ stages:
3639
vmImage: $(Image)
3740

3841
steps:
42+
- ${{ parameters.PreTestSteps }}
43+
3944
- template: /eng/common/pipelines/templates/steps/run-pester-tests.yml
4045
parameters:
4146
TargetDirectory: ${{ parameters.TargetDirectory }}

eng/common/scripts/Package-Properties.ps1

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ class PackageProps {
7777
$this.ArtifactName = $artifactName
7878
$this.Initialize($name, $version, $directoryPath, $serviceDirectory)
7979
}
80-
hidden [PSCustomObject]ParseYmlForArtifact([string]$ymlPath) {
80+
81+
hidden [PSCustomObject]ParseYmlForArtifact([string]$ymlPath, [bool]$soleCIYml = $false) {
8182
$content = LoadFrom-Yaml $ymlPath
8283
if ($content) {
8384
$artifacts = GetValueSafelyFrom-Yaml $content @("extends", "parameters", "Artifacts")
84-
$artifactForCurrentPackage = $null
85+
$artifactForCurrentPackage = @{}
86+
8587
if ($artifacts) {
8688
# If there's an artifactName match that to the name field from the yml
8789
if ($this.ArtifactName) {
@@ -98,8 +100,9 @@ class PackageProps {
98100
}
99101
}
100102

101-
# if we found an artifact for the current package, we should count this ci file as the source of the matrix for this package
102-
if ($artifactForCurrentPackage) {
103+
# if we found an artifact for the current package OR this is the sole ci.yml for the given service directory,
104+
# we should count this ci file as the source of the matrix for this package
105+
if ($artifactForCurrentPackage -or $soleCIYml) {
103106
$result = [PSCustomObject]@{
104107
ArtifactConfig = [HashTable]$artifactForCurrentPackage
105108
ParsedYml = $content
@@ -116,11 +119,12 @@ class PackageProps {
116119
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..")
117120

118121
$ciFolderPath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory)
119-
$ciFiles = Get-ChildItem -Path $ciFolderPath -Filter "ci*.yml" -File
122+
$ciFiles = @(Get-ChildItem -Path $ciFolderPath -Filter "ci*.yml" -File)
120123
$ciArtifactResult = $null
124+
$soleCIYml = ($ciFiles.Count -eq 1)
121125

122126
foreach ($ciFile in $ciFiles) {
123-
$ciArtifactResult = $this.ParseYmlForArtifact($ciFile.FullName)
127+
$ciArtifactResult = $this.ParseYmlForArtifact($ciFile.FullName, $soleCIYml)
124128
if ($ciArtifactResult) {
125129
break
126130
}
@@ -137,7 +141,7 @@ class PackageProps {
137141
if (-not $this.ArtifactDetails) {
138142
$ciArtifactResult = $this.GetCIYmlForArtifact()
139143

140-
if ($ciArtifactResult) {
144+
if ($ciArtifactResult -and $null -ne $ciArtifactResult.ArtifactConfig) {
141145
$this.ArtifactDetails = [Hashtable]$ciArtifactResult.ArtifactConfig
142146

143147
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..")
@@ -147,27 +151,32 @@ class PackageProps {
147151
if (-not $this.ArtifactDetails["triggeringPaths"]) {
148152
$this.ArtifactDetails["triggeringPaths"] = @()
149153
}
150-
else {
151-
$adjustedPaths = @()
152-
153-
# we need to convert relative references to absolute references within the repo
154-
# this will make it extremely easy to compare triggering paths to files in the deleted+changed file list.
155-
for ($i = 0; $i -lt $this.ArtifactDetails["triggeringPaths"].Count; $i++) {
156-
$currentPath = $this.ArtifactDetails["triggeringPaths"][$i]
157-
$newPath = Join-Path $repoRoot $currentPath
158-
if (!$currentPath.StartsWith("/")) {
159-
$newPath = Join-Path $repoRoot $relRoot $currentPath
160-
}
161-
# it is a possibility that users may have a triggerPath dependency on a file that no longer exists.
162-
# before we resolve it to get rid of possible relative references, we should check if the file exists
163-
# if it doesn't, we should just leave it as is. Otherwise we would _crash_ here when a user accidentally
164-
# left a triggeringPath on a file that had been deleted
165-
if (Test-Path $newPath) {
166-
$adjustedPaths += (Resolve-Path -Path $newPath -Relative -RelativeBasePath $repoRoot).TrimStart(".").Replace("`\", "/")
167-
}
154+
155+
# if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package
156+
$serviceTriggeringPaths = GetValueSafelyFrom-Yaml $ciArtifactResult.ParsedYml @("extends", "parameters", "TriggeringPaths")
157+
if ($serviceTriggeringPaths){
158+
$this.ArtifactDetails["triggeringPaths"] += $serviceTriggeringPaths
159+
}
160+
161+
$adjustedPaths = @()
162+
163+
# we need to convert relative references to absolute references within the repo
164+
# this will make it extremely easy to compare triggering paths to files in the deleted+changed file list.
165+
for ($i = 0; $i -lt $this.ArtifactDetails["triggeringPaths"].Count; $i++) {
166+
$currentPath = $this.ArtifactDetails["triggeringPaths"][$i]
167+
$newPath = Join-Path $repoRoot $currentPath
168+
if (!$currentPath.StartsWith("/")) {
169+
$newPath = Join-Path $repoRoot $relRoot $currentPath
170+
}
171+
# it is a possibility that users may have a triggerPath dependency on a file that no longer exists.
172+
# before we resolve it to get rid of possible relative references, we should check if the file exists
173+
# if it doesn't, we should just leave it as is. Otherwise we would _crash_ here when a user accidentally
174+
# left a triggeringPath on a file that had been deleted
175+
if (Test-Path $newPath) {
176+
$adjustedPaths += (Resolve-Path -Path $newPath -Relative -RelativeBasePath $repoRoot).TrimStart(".").Replace("`\", "/")
168177
}
169-
$this.ArtifactDetails["triggeringPaths"] = $adjustedPaths
170178
}
179+
$this.ArtifactDetails["triggeringPaths"] = $adjustedPaths
171180
$this.ArtifactDetails["triggeringPaths"] += $ciYamlPath
172181

173182
$this.CIParameters["CIMatrixConfigs"] = @()
@@ -215,6 +224,22 @@ function Get-PkgProperties {
215224
return $null
216225
}
217226

227+
function Get-PackagesFromPackageInfo([string]$PackageInfoFolder, [bool]$IncludeIndirect, [ScriptBlock]$CustomCompareFunction = $null) {
228+
$packages = Get-ChildItem -R -Path $PackageInfoFolder -Filter "*.json" | ForEach-Object {
229+
Get-Content $_.FullName | ConvertFrom-Json
230+
}
231+
232+
if (-not $includeIndirect) {
233+
$packages = $packages | Where-Object { $_.IncludedForValidation -eq $false }
234+
}
235+
236+
if ($CustomCompareFunction) {
237+
$packages = $packages | Where-Object { &$CustomCompareFunction $_ }
238+
}
239+
240+
return $packages
241+
}
242+
218243

219244
function Get-TriggerPaths([PSCustomObject]$AllPackageProperties) {
220245
$existingTriggeringPaths = @()
@@ -447,7 +472,8 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
447472
# finally, if we have gotten all the way here and we still don't have any packages, we should include the template service
448473
# packages. We should never return NO validation.
449474
if ($packagesWithChanges.Count -eq 0) {
450-
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template" })
475+
# most of our languages use `template` as the service directory for the template service, but `go` uses `template/aztemplate`.
476+
$packagesWithChanges += ($allPackageProperties | Where-Object { $_.ServiceDirectory -eq "template"-or $_.ServiceDirectory -eq "template/aztemplate" })
451477
foreach ($package in $packagesWithChanges) {
452478
$package.IncludedForValidation = $true
453479
}

0 commit comments

Comments
 (0)