Skip to content

Commit 2856260

Browse files
authored
Updated sync aliases pipeline after migrating from fabricbot.json to resourceManagement.yml (#22641)
* Updated the synchronization of service contact list per new yaml config schema * Fixed mentionee issue and only committed files under policies folder
1 parent 00b976d commit 2856260

File tree

3 files changed

+159
-91
lines changed

3 files changed

+159
-91
lines changed

.azure-pipelines/sync-aliases.yml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,40 @@ schedules:
77
- main
88

99
jobs:
10-
- job: UpdateJson
11-
displayName: Update fabricbot.json
10+
- job: UpdateYaml
11+
displayName: Update resourceManagement.yml
12+
pool: pool-windows-2019
13+
1214
steps:
15+
- task: UseDotNet@2
16+
displayName: Install .NET 7 SDK
17+
inputs:
18+
packageType: sdk
19+
version: 7.0.x
20+
21+
- pwsh: |
22+
dotnet --version
23+
dotnet new tool-manifest --force
24+
dotnet tool install powershell
25+
displayName: Install Latest PowerShell (7.3+)
26+
1327
- task: AzurePowerShell@5
1428
inputs:
1529
azureSubscription: 'Azure SDK Infrastructure'
1630
ScriptType: 'InlineScript'
1731
Inline: |
1832
$ADOTokenValue = Get-AzKeyVaultSecret -VaultName ${env:KEYVAULTNAME} -Name ${env:ADOTOKENNAME} -AsPlainText
19-
Write-Host "##vso[task.setvariable variable=ADOToken;issecret=true]$ADOTokenValue"
33+
Write-Host "##vso[task.setvariable variable=ADOToken;issecret=true]$ADOTokenValue"
2034
azurePowerShellVersion: 'LatestVersion'
2135
displayName: Get ADOToken from Key Vault
2236

2337
- pwsh: |
24-
./tools/Github/ParseWiki2Json.ps1 -ADOToken $(ADOToken)
25-
displayName: Update fabricbot.json file locally
38+
dotnet tool run pwsh -NoLogo -NoProfile -NonInteractive -File "./tools/Github/ParseServiceContactsList.ps1 -ADOToken $(ADOToken)"
39+
displayName: Update resourceManagement.yml file locally
2640
2741
- pwsh: |
28-
$gitStatus = git status -s
29-
if (-not $gitStatus) {
42+
$hasChanges = git diff --name-only .github/policies
43+
if ($null -eq $hasChanges) {
3044
Write-Host "The wiki has no changes."
3145
Write-Host "##vso[task.setvariable variable=ChangesDetected]false"
3246
} else {
@@ -38,21 +52,21 @@ jobs:
3852
- pwsh: |
3953
git config --global user.email "[email protected]"
4054
git config --global user.name "azure-powershell-bot"
41-
git checkout -b "internal/sync-fabricbot-json"
42-
43-
git add .
44-
git commit -m "Sync fabricbot.json"
45-
55+
git checkout -b "internal/sync-resourcemanagement-yml"
56+
57+
git add .github/policies
58+
git commit -m "Sync resourceManagement.yml"
59+
4660
git remote set-url origin https://azure-powershell-bot:$(BotAccessToken)@github.com/Azure/azure-powershell.git;
47-
git push origin internal/sync-fabricbot-json --force
61+
git push origin internal/sync-resourcemanagement-yml --force
4862
displayName: Git commit and push
4963
condition: and(succeeded(), eq(variables['ChangesDetected'], 'true'))
50-
64+
5165
- pwsh: |
52-
$Title = "Sync fabricbot.json According To ADO Wiki Page"
53-
$HeadBranch = "internal/sync-fabricbot-json"
66+
$Title = "Sync resourceManagement.yml according To ADO Wiki Page - Service Contact List"
67+
$HeadBranch = "internal/sync-resourcemanagement-yml"
5468
$BaseBranch = "main"
55-
$Description = "This PR sync taskType: scheduledAndTrigger part of fabricbot.json from table of Service-Team-Label-and-Contact-List in ADO wiki page"
69+
$Description = "This PR synchronizes the task: 'Triage issues to the service team' part of resourceManagement.yml from table of Service Contact List in ADO wiki page"
5670
./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(BotAccessToken) -Description $Description
5771
displayName: Create PR to main branch
5872
condition: and(succeeded(), eq(variables['ChangesDetected'], 'true'))
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Sync ADO Wiki Service Contact List to resourceManagement.yml.
18+
19+
#>
20+
param(
21+
[Parameter(Mandatory = $true)]
22+
[string]$ADOToken
23+
)
24+
25+
function InitializeRequiredPackages {
26+
[CmdletBinding()]
27+
param ()
28+
29+
$packagesDirectoryName = "JsonYamlPackages"
30+
$packagesDirectory = Join-Path -Path . -ChildPath $packagesDirectoryName
31+
if (Test-Path -LiteralPath $packagesDirectory) {
32+
Remove-Item -LiteralPath $packagesDirectory -Recurse -Force
33+
}
34+
35+
New-Item -Path . -Name $packagesDirectoryName -ItemType Directory -Force
36+
37+
$requiredPackages = @(
38+
@{ PackageName = "Newtonsoft.Json"; PackageVersion = "13.0.2"; DllName = "Newtonsoft.Json.dll" },
39+
@{ PackageName = "YamlDotNet"; PackageVersion = "13.2.0"; DllName = "YamlDotNet.dll" }
40+
41+
)
42+
43+
$requiredPackages | ForEach-Object {
44+
$packageName = $_["PackageName"]
45+
$packageVersion = $_["PackageVersion"]
46+
$packageDll = $_["DllName"]
47+
Install-Package -Name $packageName -RequiredVersion $packageVersion -Source "https://www.nuget.org/api/v2" -Destination $packagesDirectory -SkipDependencies -ExcludeVersion -Force
48+
Add-Type -LiteralPath (Join-Path -Path $packagesDirectory -ChildPath $packageName | Join-Path -ChildPath "lib" | Join-Path -ChildPath "net6.0" | Join-Path -ChildPath $packageDll) -ErrorAction SilentlyContinue
49+
}
50+
}
51+
52+
# get wiki content
53+
$username = ""
54+
$password = $ADOToken
55+
$pair = "{0}:{1}" -f ($username, $password)
56+
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
57+
$token = [System.Convert]::ToBase64String($bytes)
58+
$headers = @{
59+
Authorization = "Basic {0}" -f ($token)
60+
}
61+
62+
$response = Invoke-RestMethod 'https://dev.azure.com/azclitools/internal/_apis/wiki/wikis/internal.wiki/pages?path=/Service%20Contact%20List&includeContent=true' -Headers $headers
63+
$contactsList = ($response.content -split "\n") | Where-Object { $_ -like '|*' } | Select-Object -Skip 2
64+
65+
$idxServiceTeamLabel = 2
66+
$idxPSNotifyGithubHandler = 6
67+
$serviceContacts = [System.Collections.Generic.SortedList[System.String, PSCustomObject]]::new()
68+
69+
foreach ($contacts in $contactsList) {
70+
$items = $contacts -split "\|"
71+
$colServiceTeamLabel = $items[$idxServiceTeamLabel]
72+
if (![string]::IsNullOrWhiteSpace($colServiceTeamLabel)) {
73+
$serviceTeamLabel = $colServiceTeamLabel.Trim()
74+
$colPSNotifyGithubHandler = $items[$idxPSNotifyGithubHandler]
75+
76+
if (![string]::IsNullOrWhiteSpace($colPSNotifyGithubHandler)) {
77+
$psNotifyGithubHandler = $colPSNotifyGithubHandler.Trim()
78+
[array]$mentionees = $psNotifyGithubHandler.Split(",", [StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object {
79+
$_.Trim()
80+
}
81+
82+
$serviceContacts.Add($serviceTeamLabel, [PSCustomObject]@{
83+
if = @(
84+
[PSCustomObject]@{
85+
hasLabel = [PSCustomObject]@{
86+
label = 'Service Attention'
87+
}
88+
},
89+
[PSCustomObject]@{
90+
hasLabel = [PSCustomObject]@{
91+
label = $serviceTeamLabel
92+
}
93+
}
94+
)
95+
then = @(
96+
[PSCustomObject]@{
97+
mentionUsers = [PSCustomObject]@{
98+
mentionees = $mentionees
99+
replyTemplate = 'Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc ${mentionees}.'
100+
assignMentionees = 'False'
101+
}
102+
}
103+
)
104+
})
105+
}
106+
}
107+
}
108+
109+
# Update yaml file
110+
InitializeRequiredPackages
111+
112+
$yamlConfigPath = $PSScriptRoot | Split-Path | Split-Path | Join-Path -ChildPath ".github" | Join-Path -ChildPath "policies" | Join-Path -ChildPath "resourceManagement.yml"
113+
$yamlContent = Get-Content -Path $yamlConfigPath -Raw
114+
$yamlDeserializer = [YamlDotNet.Serialization.DeserializerBuilder]::new().Build()
115+
$yamlObjectGraph = $yamlDeserializer.Deserialize($yamlContent)
116+
$jsonSerializer = [YamlDotNet.Serialization.SerializerBuilder]::new().JsonCompatible().Build()
117+
$jsonObjectGraph = $jsonSerializer.Serialize($yamlObjectGraph) | ConvertFrom-Json
118+
119+
$serviceContactsTask = $jsonObjectGraph.configuration.resourceManagementConfiguration.eventResponderTasks | Where-Object { $_.description -eq "Triage issues to the service team" }
120+
if ($null -ne $serviceContactsTask) {
121+
$serviceContactsTask.then = $serviceContacts.Values
122+
}
123+
124+
$updatedJsonContent = $jsonObjectGraph | ConvertTo-Json -Depth 64
125+
$updatedJsonObjectGraph = [Newtonsoft.Json.JsonConvert]::DeserializeObject[System.Dynamic.ExpandoObject]($updatedJsonContent)
126+
$yamlSerializer = [YamlDotNet.Serialization.SerializerBuilder]::new().Build()
127+
$updatedYamlContent = $yamlSerializer.Serialize($updatedJsonObjectGraph)
128+
$updatedYamlContent | Out-File -FilePath $yamlConfigPath -NoNewline -Force

tools/Github/ParseWiki2Json.ps1

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)