Skip to content

Commit

Permalink
fix: enforce PowerShell code formatter (#1458)
Browse files Browse the repository at this point in the history
## Description

<!--
>Thank you for your contribution !
> Please include a summary of the change and which issue is fixed.
> Please also include the context.
> List any dependencies that are required for this change.

Fixes #123
Fixes #456
Closes #123
Closes #456
-->

## Pipeline Reference

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

| Pipeline |
| -------- |
|
[![avm.res.network.nat-gateways](https://github.com/eriqua/bicep-registry-modules/actions/workflows/avm.res.network.nat-gateway.yml/badge.svg?branch=fix%2Fformatter)](https://github.com/eriqua/bicep-registry-modules/actions/workflows/avm.res.network.nat-gateway.yml)
expected |
|
[![avm.res.compute.virtual-machine](https://github.com/eriqua/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml/badge.svg?branch=fix%2Fformatter)](https://github.com/eriqua/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml)
expected |
|
[![avm.res.key-vault.vault](https://github.com/eriqua/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=fix%2Fformatter)](https://github.com/eriqua/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml)
|

## Type of Change

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

- [ ] Update to CI Environment or utlities (Non-module effecting
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

## Checklist

- [ ] I'm sure there are no other open Pull Requests for the same
update/change
- [ ] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [ ] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to day with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
  • Loading branch information
eriqua authored Mar 28, 2024
1 parent 4c36cb6 commit 7982151
Show file tree
Hide file tree
Showing 33 changed files with 116 additions and 115 deletions.
18 changes: 16 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"files.autoSave": "onFocusChange",
"git.autofetch": true,
"githubPullRequests.pullBranch": "always",
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.newLineAfterCloseBrace": false,
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.useConstantStrings": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"[json,jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand All @@ -12,5 +21,10 @@
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true
}
"[powershell]": {
"editor.insertSpaces": true,
"editor.tabSize": 4,
"files.encoding": "utf8bom",
"files.insertFinalNewline": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ BeforeAll {

if ($moduleFolderPaths.Count -gt 1) {
$topLevelModuleTemplatePath = $moduleFolderPaths | Sort-Object | Select-Object -First 1
}
else {
} else {
$topLevelModuleTemplatePath = $moduleFolderPaths
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Describe 'Validate private endpoint deployment' {

Context 'Validate sucessful deployment' {

It "Private endpoints should be deployed in resource group" {
It 'Private endpoints should be deployed in resource group' {

$keyVaultResourceId = $TestInputData.DeploymentOutputs.resourceId.Value
$testResourceGroup = ($keyVaultResourceId -split '\/')[4]
Expand All @@ -36,4 +36,4 @@ Describe 'Validate private endpoint deployment' {
$roleAssignments.Count | Should -BeGreaterThan 0
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ BeforeAll {

if ($moduleFolderPaths.Count -gt 1) {
$topLevelModuleTemplatePath = $moduleFolderPaths | Sort-Object | Select-Object -First 1
}
else {
} else {
$topLevelModuleTemplatePath = $moduleFolderPaths
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ function Get-AzAvailableResourceLocation {

[Parameter(Mandatory = $false)]
[array] $ExcludedRegions = @(
"asiasoutheast",
"brazilsouth",
"eastus2",
"japaneast",
"koreacentral",
"qatercentral",
"southcentralus",
"switzerlandnorth",
"uaenorth",
"westeurope",
"westus2",
"westus2"
'asiasoutheast',
'brazilsouth',
'eastus2',
'japaneast',
'koreacentral',
'qatercentral',
'southcentralus',
'switzerlandnorth',
'uaenorth',
'westeurope',
'westus2',
'westus2'
)
)

Expand All @@ -82,18 +82,17 @@ function Get-AzAvailableResourceLocation {
$ResourceRegionList = (Get-AzResourceProvider | Where-Object { $_.ProviderNamespace -eq $formattedResourceProvider }).ResourceTypes | Where-Object { $_.ResourceTypeName -eq $formattedServiceName } | Select-Object -ExpandProperty Locations
Write-Verbose "Region list: $($resourceRegionList | ConvertTo-Json)"

if ($resourceRegionList -eq "global" -or $null -eq $resourceRegionList) {
if ($resourceRegionList -eq 'global' -or $null -eq $resourceRegionList) {
Write-Verbose "Resource is global or does not have a location in the Resource Providers API, default region [$GlobalResourceGroupLocation] will be used for resource group creation"
$location = $GlobalResourceGroupLocation # Set Location to resource group location. Globabl resources should have hardocded location in `main.bicep`
}
else {
} else {

$locations = Get-AzLocation | Where-Object {
$_.DisplayName -in $ResourceRegionList -and
$_.Location -notin $ExcludedRegions -and
$_.PairedRegion -ne "{}" -and
$_.RegionCategory -eq "Recommended"
} | Select-Object -ExpandProperty Location
$_.PairedRegion -ne '{}' -and
$_.RegionCategory -eq 'Recommended'
} | Select-Object -ExpandProperty Location
Write-Verbose "Available Locations: $($locations | ConvertTo-Json)"

$filteredAllowedLocations = @($locations | Where-Object { $_ -in $AllowedRegionsList })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,4 @@ function New-TemplateDeployment {
end {
Write-Debug ('{0} exited' -f $MyInvocation.MyCommand)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ function Invoke-ResourceLockRemoval {
$resourceLock = Invoke-ResourceLockRetrieval -ResourceId $ResourceId -Type $Type
$isLocked = $resourceLock.count -gt 0
} while ($isLocked)

Write-Verbose (' [-] [{0}] resource lock(s) removed.' -f $resourceLock.count) -Verbose
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ function Remove-Deployment {
if ($PSCmdlet.ShouldProcess(('[{0}] resources' -f (($resourcesToRemove -is [array]) ? $resourcesToRemove.Count : 1)), 'Remove')) {
Remove-ResourceList -ResourcesToRemove $resourcesToRemove
}
}
else {
} else {
Write-Verbose 'Found [0] resources to remove'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ function Publish-ModuleFromTagToPBR {

$publishInput = @(
$moduleBicepFilePath
'--target', ("br:{0}/public/bicep/{1}:{2}" -f $plainPublicRegistryServer, $moduleRelativeFolderPath, $targetVersion)
'--target', ('br:{0}/public/bicep/{1}:{2}' -f $plainPublicRegistryServer, $moduleRelativeFolderPath, $targetVersion)
'--documentationUri', $documentationUri
'--with-source'
'--force'
)

Write-Verbose "Publish Input:`n $($publishInput | ConvertTo-Json -Depth 10)" -Verbose

if ($PSCmdlet.ShouldProcess("Module of tag [$ModuleReleaseTagName]", "Publish")) {
if ($PSCmdlet.ShouldProcess("Module of tag [$ModuleReleaseTagName]", 'Publish')) {
bicep publish @publishInput
}

Expand Down
28 changes: 13 additions & 15 deletions avm/utilities/pipelines/platform/Set-AvmGitHubIssueOwnerConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@ Function Get-AvmCsvData {
)

# CSV file URLs
$BicepResourceUrl = "https://aka.ms/avm/index/bicep/res/csv"
$BicepPatternUrl = "https://aka.ms/avm/index/bicep/ptn/csv"
$BicepResourceUrl = 'https://aka.ms/avm/index/bicep/res/csv'
$BicepPatternUrl = 'https://aka.ms/avm/index/bicep/ptn/csv'

# Retrieve the CSV file
switch ($ModuleIndex) {
'Bicep-Resource' {
try {
$unfilteredCSV = Invoke-WebRequest -Uri $BicepResourceUrl
}
catch {
Write-Error "Unable to retrieve CSV file - Check network connection."
} catch {
Write-Error 'Unable to retrieve CSV file - Check network connection.'
}
}
'Bicep-Pattern' {
try {
$unfilteredCSV = Invoke-WebRequest -Uri $BicepPatternUrl
}
catch {
Write-Error "Unable to retrieve CSV file - Check network connection."
} catch {
Write-Error 'Unable to retrieve CSV file - Check network connection.'
}
}
}

# Convert the CSV content to a PowerShell object
$formattedBicepFullCsv = ConvertFrom-CSV $unfilteredCSV.Content
$formattedBicepFullCsv = ConvertFrom-Csv $unfilteredCSV.Content

# Loop through each item in the filtered data
foreach ($item in $formattedBicepFullCsv) {
Expand Down Expand Up @@ -92,14 +90,14 @@ function Set-AvmGitHubIssueOwnerConfig {
$issue = gh issue view $IssueUrl.Replace('api.', '').Replace('repos/', '') --json 'author,title,url,body,comments' --repo $Repo | ConvertFrom-Json -Depth 100

if ($issue.title.StartsWith('[AVM Module Issue]')) {
$moduleName = ($issue.body.Split("`n") -match "avm/(?:res|ptn)")[0].Trim().Replace(' ', '')
$moduleName = ($issue.body.Split("`n") -match 'avm/(?:res|ptn)')[0].Trim().Replace(' ', '')

if ([string]::IsNullOrEmpty($moduleName)) {
throw 'No valid module name was found in the issue.'
}

$moduleIndex = $moduleName.StartsWith("avm/res") ? "Bicep-Resource" : "Bicep-Pattern"
$module = Get-AvmCsvData -ModuleIndex $moduleIndex | Where-Object ModuleName -eq $moduleName
$moduleIndex = $moduleName.StartsWith('avm/res') ? 'Bicep-Resource' : 'Bicep-Pattern'
$module = Get-AvmCsvData -ModuleIndex $moduleIndex | Where-Object ModuleName -EQ $moduleName

if ([string]::IsNullOrEmpty($module)) {
throw "Module $moduleName was not found in $moduleIndex CSV file."
Expand All @@ -113,11 +111,11 @@ A member of the @azure/$($module.ModuleOwnersGHTeam) or @azure/$($module.ModuleC

if ($PSCmdlet.ShouldProcess("attention label to issue [$($issue.title)]", 'Add')) {
# add labels
gh issue edit $issue.url --add-label "Needs: Attention :wave:" --repo $Repo
gh issue edit $issue.url --add-label 'Needs: Attention :wave:' --repo $Repo
}

if ($PSCmdlet.ShouldProcess("class label to issue [$($issue.title)]", 'Add')) {
gh issue edit $issue.url --add-label ($moduleIndex -eq "Bicep-Resource" ? "Class: Resource Module :package:" : "Class: Pattern Module :package:") --repo $Repo
gh issue edit $issue.url --add-label ($moduleIndex -eq 'Bicep-Resource' ? 'Class: Resource Module :package:' : 'Class: Pattern Module :package:') --repo $Repo
}

if ($PSCmdlet.ShouldProcess("reply comment to issue [$($issue.title)]", 'Add')) {
Expand All @@ -139,4 +137,4 @@ A member of the @azure/$($module.ModuleOwnersGHTeam) or @azure/$($module.ModuleC
}

Write-Verbose ('issue {0}{1} updated' -f $issue.title, $($WhatIfPreference ? ' would have been' : ''))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Set-AvmGithubIssueForWorkflow {
$runId = $run.url.Split('/') | Select-Object -Last 1
$runDetails = gh run view $runId --json 'conclusion,number' --repo $Repo | ConvertFrom-Json -Depth 100

if ($run.workflowName.StartsWith("avm.")) {
if ($run.workflowName.StartsWith('avm.')) {
if (-not $workflowRuns.ContainsKey($run.workflowName) -or $runDetails.number -gt $workflowRuns[$run.workflowName].number) {
$workflowRun = New-Object PSObject -Property @{
workflowName = $run.workflowName
Expand All @@ -66,8 +66,7 @@ function Set-AvmGithubIssueForWorkflow {

if (-not $workflowRuns.ContainsKey($run.workflowName)) {
$workflowRuns.Add($run.workflowName, $workflowRun)
}
else {
} else {
$workflowRuns[$run.workflowName] = $workflowRun
}
}
Expand All @@ -86,8 +85,7 @@ function Set-AvmGithubIssueForWorkflow {
}

$issuesCreated++
}
else {
} else {
$issue = ($issues | Where-Object { $_.title -eq $issueName })[0]

if (-not $issue.body.Contains($failedrun)) {
Expand All @@ -97,8 +95,7 @@ function Set-AvmGithubIssueForWorkflow {
}

$issuesCommented++
}
else {
} else {
if (-not $issue.comments.body.Contains($failedrun)) {
if ($PSCmdlet.ShouldProcess("Issue [$issueName]", 'Close')) {
gh issue comment $issue.url --body $failedrun --repo $Repo
Expand All @@ -109,8 +106,7 @@ function Set-AvmGithubIssueForWorkflow {
}
}
}
}
else {
} else {
$issueName = "[Failed pipeline] $($workflowRun.workflowName)"

if ($issues.title -contains $issueName) {
Expand Down
2 changes: 1 addition & 1 deletion avm/utilities/pipelines/platform/Switch-WorkflowState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Switch-WorkflowState {
throw 'Function should not run for [Azure/bicep-registry-modules].'
}

$workflows = gh workflow list --repo $repo --all --json "name,state,id" --limit 999 | ConvertFrom-Json -Depth 100
$workflows = gh workflow list --repo $repo --all --json 'name,state,id' --limit 999 | ConvertFrom-Json -Depth 100
$relevantWorkflows = $workflows | Where-Object {
$_.name -match $IncludePattern -and $_.name -notmatch $ExlcudePattern
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function Publish-ModuleFromPathToPBR {

# 1. Test if module qualifies for publishing
if (-not (Get-ModulesToPublish -ModuleFolderPath $moduleFolderPath)) {
Write-Verbose "No changes detected. Skipping publishing" -Verbose
Write-Verbose 'No changes detected. Skipping publishing' -Verbose
return
}

Expand Down Expand Up @@ -95,7 +95,7 @@ function Publish-ModuleFromPathToPBR {

$publishInput = @(
$moduleBicepFilePath
'--target', ("br:{0}/public/bicep/{1}:{2}" -f $plainPublicRegistryServer, $publishedModuleName, $targetVersion)
'--target', ('br:{0}/public/bicep/{1}:{2}' -f $plainPublicRegistryServer, $publishedModuleName, $targetVersion)
'--documentationUri', $documentationUri
'--with-source'
'--force'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ function Get-ModuleReadmeLink {
[string] $RegistryBaseUri = 'https://github.com/Azure/bicep-registry-modules/tree'
)

$ModuleRelativeFolderPath = ("avm/{0}" -f ($ModuleFolderPath -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'
$ModuleRelativeFolderPath = ('avm/{0}' -f ($ModuleFolderPath -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'
return (('{0}/{1}/{2}/README.md' -f $RegistryBaseUri, $TagName, $ModuleRelativeFolderPath) -replace '\\', '/')
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ function Get-ModuleTargetPatchVersion {
[string] $MajMinVersion
)

$ModuleRelativeFolderPath = ("avm/{0}" -f ($ModuleFolderPath -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'
$ModuleRelativeFolderPath = ('avm/{0}' -f ($ModuleFolderPath -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'

# Get all released module tags (using upstream specifically to work in forks)
$existingTagList = git ls-remote --tag 'https://github.com/Azure/bicep-registry-modules.git' "$ModuleRelativeFolderPath/$MajMinVersion*"
if ( $existingTagList.count -eq 0 ) {
# If first module tag, reset patch
Write-Verbose "No existing tag for module [$ModuleRelativeFolderPath] starting with version [$MajMinVersion]" -Verbose
Write-Verbose "Setting patch version to 0" -Verbose
Write-Verbose 'Setting patch version to 0' -Verbose
$patch = 0
} else {
# Otherwise get latest patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ function Get-ModuleTargetVersion {

if ($versionChange) {
# If [version.json] file version property was updated, reset the patch/bug version back to 0
Write-Verbose "[version.json] file version property was updated. Resetting PATCH back to 0." -Verbose
Write-Verbose '[version.json] file version property was updated. Resetting PATCH back to 0.' -Verbose
$patch = '0'
}
else {
} else {
# Otherwise calculate the patch version
Write-Verbose "[version.json] file version property was not updated. Calculating new PATCH version." -Verbose
Write-Verbose '[version.json] file version property was not updated. Calculating new PATCH version.' -Verbose
$patch = Get-ModuleTargetPatchVersion -ModuleFolderPath $ModuleFolderPath -MajMinVersion "$major.$minor"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ function Get-ModuleVersionChange {
}

if ($newVersion -lt $oldVersion) {
Write-Verbose "The new version is smaller than the old version"
Write-Verbose 'The new version is smaller than the old version'
} elseif ($newVersion -eq $oldVersion) {
Write-Verbose "The new version equals the old version"
Write-Verbose 'The new version equals the old version'
} else {
Write-Verbose "The new version is greater than the old version"
Write-Verbose 'The new version is greater than the old version'
}

if (-not [String]::IsNullOrEmpty($newVersion) -and -not [String]::IsNullOrEmpty($oldVersion)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Get-TemplateFileToPublish {
[string[]] $PathsToInclude = @()
)

$ModuleRelativeFolderPath = ("avm/{0}" -f ($ModuleFolderPath -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'
$ModuleRelativeFolderPath = ('avm/{0}' -f ($ModuleFolderPath -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'
$ModifiedFiles = Get-ModifiedFileList -Verbose
Write-Verbose "Looking for modified files under: [$ModuleRelativeFolderPath]" -Verbose
$modifiedModuleFiles = $ModifiedFiles.FullName | Where-Object { $_ -like "*$ModuleFolderPath*" }
Expand All @@ -110,7 +110,7 @@ function Get-TemplateFileToPublish {

Write-Verbose ('Modified modules found: [{0}]' -f $TemplateFilesToPublish.count) -Verbose
$TemplateFilesToPublish | ForEach-Object {
$RelPath = ("avm/{0}" -f ($_ -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'
$RelPath = ('avm/{0}' -f ($_ -split '[\/|\\]avm[\/|\\]')[-1]) -replace '\\', '/'
$RelPath = $RelPath.Split('/main.')[0]
Write-Verbose " - [$RelPath]" -Verbose
}
Expand Down
Loading

0 comments on commit 7982151

Please sign in to comment.