From 28a2e85f5d331185ba29594096516b5b09bbf3fb Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Fri, 4 Oct 2024 13:59:38 -0700 Subject: [PATCH 01/13] add compatible function which functions both on a pipeline as well as a direct function call --- .../scripts/Helpers/Package-Helpers.ps1 | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index 3cc8adbb7e3d8..661abfa09978a 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -12,7 +12,7 @@ function GetPackageKey($pkg) { return $pkgKey } - + # Different language needs a different way to index the package. Build a map in convienice to lookup the package. # E.g. : is the package key in java. function GetPackageLookup($packageList) { @@ -44,4 +44,32 @@ function GetDocsTocDisplayName($pkg) { $displayName += " (deprecated)" } return $displayName +} + +function CompatibleConvertFrom-Yaml { + param( + # Accept input directly from the command parameter + [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [string]$Content + ) + + if (!($Content)) { + Write-Error "Content is required." + exit 1 + } + + # Initialize any variables or checks that need to be done once + $yqPresent = Get-Command 'yq' -ErrorAction SilentlyContinue + if (-not $yqPresent) { + . (Join-Path $PSScriptRoot "../../../../eng/common/scripts/Helpers" PSModule-Helpers.ps1) + Install-ModuleIfNotInstalled -WhatIf:$false "powershell-yaml" "0.4.1" | Import-Module + } + + # Process the content (for example, you could convert from YAML here) + if ($yqPresent) { + return ($content | yq -o=json | ConvertFrom-Json -AsHashTable) + } + else { + return (ConvertFrom-Yaml (Get-Content -Raw sdk/core/ci.yml)) + } } \ No newline at end of file From 1a8898b043b1a6f57e958d041624819db274934f Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Fri, 4 Oct 2024 18:59:41 -0700 Subject: [PATCH 02/13] working through really annoying details in language-specific locations --- .../scripts/Helpers/Package-Helpers.ps1 | 21 ++++++- eng/common/scripts/Package-Properties.ps1 | 61 ++++++++++++++++++- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index 661abfa09978a..ef08c2ccd1da6 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -46,9 +46,28 @@ function GetDocsTocDisplayName($pkg) { return $displayName } + +<# +.SYNOPSIS +This function is a safe wrapper around `yq` and `ConvertFrom-Yaml` to convert YAML content to a PowerShell HashTable object + +.DESCRIPTION +This function wraps `yq` and `ConvertFrom-Yaml` to convert YAML content to a PowerShell HashTable object. The reason this function exists is +because while on a local user's machine, installing a module from the powershell gallery is an easy task, in pipelines we often have failures +to install modules from the gallery. This function will attempt to use the `yq` command if it is available on the machine, and only will install +the yaml module if `yq` is not available. This means that for the majority of runs on CI machines, the yaml module will not be installed. + +.PARAMETER Content +The content to convert from YAML to a PowerShell HashTable object. Accepted as named argument or from the pipeline. + +.EXAMPLE +CompatibleConvertFrom-Yaml -Content (Get-Content -Raw path/to/file.yml) + +.EXAMPLE +Get-Content -Raw path/to/file.yml | CompatibleConvertFrom-Yaml +#> function CompatibleConvertFrom-Yaml { param( - # Accept input directly from the command parameter [Parameter(Mandatory=$true, ValueFromPipeline=$true)] [string]$Content ) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 486eeaca4b159..19b78a0fc6c23 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -1,6 +1,6 @@ -# Helper functions for retireving useful information from azure-sdk-for-* repo +# Helper functions for retrieving useful information from azure-sdk-for-* repo . "${PSScriptRoot}\logging.ps1" - +. "${PSScriptRoot}\Helpers\Package-Helpers.ps1" class PackageProps { [string]$Name @@ -19,6 +19,7 @@ class PackageProps [boolean]$IncludedForValidation # does this package include other packages that we should trigger validation for? [string[]]$AdditionalValidationPackages + [HashTable]$ArtifactDetails PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory) { @@ -66,6 +67,8 @@ class PackageProps { $this.ChangeLogPath = $null } + + $this.InitializeCIArtifacts() } hidden [void]Initialize( @@ -79,6 +82,60 @@ class PackageProps $this.Initialize($name, $version, $directoryPath, $serviceDirectory) $this.Group = $group } + + hidden [object]Get-ValueSafely($hashtable, [string[]]$keys) { + $current = $hashtable + foreach ($key in $keys) { + if ($current.ContainsKey($key) -or $current[$key]) { + $current = $current[$key] + } + else { + return $null + } + } + return $current + } + + hidden [string]ParseYmlForArtifact([string]$ymlPath) { + if (Test-Path -Path $ymlPath) { + try { + $content = Get-Content -Raw -Path $ymlPath | CompatibleConvertFrom-Yaml + if ($content) { + + $artifacts = $this.GetValueSafely($content, @("extends", "parameters", "Artifacts")) + + $artifactForCurrentPackage = $artifacts | Where-Object { $_.name -eq $this.ArtifactName } + + return $artifactForCurrentPackage + } + } + catch { + Write-Host "Exception while parsing yml file $($ymlPath): $_" + } + } + + return $null + } + + hidden [void]InitializeCIArtifacts(){ + $RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..") + $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") + $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") + + $ciArtifactResult = $this.ParseYmlForArtifact($ciFilePath) + + if ($ciArtifactResult) { + Write-Host "Is CI" + $this.ArtifactDetails = $ciArtifactResult + } + return + + $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) + + if ($ciMgmtResult) { + $this.ArtifactDetails = $ciArtifactResult + } + } } # Takes package name and service Name From 63d61e08ea1293a19b8e9d90d0105e41ac0504b7 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 7 Oct 2024 15:18:11 -0700 Subject: [PATCH 03/13] whole bunch of debugging still present. why is this not working? --- eng/common/scripts/Package-Properties.ps1 | 61 +++++++++++++++++------ 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 19b78a0fc6c23..fd956c03cd364 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -83,7 +83,7 @@ class PackageProps $this.Group = $group } - hidden [object]Get-ValueSafely($hashtable, [string[]]$keys) { + hidden [object]GetValueSafely($hashtable, [string[]]$keys) { $current = $hashtable foreach ($key in $keys) { if ($current.ContainsKey($key) -or $current[$key]) { @@ -93,20 +93,38 @@ class PackageProps return $null } } + return $current } - hidden [string]ParseYmlForArtifact([string]$ymlPath) { + hidden [HashTable]ParseYmlForArtifact([string]$ymlPath) { if (Test-Path -Path $ymlPath) { try { $content = Get-Content -Raw -Path $ymlPath | CompatibleConvertFrom-Yaml if ($content) { - + Write-Host "Calling CI Artifacts for $($this.Name) using artifact name $($this.ArtifactName)" $artifacts = $this.GetValueSafely($content, @("extends", "parameters", "Artifacts")) - $artifactForCurrentPackage = $artifacts | Where-Object { $_.name -eq $this.ArtifactName } - - return $artifactForCurrentPackage + $artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name } | Select-Object -First 1 + + # adapt this for a warning + # if ($pkgProps.Count -ge 1) + # { + # if ($pkgProps.Count -gt 1) + # { + # Write-Host "Found more than one project with the name [$PackageName], choosing the first one under $($pkgProps[0].DirectoryPath)" + # } + # return $pkgProps[0] + # } + if ($artifactForCurrentPackage) { + Write-Host "Got $artifactForCurrentPackage with type $($artifactForCurrentPackage.GetType())" + return [HashTable]$artifactForCurrentPackage + } + else { + Write-Host "No artifact found for $($this.Name)" + return $null + } + return @{} } } catch { @@ -117,23 +135,34 @@ class PackageProps return $null } - hidden [void]InitializeCIArtifacts(){ + [void]InitializeCIArtifacts(){ $RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..") $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") + Write-Host "Calling InitializeCIArtifacts against $($this.Name)" + $ciArtifactResult = $this.ParseYmlForArtifact($ciFilePath) - if ($ciArtifactResult) { - Write-Host "Is CI" - $this.ArtifactDetails = $ciArtifactResult - } - return + if (-not $this.ArtifactDetails) { + Write-Host "No assigned ArtifactDetails, so using the artifact result if it exists" + if ($ciArtifactResult) { + Write-Host "We have a ciArtifactResult" + $this.ArtifactDetails = [Hashtable]$ciArtifactResult + Write-Host $this.ArtifactDetails | Format-Table + } + else { + Write-Host "We lost ciArtifactResult somehowfor $($this.ArtifactName)" + } - $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) + if (-not $this.ArtifactDetails) { + $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) - if ($ciMgmtResult) { - $this.ArtifactDetails = $ciArtifactResult + if ($ciMgmtResult) { + $ciMgmtResult.GetEnumerator() | Format-List -Force + $this.ArtifactDetails = [Hashtable]$ciMgmtResult + } + } } } } @@ -170,7 +199,7 @@ function Get-PkgProperties function Get-PrPkgProperties([string]$InputDiffJson) { $packagesWithChanges = @() - $allPackageProperties = Get-AllPkgProperties + $allPackageProperties = Get-AllPkgProperties "appconfiguration" $diff = Get-Content $InputDiffJson | ConvertFrom-Json $targetedFiles = $diff.ChangedFiles From de3100cb0902f1e501cfbeae7311b2f9e6efc574 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Wed, 9 Oct 2024 18:01:15 -0700 Subject: [PATCH 04/13] just commenting a few that are operating properly --- eng/common/scripts/Package-Properties.ps1 | 52 ++++++++++------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index fd956c03cd364..448f5ca0f8606 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -107,23 +107,15 @@ class PackageProps $artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name } | Select-Object -First 1 - # adapt this for a warning - # if ($pkgProps.Count -ge 1) - # { - # if ($pkgProps.Count -gt 1) - # { - # Write-Host "Found more than one project with the name [$PackageName], choosing the first one under $($pkgProps[0].DirectoryPath)" - # } - # return $pkgProps[0] - # } + if ($artifactForCurrentPackage.Count -ge 1) + { + Write-Host "Found more than one project with the name [$PackageName], choosing the first one under $($artifactForCurrentPackage[0].DirectoryPath)" + return $artifactForCurrentPackage[0] + } if ($artifactForCurrentPackage) { - Write-Host "Got $artifactForCurrentPackage with type $($artifactForCurrentPackage.GetType())" + # Write-Host "Got $artifactForCurrentPackage with type $($artifactForCurrentPackage.GetType())" return [HashTable]$artifactForCurrentPackage } - else { - Write-Host "No artifact found for $($this.Name)" - return $null - } return @{} } } @@ -140,29 +132,31 @@ class PackageProps $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") - Write-Host "Calling InitializeCIArtifacts against $($this.Name)" - - $ciArtifactResult = $this.ParseYmlForArtifact($ciFilePath) + # Write-Host "Calling InitializeCIArtifacts against $($this.Name)" if (-not $this.ArtifactDetails) { - Write-Host "No assigned ArtifactDetails, so using the artifact result if it exists" + # Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.yml." + $ciArtifactResult = $this.ParseYmlForArtifact($ciFilePath) if ($ciArtifactResult) { - Write-Host "We have a ciArtifactResult" + # Write-Host "We have a ciArtifactResult: $ciArtifactResult" $this.ArtifactDetails = [Hashtable]$ciArtifactResult - Write-Host $this.ArtifactDetails | Format-Table - } - else { - Write-Host "We lost ciArtifactResult somehowfor $($this.ArtifactName)" } + # else { + # Write-Host "We don't have an artifact result to assign to $($this.Name)" + # } + } - if (-not $this.ArtifactDetails) { - $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) + if (-not $this.ArtifactDetails) { + # Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.mgmt.yml." + $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) - if ($ciMgmtResult) { - $ciMgmtResult.GetEnumerator() | Format-List -Force - $this.ArtifactDetails = [Hashtable]$ciMgmtResult - } + if ($ciMgmtResult) { + # Write-Host "We have a ciMgmtResult: $ciMgmtResult" + $this.ArtifactDetails = [Hashtable]$ciMgmtResult } + # else { + # Write-Host "We don't have a mgmt artifact result to assign to $($this.ArtifactName)" + # } } } } From e812d5b22d0678ba91a5129c7444cb66f72228c2 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Wed, 9 Oct 2024 18:09:41 -0700 Subject: [PATCH 05/13] more upates --- eng/common/scripts/Package-Properties.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 448f5ca0f8606..68bebf4c235ce 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -102,14 +102,14 @@ class PackageProps try { $content = Get-Content -Raw -Path $ymlPath | CompatibleConvertFrom-Yaml if ($content) { - Write-Host "Calling CI Artifacts for $($this.Name) using artifact name $($this.ArtifactName)" $artifacts = $this.GetValueSafely($content, @("extends", "parameters", "Artifacts")) $artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name } | Select-Object -First 1 - if ($artifactForCurrentPackage.Count -ge 1) + if ($artifactForCurrentPackage.Count -gt 1) { - Write-Host "Found more than one project with the name [$PackageName], choosing the first one under $($artifactForCurrentPackage[0].DirectoryPath)" + $data = ($artifactForCurrentPackage | % { $_.name }) -join ", " + Write-Host "Found more than one project with the name [$($this.Name)]: [ $data ]. Choosing the first one under $($artifactForCurrentPackage[0].DirectoryPath)" return $artifactForCurrentPackage[0] } if ($artifactForCurrentPackage) { From 923795a1e7ea1f1abaf6d4e2ad2458c2d0550aff Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Wed, 9 Oct 2024 18:29:54 -0700 Subject: [PATCH 06/13] enable all CI settings again --- eng/common/scripts/Package-Properties.ps1 | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 68bebf4c235ce..c07829934680a 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -104,7 +104,7 @@ class PackageProps if ($content) { $artifacts = $this.GetValueSafely($content, @("extends", "parameters", "Artifacts")) - $artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name } | Select-Object -First 1 + $artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name } if ($artifactForCurrentPackage.Count -gt 1) { @@ -113,10 +113,12 @@ class PackageProps return $artifactForCurrentPackage[0] } if ($artifactForCurrentPackage) { - # Write-Host "Got $artifactForCurrentPackage with type $($artifactForCurrentPackage.GetType())" + Write-Host "Got $artifactForCurrentPackage with type $($artifactForCurrentPackage.GetType())" return [HashTable]$artifactForCurrentPackage } - return @{} + else { + "We don't have a matching artifact for $($this.Name) in the yml file $($ymlPath)" + } } } catch { @@ -132,31 +134,31 @@ class PackageProps $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") - # Write-Host "Calling InitializeCIArtifacts against $($this.Name)" + Write-Host "Calling InitializeCIArtifacts against $($this.Name)" if (-not $this.ArtifactDetails) { - # Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.yml." + Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.yml." $ciArtifactResult = $this.ParseYmlForArtifact($ciFilePath) if ($ciArtifactResult) { - # Write-Host "We have a ciArtifactResult: $ciArtifactResult" + Write-Host "We have a ciArtifactResult: $ciArtifactResult" $this.ArtifactDetails = [Hashtable]$ciArtifactResult } - # else { - # Write-Host "We don't have an artifact result to assign to $($this.Name)" - # } + else { + Write-Host "We don't have an artifact result to assign to $($this.Name)" + } } if (-not $this.ArtifactDetails) { - # Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.mgmt.yml." + Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.mgmt.yml." $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) if ($ciMgmtResult) { - # Write-Host "We have a ciMgmtResult: $ciMgmtResult" + Write-Host "We have a ciMgmtResult: $ciMgmtResult" $this.ArtifactDetails = [Hashtable]$ciMgmtResult } - # else { - # Write-Host "We don't have a mgmt artifact result to assign to $($this.ArtifactName)" - # } + else { + Write-Host "We don't have a mgmt artifact result to assign to $($this.ArtifactName)" + } } } } @@ -193,7 +195,7 @@ function Get-PkgProperties function Get-PrPkgProperties([string]$InputDiffJson) { $packagesWithChanges = @() - $allPackageProperties = Get-AllPkgProperties "appconfiguration" + $allPackageProperties = Get-AllPkgProperties $diff = Get-Content $InputDiffJson | ConvertFrom-Json $targetedFiles = $diff.ChangedFiles From 37e9b15f6f26ca3904beb30192b880c826b575cf Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Wed, 9 Oct 2024 18:44:02 -0700 Subject: [PATCH 07/13] remove a bunch of the debug output --- eng/common/scripts/Package-Properties.ps1 | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index c07829934680a..f24408db5a42c 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -106,19 +106,9 @@ class PackageProps $artifactForCurrentPackage = $artifacts | Where-Object { $_["name"] -eq $this.ArtifactName -or $_["name"] -eq $this.Name } - if ($artifactForCurrentPackage.Count -gt 1) - { - $data = ($artifactForCurrentPackage | % { $_.name }) -join ", " - Write-Host "Found more than one project with the name [$($this.Name)]: [ $data ]. Choosing the first one under $($artifactForCurrentPackage[0].DirectoryPath)" - return $artifactForCurrentPackage[0] - } if ($artifactForCurrentPackage) { - Write-Host "Got $artifactForCurrentPackage with type $($artifactForCurrentPackage.GetType())" return [HashTable]$artifactForCurrentPackage } - else { - "We don't have a matching artifact for $($this.Name) in the yml file $($ymlPath)" - } } } catch { @@ -134,31 +124,19 @@ class PackageProps $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") - Write-Host "Calling InitializeCIArtifacts against $($this.Name)" - if (-not $this.ArtifactDetails) { - Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.yml." $ciArtifactResult = $this.ParseYmlForArtifact($ciFilePath) if ($ciArtifactResult) { - Write-Host "We have a ciArtifactResult: $ciArtifactResult" $this.ArtifactDetails = [Hashtable]$ciArtifactResult } - else { - Write-Host "We don't have an artifact result to assign to $($this.Name)" - } } if (-not $this.ArtifactDetails) { - Write-Host "Artifact details for $($this.Name) is not set. Trying to get it from ci.mgmt.yml." $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) if ($ciMgmtResult) { - Write-Host "We have a ciMgmtResult: $ciMgmtResult" $this.ArtifactDetails = [Hashtable]$ciMgmtResult } - else { - Write-Host "We don't have a mgmt artifact result to assign to $($this.ArtifactName)" - } } } } From 3ee7d4c3311533ef281ffd9d5e65f6dc74b2e073 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Wed, 9 Oct 2024 19:02:49 -0700 Subject: [PATCH 08/13] just handle any ci.blah.yml --- eng/common/scripts/Package-Properties.ps1 | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index f24408db5a42c..05bbb25ded1b1 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -121,21 +121,19 @@ class PackageProps [void]InitializeCIArtifacts(){ $RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..") - $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") - $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") + # $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") + # $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") - if (-not $this.ArtifactDetails) { - $ciArtifactResult = $this.ParseYmlForArtifact($ciFilePath) - if ($ciArtifactResult) { - $this.ArtifactDetails = [Hashtable]$ciArtifactResult - } - } + $ciFolderPath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory) + $ciFiles = Get-ChildItem -Path $ciFolderPath -Filter "ci*.yml" -File if (-not $this.ArtifactDetails) { - $ciMgmtResult = $this.ParseYmlForArtifact($ciMgmtYmlFilePath) - - if ($ciMgmtResult) { - $this.ArtifactDetails = [Hashtable]$ciMgmtResult + foreach($ciFile in $ciFiles) { + $ciArtifactResult = $this.ParseYmlForArtifact($ciFile.FullName) + if ($ciArtifactResult) { + $this.ArtifactDetails = [Hashtable]$ciArtifactResult + break + } } } } From 8e331bf6193862d43348f15cc08c1e89f94a687e Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Wed, 9 Oct 2024 19:09:45 -0700 Subject: [PATCH 09/13] remove accdientally left behind reference to a core file --- eng/common/scripts/Helpers/Package-Helpers.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index ef08c2ccd1da6..918b2d7235e08 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -89,6 +89,6 @@ function CompatibleConvertFrom-Yaml { return ($content | yq -o=json | ConvertFrom-Json -AsHashTable) } else { - return (ConvertFrom-Yaml (Get-Content -Raw sdk/core/ci.yml)) + return ConvertFrom-Yaml $content } } \ No newline at end of file From 4ad426d8972976ab58c27f09ad5b6850af1dbc43 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Thu, 10 Oct 2024 10:59:29 -0700 Subject: [PATCH 10/13] exit 1 -> throw --- eng/common/scripts/Helpers/Package-Helpers.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index 918b2d7235e08..325207b5cf083 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -73,8 +73,7 @@ function CompatibleConvertFrom-Yaml { ) if (!($Content)) { - Write-Error "Content is required." - exit 1 + throw "Content to parse is a required input." } # Initialize any variables or checks that need to be done once From 4de3ffaf7fd377340a9da70d4488876b75ef9534 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Thu, 10 Oct 2024 11:44:09 -0700 Subject: [PATCH 11/13] remove some random comments that don't need to be there --- eng/common/scripts/Package-Properties.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 05bbb25ded1b1..72810397c94f2 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -121,8 +121,6 @@ class PackageProps [void]InitializeCIArtifacts(){ $RepoRoot = Resolve-Path (Join-Path $PSScriptRoot ".." ".." "..") - # $ciFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.yml") - # $ciMgmtYmlFilePath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory "ci.mgmt.yml") $ciFolderPath = Join-Path -Path $RepoRoot -ChildPath (Join-Path "sdk" $this.ServiceDirectory) $ciFiles = Get-ChildItem -Path $ciFolderPath -Filter "ci*.yml" -File From c6f85f5b126d29214d0069f9b0d26ef624d98694 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Thu, 10 Oct 2024 11:47:33 -0700 Subject: [PATCH 12/13] adding newline --- eng/common/scripts/Helpers/Package-Helpers.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index 325207b5cf083..fbf5aa131d293 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -90,4 +90,4 @@ function CompatibleConvertFrom-Yaml { else { return ConvertFrom-Yaml $content } -} \ No newline at end of file +} From 753a4395e6678560342c35b5515bfdf98067b951 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Thu, 10 Oct 2024 12:49:29 -0700 Subject: [PATCH 13/13] get rid of a relative path from repo root when we cnan simply go relative to the PSScriptRoot directly --- eng/common/scripts/Helpers/Package-Helpers.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index fbf5aa131d293..985ebcc4ee3bc 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -79,7 +79,7 @@ function CompatibleConvertFrom-Yaml { # Initialize any variables or checks that need to be done once $yqPresent = Get-Command 'yq' -ErrorAction SilentlyContinue if (-not $yqPresent) { - . (Join-Path $PSScriptRoot "../../../../eng/common/scripts/Helpers" PSModule-Helpers.ps1) + . (Join-Path $PSScriptRoot PSModule-Helpers.ps1) Install-ModuleIfNotInstalled -WhatIf:$false "powershell-yaml" "0.4.1" | Import-Module } @@ -90,4 +90,4 @@ function CompatibleConvertFrom-Yaml { else { return ConvertFrom-Yaml $content } -} +} \ No newline at end of file