|
| 1 | +name: Azure CLI Sync Squad Mapping |
| 2 | + |
| 3 | +schedules: |
| 4 | +- cron: "20 16 * * 0" |
| 5 | + displayName: 12:20 AM (UTC + 8:00) China Weekly Run |
| 6 | + branches: |
| 7 | + include: |
| 8 | + - dev |
| 9 | + |
| 10 | +resources: |
| 11 | + repositories: |
| 12 | + - repository: SquadMappingWiki |
| 13 | + type: git |
| 14 | + name: internal.wiki |
| 15 | + |
| 16 | +variables: |
| 17 | +- template: ${{ variables.Pipeline.Workspace }}/.azure-pipelines/templates/variables.yml |
| 18 | + |
| 19 | +jobs: |
| 20 | +- job: UpdateYaml |
| 21 | + displayName: Update resourceManagement.yml with squad labels |
| 22 | + pool: |
| 23 | + name: ${{ variables.windows_pool }} |
| 24 | + uses: |
| 25 | + repositories: |
| 26 | + - SquadMappingWiki |
| 27 | + |
| 28 | + steps: |
| 29 | + - task: UseDotNet@2 |
| 30 | + displayName: Install .NET 8 SDK |
| 31 | + inputs: |
| 32 | + packageType: sdk |
| 33 | + version: 8.0.x |
| 34 | + |
| 35 | + - pwsh: | |
| 36 | + dotnet --version |
| 37 | + dotnet new tool-manifest --force |
| 38 | + dotnet tool install powershell --version 7.4.* |
| 39 | + displayName: Install PowerShell 7.4.x |
| 40 | +
|
| 41 | + - pwsh: | |
| 42 | + dotnet tool run pwsh -NoLogo -NoProfile -NonInteractive -File ./tools/Github/ParseSquadMappingList.ps1 -AccessToken $env:SYSTEM_ACCESSTOKEN |
| 43 | + env: |
| 44 | + SYSTEM_ACCESSTOKEN: $(System.AccessToken) |
| 45 | + displayName: Update resourceManagement.yml file locally |
| 46 | +
|
| 47 | + - pwsh: | |
| 48 | + $hasChanges = git diff --name-only .github/policies |
| 49 | + if ($null -eq $hasChanges) { |
| 50 | + Write-Host "The wiki has no changes." |
| 51 | + Write-Host "##vso[task.setvariable variable=ChangesDetected]false" |
| 52 | + } else { |
| 53 | + Write-Host "There are changes in the wiki." |
| 54 | + Write-Host "##vso[task.setvariable variable=ChangesDetected]true" |
| 55 | + } |
| 56 | + displayName: Check if Wiki table has any changes |
| 57 | +
|
| 58 | + - task: AzurePowerShell@5 |
| 59 | + inputs: |
| 60 | + pwsh: true |
| 61 | + azureSubscription: '$(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)' |
| 62 | + ScriptType: 'InlineScript' |
| 63 | + Inline: | |
| 64 | + $GithubToken = Get-AzKeyVaultSecret -VaultName $(GithubPATKeyVaultName) -Name $(GithubPATKeyVaultAccount) -AsPlainText |
| 65 | + Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken" |
| 66 | + azurePowerShellVersion: 'LatestVersion' |
| 67 | + displayName: Get Github PAT from Key Vault |
| 68 | + condition: and(succeeded(), eq(variables['ChangesDetected'], 'true')) |
| 69 | + |
| 70 | + - pwsh: | |
| 71 | + git config --global user.email "AzPyCLI@microsoft.com" |
| 72 | + git config --global user.name "Azure CLI Team" |
| 73 | + git checkout -b "sync_squad_mapping_$env:Build_BuildId" |
| 74 | +
|
| 75 | + git add .github/policies |
| 76 | + git commit -m "Sync resourceManagement.yml for squad mapping" |
| 77 | +
|
| 78 | + git remote add azclibot https://azclibot:$(GithubToken)@github.com/azclibot/azure-cli.git |
| 79 | + git push azclibot "sync_squad_mapping_$env:Build_BuildId" --force |
| 80 | + displayName: Git commit and push |
| 81 | + condition: and(succeeded(), eq(variables['ChangesDetected'], 'true')) |
| 82 | +
|
| 83 | + - pwsh: | |
| 84 | + $Title = "{CI} Sync squad mapping labels from ADO Wiki to resourceManagement.yml" |
| 85 | + $HeadBranch = "azclibot:sync_squad_mapping_$env:Build_BuildId" |
| 86 | + $BaseBranch = "dev" |
| 87 | + $Description = "This PR synchronizes squad labels in resourceManagement.yml based on the Squad Mapping ADO wiki page." |
| 88 | +
|
| 89 | + $Headers = @{"Accept" = "application/vnd.github+json"; "Authorization" = "Bearer $(GithubToken)" } |
| 90 | + $RequestBody = @{"title" = $Title; "body" = $Description; "head" = $HeadBranch; "base" = $BaseBranch;} |
| 91 | + $Uri = "https://api.github.com/repos/Azure/azure-cli/pulls" |
| 92 | +
|
| 93 | + Invoke-WebRequest -Uri $Uri -Method POST -Headers $Headers -Body ($RequestBody | ConvertTo-Json) |
| 94 | + displayName: Create PR to azure/azure-cli dev branch |
| 95 | + condition: and(succeeded(), eq(variables['ChangesDetected'], 'true')) |
0 commit comments