-
Notifications
You must be signed in to change notification settings - Fork 94
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
Adding MAR Manifest file generator #726
Open
krbar
wants to merge
11
commits into
Azure:main
Choose a base branch
from
krbar:users/krbar/setBicepMcr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3a4e907
Add MARManifestGenerator PowerShell script
krbar 1d4a91c
Updated parameters synopsis
krbar 13c2f12
Add example call of Set-MARManifest function
krbar a604e30
Addressed linter errors
krbar 9836de8
Update Set-MARManifest.ps1 script
krbar d40b52e
Refactor Set-MARManifest.ps1 to use Join-Path cmdlet for header file …
krbar 2afaaf7
Removed empty last line
krbar d46e923
Refactor YAML entry formatting in Set-MARManifest.ps1
krbar fe553a0
Updated order of the functions (moved main function to the top)
krbar b01798a
Renamed parameter OutputPath to more accurate OutputFile
krbar bfbcf6c
Merge branch 'main' of https://github.com/Azure/Azure-Verified-Module…
krbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
utilities/tools/MARManifestGenerator/Set-MARManifest.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,160 @@ | ||||||
<# | ||||||
.SYNOPSIS | ||||||
Creates the Bicep module YAML file in MCR | ||||||
|
||||||
.DESCRIPTION | ||||||
The function generates the MCR bicep.yaml file based on the AVM CSV files. It uses the Get-ModuleYamlBlock function | ||||||
to create the YAML entries for the Bicep-Resource and Bicep-Pattern modules, then it composes the bicep.yaml file | ||||||
and saves it to the specified location. | ||||||
|
||||||
.PARAMETER OutputFile | ||||||
The path where the bicep.yaml file should be saved. | ||||||
|
||||||
.EXAMPLE | ||||||
Set-MARManifest -OutputFile bicep.yml | ||||||
|
||||||
.NOTES | ||||||
The entries are sorted by the full module name. | ||||||
#> | ||||||
Function Set-MARManifest { | ||||||
[CmdletBinding(SupportsShouldProcess)] | ||||||
param ( | ||||||
[Parameter(Mandatory = $false)] | ||||||
[string] $OutputFile = $(Join-Path $PSScriptRoot 'bicep.yml') | ||||||
) | ||||||
|
||||||
# Retrieve the converted YAML entries for the Bicep-Resource and Bicep-Pattern modules | ||||||
$yamlEntries = Get-ModuleYamlBlock | ||||||
|
||||||
# Constructing the output file content | ||||||
# Adding the header file to the output file content | ||||||
$headerFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'manifestHeader.yml' | ||||||
if (-not (Test-Path $headerFilePath)) { | ||||||
Write-Error "The header file [$headerFilePath] does not exist." | ||||||
} | ||||||
|
||||||
# Adding the header file content to the output file content | ||||||
$outputFileContent = Get-Content -Path $headerFilePath | ||||||
|
||||||
# Adding the Bicep-Resource YAML entries to the output file content | ||||||
$outputFileContent += $yamlEntries | ||||||
|
||||||
# Save the output file | ||||||
$outputFileContent | Out-File -FilePath $OutputFile -Force | ||||||
} | ||||||
|
||||||
<# | ||||||
.SYNOPSIS | ||||||
Parses AVM module CSV files | ||||||
|
||||||
.DESCRIPTION | ||||||
The CSV files will be parsed and returned a an object | ||||||
|
||||||
.PARAMETER ModuleIndexURLs | ||||||
Array the URLs, where module CSV files for Resource and Pattern modules are stored | ||||||
|
||||||
.EXAMPLE | ||||||
Get-AvmCsvData -ModuleIndexURLs 'https://example.com/url3', 'https://example.com/url4' | ||||||
|
||||||
#> | ||||||
Function Get-AvmCsvData { | ||||||
[CmdletBinding()] | ||||||
param ( | ||||||
[Parameter(Mandatory=$false)] | ||||||
[string[]] $ModuleIndexURLs = @('https://aka.ms/avm/index/bicep/res/csv', 'https://aka.ms/avm/index/bicep/ptn/csv') | ||||||
) | ||||||
|
||||||
$formattedBicepFullCsv = @() | ||||||
|
||||||
foreach ($url in $ModuleIndexURLs) { | ||||||
try { | ||||||
$unfilteredCSV = Invoke-WebRequest -Uri $url | ||||||
} | ||||||
catch { | ||||||
Write-Error "Unable to retrieve CSV file - Check network connection." | ||||||
} | ||||||
|
||||||
# Convert the CSV content to a PowerShell object | ||||||
$formattedBicepFullCsv += ConvertFrom-CSV $unfilteredCSV.Content | ||||||
} | ||||||
|
||||||
# Loop through each item in the filtered data | ||||||
foreach ($item in $formattedBicepFullCsv) { | ||||||
# Remove '@Azure/' from the ModuleOwnersGHTeam property | ||||||
$item.ModuleOwnersGHTeam = $item.ModuleOwnersGHTeam -replace '@Azure/', '' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Careful with the regex |
||||||
# Remove '@Azure/' from the ModuleContributorsGHTeam property | ||||||
$item.ModuleContributorsGHTeam = $item.ModuleContributorsGHTeam -replace '@Azure/', '' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
# Return the modified data | ||||||
return $formattedBicepFullCsv | ||||||
} | ||||||
|
||||||
<# | ||||||
.SYNOPSIS | ||||||
Creates a block of YAML entries based on a AVM CSV file | ||||||
|
||||||
.DESCRIPTION | ||||||
The function reads the AVM CSV file and converts all entries into a YAML file entries for the MCR bicep.yaml file. | ||||||
|
||||||
.PARAMETER logoURL | ||||||
URL to the logo image for all modules. | ||||||
|
||||||
.PARAMETER supportLink | ||||||
URL to the support page for all modules. | ||||||
|
||||||
.PARAMETER IndentFirstLine | ||||||
Number of spaces to indent the first line of the YAML entry. | ||||||
|
||||||
.PARAMETER IndentOtherLines | ||||||
Number of spaces to indent the other lines of the YAML entry. | ||||||
|
||||||
.EXAMPLE | ||||||
Get-ModuleYamlBlock -ModuleIndex Bicep-Resource -IndentFirstLine 2 -IndentOtherLines 4 | ||||||
|
||||||
.NOTES | ||||||
The entries are sorted by the module name. | ||||||
#> | ||||||
Function Get-ModuleYamlBlock { | ||||||
[CmdletBinding()] | ||||||
param ( | ||||||
[Parameter(Mandatory=$false)] | ||||||
[string] $logoURL = 'https://raw.githubusercontent.com/Azure/bicep/main/src/vscode-bicep/icons/bicep-logo-256.png', | ||||||
|
||||||
[Parameter(Mandatory=$false)] | ||||||
[string] $supportLink = 'https://github.com/Azure/bicep-registry-modules/issues', | ||||||
|
||||||
[Parameter(Mandatory=$false)] | ||||||
[int] $IndentFirstLine = 2, | ||||||
|
||||||
[Parameter(Mandatory=$false)] | ||||||
[int] $IndentOtherLines = 4 | ||||||
) | ||||||
|
||||||
# Retrieve the CSV data and sort it by the module name | ||||||
$csvData = Get-AvmCsvData | Sort-Object -Property ModuleName | ||||||
|
||||||
# Create an array to store YAML entries | ||||||
$yamlEntries = @() | ||||||
|
||||||
# Iterate through each CSV entry and convert it to a YAML entry | ||||||
foreach ($csvLine in $csvData) { | ||||||
$yamlEntry = @' | ||||||
{6}- name: public/bicep/{0} | ||||||
{7}displayName: {1} | ||||||
{7}description: {2} | ||||||
{7}logoUrl: {3} | ||||||
{7}supportLink: {4} | ||||||
{7}documentationLink: {5}/README.md | ||||||
'@ | ||||||
if ($csvLine -ne $csvData[-1]) { # Add a newline between entries, except for the last one | ||||||
$yamlEntries += $yamlEntry -f ($csvLine.ModuleName, $csvLine.ModuleDisplayName, $csvLine.Description, $logoURL, $supportLink, $csvLine.RepoURL, $(' ' * $IndentFirstLine), $(' ' * $IndentOtherLines)) + [Environment]::NewLine | ||||||
} | ||||||
else { | ||||||
$yamlEntries += $yamlEntry -f ($csvLine.ModuleName, $csvLine.ModuleDisplayName, $csvLine.Description, $logoURL, $supportLink, $csvLine.RepoURL, $(' ' * $IndentFirstLine), $(' ' * $IndentOtherLines)) | ||||||
} | ||||||
} | ||||||
|
||||||
# Return the YAML entries | ||||||
return $yamlEntries | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.