Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{CI} Sync resourceManagement.yml according To ADO Wiki Page - Service Contact List #8287

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading