Skip to content

Commit c3477cb

Browse files
Update devops helper script based on changes in azure-sdk repo (Azure#18540)
- Sync devops helper script changes - Fix issue in SemVer script when using strict mode with Language not set Co-authored-by: Wes Haggard <[email protected]>
1 parent fd0b04d commit c3477cb

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ function Invoke-AzBoardsCmd($subCmd, $parameters, $output = $true)
1212
return Invoke-Expression "$azCmdStr" | ConvertFrom-Json -AsHashTable
1313
}
1414

15-
function LoginToAzureDevops([string]$devop_pat)
15+
function LoginToAzureDevops([string]$devops_pat)
1616
{
17-
if (!$devop_pat) {
17+
if (!$devops_pat) {
1818
return
1919
}
2020
$azCmdStr = "'$devops_pat' | az devops login $($ReleaseDevOpsOrgParameters -join ' ')"
@@ -44,7 +44,7 @@ function BuildHashKey()
4444
}
4545

4646
$parentWorkItems = @{}
47-
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $true)
47+
function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand = $false)
4848
{
4949
$key = BuildHashKey $serviceName $packageDisplayName
5050
if ($key -and $parentWorkItems.ContainsKey($key)) {
@@ -73,7 +73,7 @@ function FindParentWorkItem($serviceName, $packageDisplayName, $outputCommand =
7373
foreach ($wi in $workItems) {
7474
$localKey = BuildHashKey $wi.fields["Custom.ServiceName"] $wi.fields["Custom.PackageDisplayName"]
7575
if (!$localKey) { continue }
76-
if ($parentWorkItems.ContainsKey($localKey)) {
76+
if ($parentWorkItems.ContainsKey($localKey) -and $parentWorkItems[$localKey].id -ne $wi.id) {
7777
Write-Warning "Already found parent [$($parentWorkItems[$localKey].id)] with key [$localKey], using that one instead of [$($wi.id)]."
7878
}
7979
else {
@@ -148,7 +148,7 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
148148
$query = "SELECT ${fieldList} FROM WorkItems WHERE [Work Item Type] = 'Package'"
149149

150150
if (!$includeClosed -and !$lang) {
151-
$query += " AND [State] <> 'No Active Development'"
151+
$query += " AND [State] <> 'No Active Development' AND [PackageTypeNewLibrary] = true"
152152
}
153153
if ($lang) {
154154
$query += " AND [Language] = '${lang}'"
@@ -172,7 +172,7 @@ function FindPackageWorkItem($lang, $packageName, $version, $outputCommand = $tr
172172
Write-Host "Skipping package [$($wi.id)]$($wi.fields['System.Title']) which is missing required fields language, package, or version."
173173
continue
174174
}
175-
if ($packageWorkItems.ContainsKey($localKey)) {
175+
if ($packageWorkItems.ContainsKey($localKey) -and $packageWorkItems[$localKey].id -ne $wi.id) {
176176
Write-Warning "Already found package [$($packageWorkItems[$localKey].id)] with key [$localKey], using that one instead of [$($wi.id)]."
177177
}
178178
else {
@@ -344,7 +344,7 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
344344
if ($title -ne $existingItem.fields["System.Title"]) { $changedField = "System.Title" }
345345

346346
if ($changedField) {
347-
Write-Host "At least field $changedField ($($existingItem.fields[$field])) changed so updating."
347+
Write-Host "At least field $changedField ($($existingItem.fields[$changedField])) changed so updating."
348348
}
349349

350350
$beforeState = $existingItem.fields["System.State"]
@@ -356,12 +356,12 @@ function CreateOrUpdatePackageWorkItem($lang, $pkg, $verMajorMinor, $existingIte
356356
}
357357
$existingItem = ResetWorkItemState $existingItem $beforeState -outputCommand $outputCommand
358358

359-
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $outputCommand
359+
$newparentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
360360
UpdateWorkItemParent $existingItem $newParentItem -outputCommand $outputCommand
361361
return $existingItem
362362
}
363363

364-
$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $outputCommand
364+
$parentItem = FindOrCreatePackageGroupParent $serviceName $pkgDisplayName -outputCommand $false
365365
$workItem = CreateWorkItem $title "Package" "Release" "Release" $fields $assignedTo $parentItem.id -outputCommand $outputCommand
366366
$workItem = ResetWorkItemState $workItem -outputCommand $outputCommand
367367
Write-Host "[$($workItem.id)]$lang - $pkgName($verMajorMinor) - Created"
@@ -496,7 +496,6 @@ function GetMDVersionValue($versionlist)
496496
{
497497
$mdVersions = ""
498498
$mdFormat = "| {0} | {1} | {2} |`n"
499-
$versionlist | ForEach-Object { $mdVersions += ($mdFormat -f $_.Type, $_.Version, $_.Date) }
500499

501500
$htmlVersions = ""
502501
$htmlFormat = @"
@@ -507,7 +506,11 @@ function GetMDVersionValue($versionlist)
507506
</tr>
508507
509508
"@
510-
$versionlist | ForEach-Object { $htmlVersions += ($htmlFormat -f $_.Type, $_.Version, $_.Date) }
509+
510+
foreach ($version in $versionList) {
511+
$mdVersions += ($mdFormat -f $version.Type, $version.Version, $version.Date)
512+
$htmlVersions += ($htmlFormat -f $version.Type, $version.Version, $version.Date)
513+
}
511514

512515
$htmlTemplate = @"
513516
<div style='display:none;width:0;height:0;overflow:hidden;position:absolute;font-size:0;' id=__md>| Type | Version | Date |
@@ -697,7 +700,7 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
697700
{
698701
if (!$shippedVersionSet.ContainsKey($version.Version))
699702
{
700-
$shippedVersionSet[$v.Version] = $version
703+
$shippedVersionSet[$version.Version] = $version
701704
$updateShipped = $true
702705
}
703706
}
@@ -711,7 +714,7 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
711714
}
712715
}
713716

714-
foreach ($version in $plannedVersionSet.Keys)
717+
foreach ($version in @($plannedVersionSet.Keys))
715718
{
716719
if (!$versionSet.ContainsKey($version))
717720
{
@@ -728,7 +731,7 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
728731
$fieldUpdates = @()
729732
if ($updatePlanned)
730733
{
731-
$plannedPackages = GetMDVersionValue ($plannedVersionSet.Values | Sort-Object Date, Version -Descending)
734+
$plannedPackages = GetMDVersionValue ($plannedVersionSet.Values | Sort-Object {$_.Date -as [DateTime]}, Version -Descending)
732735
$fieldUpdates += @"
733736
{
734737
"op": "replace",
@@ -740,7 +743,7 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
740743

741744
if ($updateShipped)
742745
{
743-
$newShippedVersions = $shippedVersionSet.Values | Sort-Object Date, Version -Descending
746+
$newShippedVersions = $shippedVersionSet.Values | Sort-Object {$_.Date -as [DateTime]}, Version -Descending
744747
$shippedPackages = GetMDVersionValue $newShippedVersions
745748
$fieldUpdates += @"
746749
{
@@ -771,15 +774,14 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
771774
}
772775

773776
# Full merged version set
774-
$versionList = $versionSet.Values | Sort-Object Date, Version -Descending
777+
$versionList = $versionSet.Values | Sort-Object {$_.Date -as [DateTime]}, Version -Descending
775778

776779
$versionFieldUpdates = GetTextVersionFields $versionList $pkgWorkItem
777780
if ($versionFieldUpdates.Count -gt 0)
778781
{
779782
$fieldUpdates += $versionFieldUpdates
780783
}
781784

782-
783785
# If no version files to update do nothing
784786
if ($fieldUpdates.Count -eq 0) {
785787
return
@@ -796,9 +798,18 @@ function UpdatePackageVersions($pkgWorkItem, $plannedVersions, $shippedVersions)
796798

797799
$body = "[" + ($fieldUpdates -join ',') + "]"
798800

799-
# Get a temp access token from the logged in az cli user for azure devops resource
800-
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
801-
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
801+
$headers = $null
802+
if ($devops_pat)
803+
{
804+
$encodedToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([string]::Format("{0}:{1}", "", $devops_pat)))
805+
$headers = @{ Authorization = "Basic $encodedToken" }
806+
}
807+
else
808+
{
809+
# Get a temp access token from the logged in az cli user for azure devops resource
810+
$jwt_accessToken = (az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
811+
$headers = @{ Authorization = "Bearer $jwt_accessToken" }
812+
}
802813
$response = Invoke-RestMethod -Method PATCH `
803814
-Uri "https://dev.azure.com/azure-sdk/_apis/wit/workitems/${id}?api-version=6.0" `
804815
-Headers $headers -Body $body -ContentType "application/json-patch+json"

eng/common/scripts/SemVer.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class AzureEngSemanticVersion {
3434
# Regex inspired but simplified from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
3535
# Validation: https://regex101.com/r/vkijKf/426
3636
static [string] $SEMVER_REGEX = "(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:(?<presep>-?)(?<prelabel>[a-zA-Z]+)(?:(?<prenumsep>\.?)(?<prenumber>[0-9]{1,8})(?:(?<buildnumsep>\.?)(?<buildnumber>\d{1,3}))?)?)?"
37-
static [string] $ParseLanguage = $Language
3837

3938
static [AzureEngSemanticVersion] ParseVersionString([string] $versionString)
4039
{
@@ -68,7 +67,9 @@ class AzureEngSemanticVersion {
6867
$this.Minor = [int]$matches.Minor
6968
$this.Patch = [int]$matches.Patch
7069

71-
if ([AzureEngSemanticVersion]::ParseLanguage -eq "python") {
70+
# If Language exists and is set to python setup the python conventions.
71+
$parseLanguage = (Get-Variable -Name "Language" -ValueOnly -ErrorAction "Ignore")
72+
if ($parseLanguage -eq "python") {
7273
$this.SetupPythonConventions()
7374
}
7475
else {
@@ -194,6 +195,7 @@ class AzureEngSemanticVersion {
194195

195196
static [void] QuickTests()
196197
{
198+
$global:Language = ""
197199
$versions = @(
198200
"1.0.1",
199201
"2.0.0",
@@ -257,7 +259,7 @@ class AzureEngSemanticVersion {
257259
Write-Host "Error: alpha string did not correctly round trip with ToString. Expected: $($alphaVerString), Actual: $($alphaVer)"
258260
}
259261

260-
[AzureEngSemanticVersion]::ParseLanguage = "python"
262+
$global:Language = "python"
261263
$pythonAlphaVerString = "1.2.3a20200828009"
262264
$pythonAlphaVer = [AzureEngSemanticVersion]::new($pythonAlphaVerString)
263265
if (!$pythonAlphaVer.IsPrerelease) {
@@ -290,7 +292,7 @@ class AzureEngSemanticVersion {
290292
}
291293
}
292294

293-
[AzureEngSemanticVersion]::ParseLanguage = ""
295+
$global:Language = ""
294296

295297
$gaVerString = "1.2.3"
296298
$gaVer = [AzureEngSemanticVersion]::ParseVersionString($gaVerString)

0 commit comments

Comments
 (0)