Skip to content

Commit 2f6c99d

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository (#12745)
1 parent 8fa63f3 commit 2f6c99d

File tree

5 files changed

+352
-5
lines changed

5 files changed

+352
-5
lines changed

eng/common/TestResources/New-TestResources.ps1

+20-4
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,21 @@ if ($ProvisionerApplicationId) {
154154
$subscriptionArgs = if ($SubscriptionId) {
155155
@{SubscriptionId = $SubscriptionId}
156156
}
157+
else {
158+
@{}
159+
}
157160

158161
$provisionerAccount = Retry {
159162
Connect-AzAccount -Force:$Force -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal -Environment $Environment @subscriptionArgs
160163
}
161164

162165
$exitActions += {
163166
Write-Verbose "Logging out of service principal '$($provisionerAccount.Context.Account)'"
164-
$null = Disconnect-AzAccount -AzureContext $provisionerAccount.Context
167+
168+
# Only attempt to disconnect if the -WhatIf flag was not set. Otherwise, this call is not necessary and will fail.
169+
if ($PSCmdlet.ShouldProcess($ProvisionerApplicationId)) {
170+
$null = Disconnect-AzAccount -AzureContext $provisionerAccount.Context
171+
}
165172
}
166173
}
167174

@@ -176,7 +183,6 @@ if ($TestApplicationId -and !$TestApplicationOid) {
176183
}
177184
}
178185

179-
180186
# If the ServiceDirectory is an absolute path use the last directory name
181187
# (e.g. D:\foo\bar\ -> bar)
182188
$serviceName = if (Split-Path -IsAbsolute $ServiceDirectory) {
@@ -229,6 +235,13 @@ if ($resourceGroup.ProvisioningState -eq 'Succeeded') {
229235
# New-AzResourceGroup would've written an error and stopped the pipeline by default anyway.
230236
Write-Verbose "Successfully created resource group '$($resourceGroup.ResourceGroupName)'"
231237
}
238+
elseif (($resourceGroup -eq $null) -and (-not $PSCmdlet.ShouldProcess($resourceGroupName))) {
239+
# If the -WhatIf flag was passed, there will be no resource group created. Fake it.
240+
$resourceGroup = [PSCustomObject]@{
241+
ResourceGroupName = $resourceGroupName
242+
Location = $Location
243+
}
244+
}
232245

233246
# Populate the template parameters and merge any additional specified.
234247
$templateParameters = @{
@@ -299,6 +312,9 @@ foreach ($templateFile in $templateFiles) {
299312
"$($serviceDirectoryPrefix)RESOURCE_GROUP" = $resourceGroup.ResourceGroupName;
300313
"$($serviceDirectoryPrefix)LOCATION" = $resourceGroup.Location;
301314
"$($serviceDirectoryPrefix)ENVIRONMENT" = $context.Environment.Name;
315+
"$($serviceDirectoryPrefix)AZURE_AUTHORITY_HOST" = $context.Environment.ActiveDirectoryAuthority;
316+
"$($serviceDirectoryPrefix)RESOURCE_MANAGER_URL" = $context.Environment.ResourceManagerUrl;
317+
"$($serviceDirectoryPrefix)SERVICE_MANAGEMENT_URL" = $context.Environment.ServiceManagementUrl;
302318
}
303319

304320
foreach ($key in $deployment.Outputs.Keys) {
@@ -331,7 +347,7 @@ foreach ($templateFile in $templateFiles) {
331347
}
332348
else
333349
{
334-
350+
335351
if (!$CI) {
336352
# Write an extra new line to isolate the environment variables for easy reading.
337353
Log "Persist the following environment variables based on your detected shell ($shell):`n"
@@ -340,7 +356,7 @@ foreach ($templateFile in $templateFiles) {
340356
foreach ($key in $deploymentOutputs.Keys)
341357
{
342358
$value = $deploymentOutputs[$key]
343-
359+
344360
if ($CI) {
345361
# Treat all ARM template output variables as secrets since "SecureString" variables do not set values.
346362
# In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below.
+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Common Changelog Operations
2+
3+
$RELEASE_TITLE_REGEX = "(?<releaseNoteTitle>^\#+.*(?<version>\b\d+\.\d+\.\d+([^0-9\s][^\s:]+)?)(\s(?<releaseStatus>\(Unreleased\)|\(\d{4}-\d{2}-\d{2}\)))?)"
4+
5+
# Returns a Collection of changeLogEntry object containing changelog info for all version present in the gived CHANGELOG
6+
function Get-ChangeLogEntries {
7+
param (
8+
[Parameter(Mandatory = $true)]
9+
[String]$ChangeLogLocation
10+
)
11+
12+
$changeLogEntries = @{}
13+
if (!(Test-Path $ChangeLogLocation)) {
14+
Write-Error "ChangeLog[${ChangeLogLocation}] does not exist"
15+
return $null
16+
}
17+
18+
try {
19+
$contents = Get-Content $ChangeLogLocation
20+
# walk the document, finding where the version specifiers are and creating lists
21+
$changeLogEntry = $null
22+
foreach ($line in $contents) {
23+
if ($line -match $RELEASE_TITLE_REGEX) {
24+
$changeLogEntry = [pscustomobject]@{
25+
ReleaseVersion = $matches["version"]
26+
ReleaseStatus = $matches["releaseStatus"]
27+
ReleaseTitle = $line
28+
ReleaseContent = @() # Release content without the version title
29+
}
30+
$changeLogEntries[$changeLogEntry.ReleaseVersion] = $changeLogEntry
31+
}
32+
else {
33+
if ($changeLogEntry) {
34+
$changeLogEntry.ReleaseContent += $line
35+
}
36+
}
37+
}
38+
}
39+
catch {
40+
Write-Host "Error parsing $ChangeLogLocation."
41+
Write-Host $_.Exception.Message
42+
}
43+
return $changeLogEntries
44+
}
45+
46+
# Returns single changeLogEntry object containing the ChangeLog for a particular version
47+
function Get-ChangeLogEntry {
48+
param (
49+
[Parameter(Mandatory = $true)]
50+
[String]$ChangeLogLocation,
51+
[Parameter(Mandatory = $true)]
52+
[String]$VersionString
53+
)
54+
$changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation
55+
56+
if ($changeLogEntries -and $changeLogEntries.ContainsKey($VersionString)) {
57+
return $changeLogEntries[$VersionString]
58+
}
59+
return $null
60+
}
61+
62+
#Returns the changelog for a particular version as string
63+
function Get-ChangeLogEntryAsString {
64+
param (
65+
[Parameter(Mandatory = $true)]
66+
[String]$ChangeLogLocation,
67+
[Parameter(Mandatory = $true)]
68+
[String]$VersionString
69+
)
70+
71+
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
72+
return ChangeLogEntryAsString $changeLogEntry
73+
}
74+
75+
function ChangeLogEntryAsString($changeLogEntry) {
76+
if (!$changeLogEntry) {
77+
return "[Missing change log entry]"
78+
}
79+
[string]$releaseTitle = $changeLogEntry.ReleaseTitle
80+
[string]$releaseContent = $changeLogEntry.ReleaseContent -Join [Environment]::NewLine
81+
return $releaseTitle, $releaseContent -Join [Environment]::NewLine
82+
}
83+
84+
function Confirm-ChangeLogEntry {
85+
param (
86+
[Parameter(Mandatory = $true)]
87+
[String]$ChangeLogLocation,
88+
[Parameter(Mandatory = $true)]
89+
[String]$VersionString,
90+
[boolean]$ForRelease = $false
91+
)
92+
93+
$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
94+
95+
if (!$changeLogEntry) {
96+
Write-Error "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}."
97+
return $false
98+
}
99+
100+
Write-Host "Found the following change log entry for version '${VersionString}' in [${ChangeLogLocation}]."
101+
Write-Host "-----"
102+
Write-Host (ChangeLogEntryAsString $changeLogEntry)
103+
Write-Host "-----"
104+
105+
if ([System.String]::IsNullOrEmpty($changeLogEntry.ReleaseStatus)) {
106+
Write-Error "Entry does not have a correct release status. Please ensure the status is set to a date '(yyyy-MM-dd)' or '(Unreleased)' if not yet released."
107+
return $false
108+
}
109+
110+
if ($ForRelease -eq $True) {
111+
if ($changeLogEntry.ReleaseStatus -eq "(Unreleased)") {
112+
Write-Error "Entry has no release date set. Please ensure to set a release date with format 'yyyy-MM-dd'."
113+
return $false
114+
}
115+
116+
if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) {
117+
Write-Error "Entry has no content. Please ensure to provide some content of what changed in this version."
118+
return $false
119+
}
120+
}
121+
return $true
122+
}
+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Helper functions for retireving useful information from azure-sdk-for-* repo
2+
# Example Use : Import-Module .\eng\common\scripts\modules
3+
class PackageProps
4+
{
5+
[string]$pkgName
6+
[string]$pkgVersion
7+
[string]$pkgDirectoryPath
8+
[string]$pkgServiceName
9+
[string]$pkgReadMePath
10+
[string]$pkgChangeLogPath
11+
[string]$pkgGroup
12+
13+
PackageProps([string]$pkgName,[string]$pkgVersion,[string]$pkgDirectoryPath,[string]$pkgServiceName)
14+
{
15+
$this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName)
16+
}
17+
18+
PackageProps([string]$pkgName,[string]$pkgVersion,[string]$pkgDirectoryPath,[string]$pkgServiceName,[string]$pkgGroup="")
19+
{
20+
$this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName, $pkgGroup)
21+
}
22+
23+
hidden [void]Initialize(
24+
[string]$pkgName,
25+
[string]$pkgVersion,
26+
[string]$pkgDirectoryPath,
27+
[string]$pkgServiceName
28+
)
29+
{
30+
$this.pkgName = $pkgName
31+
$this.pkgVersion = $pkgVersion
32+
$this.pkgDirectoryPath = $pkgDirectoryPath
33+
$this.pkgServiceName = $pkgServiceName
34+
35+
if (Test-Path (Join-Path $pkgDirectoryPath "README.md"))
36+
{
37+
$this.pkgReadMePath = Join-Path $pkgDirectoryPath "README.md"
38+
}
39+
else
40+
{
41+
$this.pkgReadMePath = $null
42+
}
43+
44+
if (Test-Path (Join-Path $pkgDirectoryPath "CHANGELOG.md"))
45+
{
46+
$this.pkgChangeLogPath = Join-Path $pkgDirectoryPath "CHANGELOG.md"
47+
}
48+
else
49+
{
50+
$this.pkgChangeLogPath = $null
51+
}
52+
}
53+
54+
hidden [void]Initialize(
55+
[string]$pkgName,
56+
[string]$pkgVersion,
57+
[string]$pkgDirectoryPath,
58+
[string]$pkgServiceName,
59+
[string]$pkgGroup
60+
)
61+
{
62+
$this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName)
63+
$this.pkgGroup = $pkgGroup
64+
}
65+
}
66+
67+
# Takes package name and service Name
68+
# Returns important properties of the package as related to the language repo
69+
# Returns a PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
70+
# Note: python is required for parsing python package properties.
71+
function Get-PkgProperties
72+
{
73+
Param
74+
(
75+
[Parameter(Mandatory=$true)]
76+
[string]$PackageName,
77+
[Parameter(Mandatory=$true)]
78+
[string]$ServiceName
79+
)
80+
81+
$pkgDirectoryName = $null
82+
$pkgDirectoryPath = $null
83+
$serviceDirectoryPath = Join-Path $RepoRoot "sdk" $ServiceName
84+
if (!(Test-Path $serviceDirectoryPath))
85+
{
86+
Write-Error "Service Directory $ServiceName does not exist"
87+
exit 1
88+
}
89+
90+
$directoriesPresent = Get-ChildItem $serviceDirectoryPath -Directory
91+
92+
foreach ($directory in $directoriesPresent)
93+
{
94+
$pkgDirectoryPath = Join-Path $serviceDirectoryPath $directory.Name
95+
if ($ExtractPkgProps)
96+
{
97+
$pkgProps = &$ExtractPkgProps -pkgPath $pkgDirectoryPath -serviceName $ServiceName -pkgName $PackageName
98+
}
99+
else
100+
{
101+
Write-Error "The function '${ExtractPkgProps}' was not found."
102+
}
103+
104+
if ($pkgProps -ne $null)
105+
{
106+
return $pkgProps
107+
}
108+
}
109+
Write-Error "Failed to retrive Properties for $PackageName"
110+
}
111+
112+
# Takes ServiceName and Repo Root Directory
113+
# Returns important properties for each package in the specified service, or entire repo if the serviceName is not specified
114+
# Returns an Table of service key to array values of PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
115+
function Get-AllPkgProperties ([string]$ServiceName=$null)
116+
{
117+
$pkgPropsResult = @()
118+
119+
if ([string]::IsNullOrEmpty($ServiceName))
120+
{
121+
$searchDir = Join-Path $RepoRoot "sdk"
122+
foreach ($dir in (Get-ChildItem $searchDir -Directory))
123+
{
124+
$serviceDir = Join-Path $searchDir $dir.Name
125+
126+
if (Test-Path (Join-Path $serviceDir "ci.yml"))
127+
{
128+
$activePkgList = Get-PkgListFromYml -ciYmlPath (Join-Path $serviceDir "ci.yml")
129+
if ($activePkgList -ne $null)
130+
{
131+
$pkgPropsResult = Operate-OnPackages -activePkgList $activePkgList -serviceName $dir.Name -pkgPropsResult $pkgPropsResult
132+
}
133+
}
134+
}
135+
}
136+
else
137+
{
138+
$serviceDir = Join-Path $RepoRoot "sdk" $ServiceName
139+
if (Test-Path (Join-Path $serviceDir "ci.yml"))
140+
{
141+
$activePkgList = Get-PkgListFromYml -ciYmlPath (Join-Path $serviceDir "ci.yml")
142+
if ($activePkgList -ne $null)
143+
{
144+
$pkgPropsResult = Operate-OnPackages -activePkgList $activePkgList -serviceName $ServiceName -pkgPropsResult $pkgPropsResult
145+
}
146+
}
147+
}
148+
149+
return $pkgPropsResult
150+
}
151+
152+
function Operate-OnPackages ($activePkgList, $serviceName, [Array]$pkgPropsResult)
153+
{
154+
foreach ($pkg in $activePkgList)
155+
{
156+
$pkgProps = Get-PkgProperties -PackageName $pkg["name"] -ServiceName $serviceName
157+
$pkgPropsResult += $pkgProps
158+
}
159+
return $pkgPropsResult
160+
}
161+
162+
function Get-PkgListFromYml ($ciYmlPath)
163+
{
164+
$ProgressPreference = "SilentlyContinue"
165+
Register-PSRepository -Default -ErrorAction:SilentlyContinue
166+
Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser
167+
$ciYmlContent = Get-Content $ciYmlPath -Raw
168+
$ciYmlObj = ConvertFrom-Yaml $ciYmlContent -Ordered
169+
if ($ciYmlObj.Contains("stages"))
170+
{
171+
$artifactsInCI = $ciYmlObj["stages"][0]["parameters"]["Artifacts"]
172+
}
173+
elseif ($ciYmlObj.Contains("extends"))
174+
{
175+
$artifactsInCI = $ciYmlObj["extends"]["parameters"]["Artifacts"]
176+
}
177+
if ($artifactsInCI -eq $null)
178+
{
179+
Write-Error "Failed to retrive package names in ci $ciYmlPath"
180+
}
181+
return $artifactsInCI
182+
}

eng/common/scripts/artifact-metadata-parsing.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ function IsPythonPackageVersionPublished($pkgId, $pkgVersion) {
406406
# Retrieves the list of all tags that exist on the target repository
407407
function GetExistingTags($apiUrl) {
408408
try {
409-
return (Invoke-WebRequest -Method "GET" -Uri "$apiUrl/git/refs/tags" -MaximumRetryCount 3 -RetryIntervalSec 10) | % { $_.ref.Replace("refs/tags/", "") }
409+
return (Invoke-RestMethod -Method "GET" -Uri "$apiUrl/git/refs/tags" -MaximumRetryCount 3 -RetryIntervalSec 10) | % { $_.ref.Replace("refs/tags/", "") }
410410
}
411411
catch {
412412
Write-Host $_

0 commit comments

Comments
 (0)