forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-alias.yml
92 lines (77 loc) · 3.45 KB
/
sync-alias.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Azure CLI Sync Alias
schedules:
- cron: "50 15 * * 0"
displayName: 11:50 PM (UTC + 8:00) China Weekly Run
branches:
include:
- main
# The 'resources' and 'uses' below are used to resolve the error 'Repository associated with wiki ID <WikiId> does not exist or you do not have permissions for the operation you are attempting.'
resources:
repositories:
- repository: ServiceContactList
type: git
name: internal.wiki
jobs:
- job: UpdateYaml
displayName: Update resourceManagement.yml
pool: pool-windows-2019
uses:
repositories:
- ServiceContactList
steps:
- task: UseDotNet@2
displayName: Install .NET 8 SDK
inputs:
packageType: sdk
version: 8.0.x
- pwsh: |
dotnet --version
dotnet new tool-manifest --force
dotnet tool install powershell --version 7.4.*
displayName: Install PowerShell 7.4.x
- pwsh: |
dotnet tool run pwsh -NoLogo -NoProfile -NonInteractive -File ./scripts/automation/ParseServiceContactsList.ps1 -AccessToken $env:SYSTEM_ACCESSTOKEN
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: Update resourceManagement.yml file locally
- pwsh: |
$hasChanges = git diff --name-only .github/policies
if ($null -eq $hasChanges) {
Write-Host "The wiki has no changes."
Write-Host "##vso[task.setvariable variable=ChangesDetected]false"
} else {
Write-Host "There are changes in the repository."
Write-Host "##vso[task.setvariable variable=ChangesDetected]true"
}
displayName: Check if Wiki table has any changes
- task: AzurePowerShell@5
inputs:
pwsh: true
azureSubscription: '$(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)'
ScriptType: 'InlineScript'
Inline: |
$GithubToken = Get-AzKeyVaultSecret -VaultName $(GithubPATKeyVaultName) -Name $(GithubPATKeyVaultAccount) -AsPlainText
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
azurePowerShellVersion: 'LatestVersion'
displayName: Get Github PAT from Key Vault
- pwsh: |
git config --global user.email "AzPyCLI@microsoft.com"
git config --global user.name "Azure CLI Team"
git checkout -b "sync_alias_$env:Build_BuildId"
git add .github/policies
git commit -m "Sync resourceManagement.yml"
git remote set-url origin https://azclibot:$(GithubToken)@github.com/Azure/azure-cli-extensions.git;
git push origin "sync_alias_$env:Build_BuildId" --force
displayName: Git commit and push
condition: and(succeeded(), eq(variables['ChangesDetected'], 'true'))
- pwsh: |
$Title = "{CI} Sync resourceManagement.yml according To ADO Wiki Page - Service Contact List"
$HeadBranch = "sync_alias_$env:Build_BuildId"
$BaseBranch = "main"
$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"
$Headers = @{"Accept" = "application/vnd.github+json"; "Authorization" = "Bearer $(GithubToken)" }
$RequestBody = @{"title" = $Title; "body" = $Description; "head" = $HeadBranch; "base" = $BaseBranch;}
$Uri = "https://api.github.com/repos/Azure/azure-cli-extensions/pulls"
Invoke-WebRequest -Uri $Uri -Method POST -Headers $Headers -Body ($RequestBody | ConvertTo-Json)
displayName: Create PR to main branch
condition: and(succeeded(), eq(variables['ChangesDetected'], 'true'))