Skip to content

Commit 813d3f9

Browse files
authored
Add pipeline to sync latest UX files to Storage Blob (#20472)
* Add pipeline to sync latest UX files to Storage Blob * update * Add description for pipeline parameter
1 parent a4caba0 commit 813d3f9

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

.azure-pipelines/ux-portal.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Variable 'BotAccessToken' was defined in the Variables tab
2+
# Multi-job configuration must be converted to matrix strategy: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml#multi-job-configuration
3+
parameters:
4+
- name: AzurePowerShellVersion
5+
displayName: Azure PowerShell Version(like 9.0.0)
6+
type: string
7+
- name: IsLatestVersion
8+
displayName: IsLatestVersion
9+
type: boolean
10+
default: true
11+
12+
jobs:
13+
- job: Job_1
14+
displayName: "Sync latest UX metadata files to Storage Blob"
15+
timeoutInMinutes: 90
16+
pool: pool-windows-2019
17+
steps:
18+
- checkout: self
19+
- task: PowerShell@2
20+
displayName: Compress the UX metadata files
21+
inputs:
22+
targetType: inline
23+
script: >-
24+
.\CompressUXMetadata.ps1
25+
workingDirectory: tools
26+
- task: AzurePowerShell@5
27+
displayName: Upload to Storage Blob
28+
inputs:
29+
azureSubscription: 'azureps-infra-sp'
30+
ScriptType: InlineScript
31+
workingDirectory: artifacts
32+
Inline: |
33+
$context = New-AzStorageContext -StorageAccountName "$(StorageAccountName)"
34+
If ("${{ parameters.IsLatestVersion }}" -eq "True")
35+
{
36+
Copy-Item "UX.zip" -Destination "azps-latest.zip"
37+
Set-AzStorageBlobContent -Container $(StorageBlobContainerName) -Context $context -File "azps-latest.zip" -Blob "$(StorageBlobFolder)/azps-latest.zip" -Force
38+
}
39+
$zipFile = "${{ parameters.AzurePowerShellVersion }}.zip"
40+
Move-Item "UX.zip" -Destination $zipFile
41+
Set-AzStorageBlobContent -Container $(StorageBlobContainerName) -Context $context -File $zipFile -Blob "$(StorageBlobFolder)/$zipFile" -Force
42+
azurePowerShellVersion: LatestVersion
43+
pwsh: true
44+
- template: util/publish-artifacts-steps.yml
45+
parameters:
46+
artifactName: ux-portal

tools/CompressUXMetadata.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ----------------------------------------------------------------------------------
2+
# Copyright Microsoft Corporation
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
# ----------------------------------------------------------------------------------
13+
14+
# Move the UX metadata files under modules to the artifacts folder and compress them into a zip file.
15+
16+
$RootPath = "$PSScriptRoot/.."
17+
$RepoArtifacts = 'artifacts'
18+
$UXMetadataFolder = "$RootPath/$RepoArtifacts/UX"
19+
If (-Not (Test-Path -Path $UXMetadataFolder))
20+
{
21+
New-Item -ItemType Directory -Path $UXMetadataFolder
22+
}
23+
Else
24+
{
25+
Get-ChildItem $UXMetadataFolder | Remove-Item -Force -Recurse
26+
}
27+
28+
$Modules = Get-ChildItem -Path "$RootPath/src" -Directory | ForEach-Object { $_.BaseName }
29+
ForEach ($ModuleName In $Modules)
30+
{
31+
$SourceFolder = "$RootPath/src/$ModuleName"
32+
$MetadataFileArray = Get-ChildItem -Path $SourceFolder -Recurse -Filter UX | Get-ChildItem -Recurse -Filter *.json | ForEach-Object { $_.FullName }
33+
If ($MetadataFileArray.Length -Eq 0)
34+
{
35+
Continue
36+
}
37+
38+
ForEach ($MetadataFile In $MetadataFileArray)
39+
{
40+
$ResourceType = [System.IO.Path]::GetFileName([System.IO.Path]::GetDirectoryName($MetadataFile))
41+
$ResourceTypeFolder = "$UXMetadataFolder/$ResourceType"
42+
If (-Not (Test-Path -Path $ResourceTypeFolder))
43+
{
44+
New-Item -ItemType Directory -Path $ResourceTypeFolder
45+
}
46+
$FileName = [System.IO.Path]::GetFileName($MetadataFile)
47+
$TargetPath = "$ResourceTypeFolder/$FileName"
48+
If (-Not (Test-Path -Path $TargetPath))
49+
{
50+
Copy-Item -Path $MetadataFile -Destination $TargetPath
51+
}
52+
Else
53+
{
54+
#Merge the json files for the same resource type in hybrid module
55+
$Metadata1 = Get-Content -Path $TargetPath | ConvertFrom-Json
56+
$Metadata2 = Get-Content -Path $MetadataFile | ConvertFrom-Json
57+
$Metadata1.commands += $Metadata2.commands
58+
59+
ConvertTo-Json -Depth 10 -InputObject $Metadata1 | Out-File -FilePath $TargetPath
60+
}
61+
}
62+
}
63+
64+
$ArchivePath = "$RootPath/$RepoArtifacts/UX.zip"
65+
If (Test-Path -Path $ArchivePath)
66+
{
67+
Remove-Item -Path $ArchivePath -Force
68+
}
69+
Compress-Archive -Path $UXMetadataFolder/* -DestinationPath $ArchivePath

0 commit comments

Comments
 (0)