Skip to content

[Feature Request]: Move the metadata.json content to the template, update utilities & tests #3425

Closed

Description

Description

The title says it all.

Since version 0.19.5 we can now implement the metadata in the main.bicep template itself and should do so in preparation of the Public Bicep Registry migration.

Reference: link

Script to use for migration
[CmdletBinding(SupportsShouldProcess = $true)]
param ()

$path = 'C:\dev\ip\Azure-ResourceModules\ResourceModules\modules'
$metadataJsonFiles = Get-ChildItem -Path $path -Recurse -File -Filter 'metadata.json' | Select-Object -ExpandProperty 'FullName'

foreach ($metadataJsonFile in $metadataJsonFiles) {

    $metadataContent = ConvertFrom-Json (Get-Content -Path $metadataJsonFile -Raw)

    $templatePath = Join-Path (Split-Path $metadataJsonFile -Parent) 'main.bicep'
    $templateContent = Get-Content -Path $templatePath

    $newTemplateContent = @(
        "metadata name = '{0}'" -f $metadataContent.name
    )

    #

    $summary = $metadataContent.summary
    $summaryParts = $summary -split '\n'

    if ($summaryParts.Count -gt 2) {
        $newTemplateContent += @(
            "metadata description = '''{0}" -f $summaryParts[0]
        )

        $summaryParts[1 .. ($summaryParts.Count - 2)] | ForEach-Object {
            $newTemplateContent += @(
                $_
            )
        }

        $newTemplateContent += @(
            "{0}'''" -f $summaryParts[-1]
        )
    } elseif ($summaryParts.Count -ge 2) {
        $newTemplateContent += @(
            "metadata description = '''{0}" -f $summaryParts[0],
            "{0}'''" -f $summaryParts[1]
        )
    } else {
        $newTemplateContent += @(
            "metadata description = '{0}'" -f $metadataContent.summary
        )
    }

    $newTemplateContent += @(
        "metadata owner = '{0}'" -f $metadataContent.owner
        ''
    )

    $newTemplateContent += $templateContent

    if ($PSCmdlet.ShouldProcess("File [$templatePath]", 'Update')) {
        Set-Content -Path $templatePath -Value $newTemplateContent -Force -Encoding 'UTF8'
    }
    if ($PSCmdlet.ShouldProcess("File [$metadataJsonFile]", 'Remove')) {
        Remove-Item -Path $metadataJsonFile -Force
    }
}

Activity

  1. moved this from Needs triage to To do in Backlogon Jul 14, 2023
  2. added
    [cat] modules
    [cat] testing
    [cat] utilities
    on Jul 14, 2023
  3. moved this from To do to In progress in Backlogon Jul 14, 2023
  4. moved this from In progress to Ready for review in Backlogon Jul 14, 2023
  5. moved this from Ready for review to Done in Backlogon Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[cat] modules[cat] testing[cat] utilitiesenhancement

Type

No type

Projects

  • Status
    Done

Relationships

None yet

Development

No branches or pull requests

Issue actions