Skip to content

Commit

Permalink
fix: Intoduced special case handling for ReadMe header for non-resour…
Browse files Browse the repository at this point in the history
…ce modules (#2367)

## Description

Current ptn module headers (and later utility) don't make much sense as
the original function was written for resource modules with a
`Microsoft.` prefix etc.

This change suggests to treat those modules differently and use their
folder structure as a direct reference to their name for the file header
in PascalCase.

Updated all module readmes.

cc: @krbar & @jbinko 

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.ptn.authorization.policy-assignment](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.ptn.authorization.policy-assignment.yml/badge.svg?branch=users%2Falsehr%2FreadmeIdentifierUpdate&event=workflow_dispatch)](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.ptn.authorization.policy-assignment.yml)
|
|
[![avm.res.analysis-services.server](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.res.analysis-services.server.yml/badge.svg?branch=users%2Falsehr%2FreadmeIdentifierUpdate&event=workflow_dispatch)](https://github.com/Azure/bicep-registry-modules/actions/workflows/avm.res.analysis-services.server.yml)
|

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [x] Update to CI Environment or utilities (Non-module affecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation
  • Loading branch information
AlexanderSehr authored Jul 2, 2024
1 parent a948d97 commit 1cd0c2a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion avm/ptn/authorization/policy-assignment/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Policy Assignments (All scopes) `[Microsoft.Authorization/policyAssignments]`
# Policy Assignments (All scopes) `[Authorization/PolicyAssignment]`

This module deploys a Policy Assignment at a Management Group, Subscription or Resource Group scope.

Expand Down
2 changes: 1 addition & 1 deletion avm/ptn/authorization/resource-role-assignment/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Resource-scoped role assignment `[Microsoft.Authorization/resourceroleassignment]`
# Resource-scoped role assignment `[Authorization/ResourceRoleAssignment]`

This module deploys a Role Assignment for a specific resource.

Expand Down
2 changes: 1 addition & 1 deletion avm/ptn/authorization/role-assignment/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Role Assignments (All scopes) `[Microsoft.Authorization/roleAssignments]`
# Role Assignments (All scopes) `[Authorization/RoleAssignment]`

This module deploys a Role Assignment at a Management Group, Subscription or Resource Group scope.

Expand Down
2 changes: 1 addition & 1 deletion avm/ptn/finops-toolkit/finops-hub/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Finops-hub `[Microsoft.finopstoolkit/finopshub]`
# Finops-hub `[FinopsToolkit/FinopsHub]`

This module deploys a Finops hub from the Finops toolkit.

Expand Down
2 changes: 1 addition & 1 deletion avm/ptn/lz/sub-vending/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sub-vending `[Microsoft.lz/subvending]`
# Sub-vending `[Lz/SubVending]`

This module deploys a subscription to accelerate deployment of landing zones. For more information on how to use it, please visit this [Wiki](https://github.com/Azure/bicep-lz-vending/wiki).

Expand Down
2 changes: 1 addition & 1 deletion avm/ptn/policy-insights/remediation/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Policy Insights Remediations `[Microsoft.PolicyInsights/remediations]`
# Policy Insights Remediations `[PolicyInsights/Remediation]`

This module deploys a Policy Insights Remediation.

Expand Down
2 changes: 1 addition & 1 deletion avm/ptn/security/security-center/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Azure Security Center (Defender for Cloud) `[Microsoft.Security/securitycenter]`
# Azure Security Center (Defender for Cloud) `[Security/SecurityCenter]`

This module deploys an Azure Security Center (Defender for Cloud) Configuration.

Expand Down
31 changes: 22 additions & 9 deletions avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1644,18 +1644,31 @@ function Initialize-ReadMe {

$moduleName = $TemplateFileContent.metadata.name
$moduleDescription = $TemplateFileContent.metadata.description
$formattedResourceType = Get-SpecsAlignedResourceName -ResourceIdentifier $FullModuleIdentifier
$hasTests = (Get-ChildItem -Path (Split-Path $ReadMeFilePath) -Recurse -Filter 'main.test.bicep' -File -Force).count -gt 0

$inTemplateResourceType = (Get-NestedResourceList $TemplateFileContent).type | Select-Object -Unique | Where-Object {
$_ -match "^$formattedResourceType$"
}
if ($ReadMeFilePath -match 'avm.(?:res)') {
# Resource module
$formattedResourceType = Get-SpecsAlignedResourceName -ResourceIdentifier $FullModuleIdentifier

if (-not $inTemplateResourceType) {
Write-Warning "No resource type like [$formattedResourceType] found in template. Falling back to it as identifier."
$inTemplateResourceType = $formattedResourceType
$inTemplateResourceType = (Get-NestedResourceList $TemplateFileContent).type | Select-Object -Unique | Where-Object {
$_ -match "^$formattedResourceType$"
}

if ($inTemplateResourceType) {
$headerType = $inTemplateResourceType
} else {
Write-Warning "No resource type like [$formattedResourceType] found in template. Falling back to it as identifier."
$headerType = $formattedResourceType
}
} else {
# Non-resource modules always need a custom identifier
$parentIdentifierName, $childIdentifierName = $FullModuleIdentifier -Split '[\/|\\]', 2 # e.g. 'lz' & 'sub-vending'
$formattedParentIdentifierName = (Get-Culture).TextInfo.ToTitleCase(($parentIdentifierName -Replace '[^0-9A-Z]', ' ')) -Replace ' '
$formattedChildIdentifierName = (Get-Culture).TextInfo.ToTitleCase(($childIdentifierName -Replace '[^0-9A-Z]', ' ')) -Replace ' '
$headerType = "$formattedParentIdentifierName/$formattedChildIdentifierName"
}

$hasTests = (Get-ChildItem -Path (Split-Path $ReadMeFilePath) -Recurse -Filter 'main.test.bicep' -File -Force).count -gt 0

# Orphaned readme existing?
$orphanedReadMeFilePath = Join-Path (Split-Path $ReadMeFilePath -Parent) 'ORPHANED.md'
if (Test-Path $orphanedReadMeFilePath) {
Expand All @@ -1669,7 +1682,7 @@ function Initialize-ReadMe {
}

$initialContent = @(
"# $moduleName ``[$inTemplateResourceType]``",
"# $moduleName ``[$headerType]``",
'',
((Test-Path $orphanedReadMeFilePath) ? $orphanedReadMeContent : $null),
((Test-Path $orphanedReadMeFilePath) ? '' : $null),
Expand Down

0 comments on commit 1cd0c2a

Please sign in to comment.