Skip to content

Commit

Permalink
{CI} Sync resourceManagement.yml according To ADO Wiki Page - Service…
Browse files Browse the repository at this point in the history
… Contact List (Azure#8288)

* {CI} Sync resourceManagement.yml alias pipeline

* create pr against main branch

* Sync resourceManagement.yml

---------

Co-authored-by: Qi Pan <[email protected]>
  • Loading branch information
azclibot and Pan-Qi authored Nov 20, 2024
1 parent b09ccf5 commit da7e2d4
Show file tree
Hide file tree
Showing 3 changed files with 717 additions and 98 deletions.
92 changes: 92 additions & 0 deletions .azure-pipelines/sync-alias.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 "[email protected]"
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'))
Loading

0 comments on commit da7e2d4

Please sign in to comment.