Skip to content
Merged
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
95 changes: 95 additions & 0 deletions .azure-pipelines/sync-squad-mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Azure CLI Sync Squad Mapping

schedules:
- cron: "20 16 * * 0"
displayName: 12:20 AM (UTC + 8:00) China Weekly Run
branches:
include:
- dev

resources:
repositories:
- repository: SquadMappingWiki
type: git
name: internal.wiki

variables:
- template: ${{ variables.Pipeline.Workspace }}/.azure-pipelines/templates/variables.yml

jobs:
- job: UpdateYaml
displayName: Update resourceManagement.yml with squad labels
pool:
name: ${{ variables.windows_pool }}
uses:
repositories:
- SquadMappingWiki

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 ./tools/Github/ParseSquadMappingList.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 wiki."
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
condition: and(succeeded(), eq(variables['ChangesDetected'], 'true'))

- pwsh: |
git config --global user.email "AzPyCLI@microsoft.com"
git config --global user.name "Azure CLI Team"
git checkout -b "sync_squad_mapping_$env:Build_BuildId"

git add .github/policies
git commit -m "Sync resourceManagement.yml for squad mapping"

git remote add azclibot https://azclibot:$(GithubToken)@github.com/azclibot/azure-cli.git
git push azclibot "sync_squad_mapping_$env:Build_BuildId" --force
displayName: Git commit and push
condition: and(succeeded(), eq(variables['ChangesDetected'], 'true'))

- pwsh: |
$Title = "{CI} Sync squad mapping labels from ADO Wiki to resourceManagement.yml"
$HeadBranch = "azclibot:sync_squad_mapping_$env:Build_BuildId"
$BaseBranch = "dev"
$Description = "This PR synchronizes squad labels in resourceManagement.yml based on the Squad Mapping 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/pulls"

Invoke-WebRequest -Uri $Uri -Method POST -Headers $Headers -Body ($RequestBody | ConvertTo-Json)
displayName: Create PR to azure/azure-cli dev branch
condition: and(succeeded(), eq(variables['ChangesDetected'], 'true'))
Loading
Loading