1
1
# Helper functions for retrieving useful information from azure-sdk-for-* repo
2
2
. " ${PSScriptRoot} \logging.ps1"
3
3
. " ${PSScriptRoot} \Helpers\Package-Helpers.ps1"
4
- class PackageProps
5
- {
4
+ class PackageProps {
6
5
[string ]$Name
7
6
[string ]$Version
8
7
[string ]$DevVersion
@@ -23,13 +22,11 @@ class PackageProps
23
22
[HashTable ]$ArtifactDetails
24
23
[HashTable []]$CIMatrixConfigs
25
24
26
- PackageProps([string ]$name , [string ]$version , [string ]$directoryPath , [string ]$serviceDirectory )
27
- {
25
+ PackageProps([string ]$name , [string ]$version , [string ]$directoryPath , [string ]$serviceDirectory ) {
28
26
$this.Initialize ($name , $version , $directoryPath , $serviceDirectory )
29
27
}
30
28
31
- PackageProps([string ]$name , [string ]$version , [string ]$directoryPath , [string ]$serviceDirectory , [string ]$group = " " )
32
- {
29
+ PackageProps([string ]$name , [string ]$version , [string ]$directoryPath , [string ]$serviceDirectory , [string ]$group = " " ) {
33
30
$this.Initialize ($name , $version , $directoryPath , $serviceDirectory , $group )
34
31
}
35
32
@@ -38,35 +35,29 @@ class PackageProps
38
35
[string ]$version ,
39
36
[string ]$directoryPath ,
40
37
[string ]$serviceDirectory
41
- )
42
- {
38
+ ) {
43
39
$this.Name = $name
44
40
$this.Version = $version
45
41
$this.DirectoryPath = $directoryPath
46
42
$this.ServiceDirectory = $serviceDirectory
47
43
$this.IncludedForValidation = $false
48
44
49
- if (Test-Path (Join-Path $directoryPath " README.md" ))
50
- {
45
+ if (Test-Path (Join-Path $directoryPath " README.md" )) {
51
46
$this.ReadMePath = Join-Path $directoryPath " README.md"
52
47
}
53
- else
54
- {
48
+ else {
55
49
$this.ReadMePath = $null
56
50
}
57
51
58
- if (Test-Path (Join-Path $directoryPath " CHANGELOG.md" ))
59
- {
52
+ if (Test-Path (Join-Path $directoryPath " CHANGELOG.md" )) {
60
53
$this.ChangeLogPath = Join-Path $directoryPath " CHANGELOG.md"
61
54
# Get release date for current version and set in package property
62
55
$changeLogEntry = Get-ChangeLogEntry - ChangeLogLocation $this.ChangeLogPath - VersionString $this.Version
63
- if ($changeLogEntry -and $changeLogEntry.ReleaseStatus )
64
- {
65
- $this.ReleaseStatus = $changeLogEntry.ReleaseStatus.Trim ().Trim(" ()" )
56
+ if ($changeLogEntry -and $changeLogEntry.ReleaseStatus ) {
57
+ $this.ReleaseStatus = $changeLogEntry.ReleaseStatus.Trim ().Trim(" ()" )
66
58
}
67
59
}
68
- else
69
- {
60
+ else {
70
61
$this.ChangeLogPath = $null
71
62
}
72
63
@@ -79,8 +70,7 @@ class PackageProps
79
70
[string ]$directoryPath ,
80
71
[string ]$serviceDirectory ,
81
72
[string ]$group
82
- )
83
- {
73
+ ) {
84
74
$this.Initialize ($name , $version , $directoryPath , $serviceDirectory )
85
75
$this.Group = $group
86
76
}
@@ -99,14 +89,14 @@ class PackageProps
99
89
if ($artifactForCurrentPackage ) {
100
90
$result = [PSCustomObject ]@ {
101
91
ArtifactConfig = [HashTable ]$artifactForCurrentPackage
102
- MatrixConfigs = @ ()
92
+ MatrixConfigs = @ ()
103
93
}
104
94
105
95
# if we know this is the matrix for our file, we should now see if there is a custom matrix config for the package
106
96
$matrixConfigList = GetValueSafelyFrom- Yaml $content @ (" extends" , " parameters" , " MatrixConfigs" )
107
97
108
98
if ($matrixConfigList ) {
109
- $result.MatrixConfigs = matrixConfigList
99
+ $result.MatrixConfigs = $ matrixConfigList
110
100
}
111
101
112
102
return $result
@@ -115,14 +105,14 @@ class PackageProps
115
105
return $null
116
106
}
117
107
118
- [void ]InitializeCIArtifacts(){
108
+ [void ]InitializeCIArtifacts() {
119
109
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot " .." " .." " .." )
120
110
121
111
$ciFolderPath = Join-Path - Path $RepoRoot - ChildPath (Join-Path " sdk" $this.ServiceDirectory )
122
112
$ciFiles = Get-ChildItem - Path $ciFolderPath - Filter " ci*.yml" - File
123
113
124
114
if (-not $this.ArtifactDetails ) {
125
- foreach ($ciFile in $ciFiles ) {
115
+ foreach ($ciFile in $ciFiles ) {
126
116
$ciArtifactResult = $this.ParseYmlForArtifact ($ciFile.FullName )
127
117
if ($ciArtifactResult ) {
128
118
$this.ArtifactDetails = [Hashtable ]$ciArtifactResult.ArtifactConfig
@@ -140,8 +130,7 @@ class PackageProps
140
130
# Returns important properties of the package relative to the language repo
141
131
# Returns a PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
142
132
# Note: python is required for parsing python package properties.
143
- function Get-PkgProperties
144
- {
133
+ function Get-PkgProperties {
145
134
Param
146
135
(
147
136
[Parameter (Mandatory = $true )]
@@ -152,10 +141,8 @@ function Get-PkgProperties
152
141
$allPkgProps = Get-AllPkgProperties - ServiceDirectory $ServiceDirectory
153
142
$pkgProps = $allPkgProps.Where ({ $_.Name -eq $PackageName -or $_.ArtifactName -eq $PackageName });
154
143
155
- if ($pkgProps.Count -ge 1 )
156
- {
157
- if ($pkgProps.Count -gt 1 )
158
- {
144
+ if ($pkgProps.Count -ge 1 ) {
145
+ if ($pkgProps.Count -gt 1 ) {
159
146
Write-Host " Found more than one project with the name [$PackageName ], choosing the first one under $ ( $pkgProps [0 ].DirectoryPath) "
160
147
}
161
148
return $pkgProps [0 ]
@@ -175,14 +162,12 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
175
162
$additionalValidationPackages = @ ()
176
163
$lookup = @ {}
177
164
178
- foreach ($pkg in $allPackageProperties )
179
- {
165
+ foreach ($pkg in $allPackageProperties ) {
180
166
$pkgDirectory = Resolve-Path " $ ( $pkg.DirectoryPath ) "
181
167
$lookupKey = ($pkg.DirectoryPath ).Replace($RepoRoot , " " ).TrimStart(' \/' )
182
168
$lookup [$lookupKey ] = $pkg
183
169
184
- foreach ($file in $targetedFiles )
185
- {
170
+ foreach ($file in $targetedFiles ) {
186
171
$filePath = Resolve-Path (Join-Path $RepoRoot $file )
187
172
$shouldInclude = $filePath -like " $pkgDirectory *"
188
173
if ($shouldInclude ) {
@@ -207,8 +192,7 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
207
192
}
208
193
}
209
194
210
- if ($AdditionalValidationPackagesFromPackageSetFn -and (Test-Path " Function:$AdditionalValidationPackagesFromPackageSetFn " ))
211
- {
195
+ if ($AdditionalValidationPackagesFromPackageSetFn -and (Test-Path " Function:$AdditionalValidationPackagesFromPackageSetFn " )) {
212
196
$packagesWithChanges += & $AdditionalValidationPackagesFromPackageSetFn $packagesWithChanges $diff $allPackageProperties
213
197
}
214
198
@@ -218,25 +202,19 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
218
202
# Takes ServiceName and Repo Root Directory
219
203
# Returns important properties for each package in the specified service, or entire repo if the serviceName is not specified
220
204
# Returns a Table of service key to array values of PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
221
- function Get-AllPkgProperties ([string ]$ServiceDirectory = $null )
222
- {
205
+ function Get-AllPkgProperties ([string ]$ServiceDirectory = $null ) {
223
206
$pkgPropsResult = @ ()
224
207
225
- if (Test-Path " Function:Get-AllPackageInfoFromRepo" )
226
- {
208
+ if (Test-Path " Function:Get-AllPackageInfoFromRepo" ) {
227
209
$pkgPropsResult = Get-AllPackageInfoFromRepo - ServiceDirectory $serviceDirectory
228
210
}
229
- else
230
- {
231
- if ([string ]::IsNullOrEmpty($ServiceDirectory ))
232
- {
233
- foreach ($dir in (Get-ChildItem (Join-Path $RepoRoot " sdk" ) - Directory))
234
- {
211
+ else {
212
+ if ([string ]::IsNullOrEmpty($ServiceDirectory )) {
213
+ foreach ($dir in (Get-ChildItem (Join-Path $RepoRoot " sdk" ) - Directory)) {
235
214
$pkgPropsResult += Get-PkgPropsForEntireService - serviceDirectoryPath $dir.FullName
236
215
}
237
216
}
238
- else
239
- {
217
+ else {
240
218
$pkgPropsResult = Get-PkgPropsForEntireService - serviceDirectoryPath (Join-Path $RepoRoot " sdk" $ServiceDirectory )
241
219
}
242
220
}
@@ -246,29 +224,24 @@ function Get-AllPkgProperties ([string]$ServiceDirectory = $null)
246
224
247
225
# Given the metadata url under https://github.com/Azure/azure-sdk/tree/main/_data/releases/latest,
248
226
# the function will return the csv metadata back as part of the response.
249
- function Get-CSVMetadata ([string ]$MetadataUri = $MetadataUri )
250
- {
227
+ function Get-CSVMetadata ([string ]$MetadataUri = $MetadataUri ) {
251
228
$metadataResponse = Invoke-RestMethod - Uri $MetadataUri - method " GET" - MaximumRetryCount 3 - RetryIntervalSec 10 | ConvertFrom-Csv
252
229
return $metadataResponse
253
230
}
254
231
255
- function Get-PkgPropsForEntireService ($serviceDirectoryPath )
256
- {
232
+ function Get-PkgPropsForEntireService ($serviceDirectoryPath ) {
257
233
$projectProps = @ () # Properties from every project in the service
258
234
$serviceDirectory = $serviceDirectoryPath -replace ' ^.*[\\/]+sdk[\\/]+([^\\/]+).*$' , ' $1'
259
235
260
- if (! $GetPackageInfoFromRepoFn -or ! (Test-Path " Function:$GetPackageInfoFromRepoFn " ))
261
- {
236
+ if (! $GetPackageInfoFromRepoFn -or ! (Test-Path " Function:$GetPackageInfoFromRepoFn " )) {
262
237
LogError " The function for '$GetPackageInfoFromRepoFn ' was not found.`
263
238
Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
264
239
See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
265
240
}
266
241
267
- foreach ($directory in (Get-ChildItem $serviceDirectoryPath - Directory))
268
- {
242
+ foreach ($directory in (Get-ChildItem $serviceDirectoryPath - Directory)) {
269
243
$pkgProps = & $GetPackageInfoFromRepoFn $directory.FullName $serviceDirectory
270
- if ($null -ne $pkgProps )
271
- {
244
+ if ($null -ne $pkgProps ) {
272
245
$projectProps += $pkgProps
273
246
}
274
247
}
0 commit comments