Skip to content

Commit

Permalink
fix: Added -Culture 'en-US' to all Sort-Object operations (#1976)
Browse files Browse the repository at this point in the history
## Description

- Added `-Culture 'en-US'` to all `Sort-Object` operations to mitigate
issues some contributors with a different configured culture have
- Re-ran the generation for all files (no changes)

Related to Azure/ResourceModules#3722, but
needs to be fixed there seperately

## Type of Change

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

- [x] 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

---------

Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com>
  • Loading branch information
AlexanderSehr and eriqua authored May 20, 2024
1 parent 86cfa86 commit bc8d57b
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BeforeAll {
. (Join-Path $RepoRootPath 'avm' 'utilities' 'pipelines' 'sharedScripts' 'helper' 'Get-IsParameterRequired.ps1')

if ($moduleFolderPaths.Count -gt 1) {
$topLevelModuleTemplatePath = $moduleFolderPaths | Sort-Object | Select-Object -First 1
$topLevelModuleTemplatePath = $moduleFolderPaths | Sort-Object -Culture 'en-US' | Select-Object -First 1
} else {
$topLevelModuleTemplatePath = $moduleFolderPaths
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BeforeAll {
. (Join-Path $RepoRootPath 'avm' 'utilities' 'pipelines' 'sharedScripts' 'helper' 'Get-IsParameterRequired.ps1')

if ($moduleFolderPaths.Count -gt 1) {
$topLevelModuleTemplatePath = $moduleFolderPaths | Sort-Object | Select-Object -First 1
$topLevelModuleTemplatePath = $moduleFolderPaths | Sort-Object -Culture 'en-US' | Select-Object -First 1
} else {
$topLevelModuleTemplatePath = $moduleFolderPaths
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ function Initialize-DeploymentRemoval {
if ($PurgeTestResources) {
# Resources
$filteredResourceIds = (Get-AzResource).ResourceId | Where-Object { $_ -like '*dep-*' }
$ResourceIds += ($filteredResourceIds | Sort-Object -Unique)
$ResourceIds += ($filteredResourceIds | Sort-Object -Culture 'en-US' -Unique)

# Resource groups
$filteredResourceGroupIds = (Get-AzResourceGroup).ResourceId | Where-Object { $_ -like '*dep-*' }
$ResourceIds += ($filteredResourceGroupIds | Sort-Object -Unique)
$ResourceIds += ($filteredResourceGroupIds | Sort-Object -Culture 'en-US' -Unique)
}

# Invoke removal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function Get-ResourceIdsAsFormattedObjectList {
$allResourceGroupResources = Get-AzResource -ResourceGroupName $resourceGroupName -Name '*'
}
$expandedResources = $allResourceGroupResources | Where-Object { $_.ResourceId.startswith($resourceId) }
$expandedResources = $expandedResources | Sort-Object -Descending -Property { $_.ResourceId.Split('/').Count }
$expandedResources = $expandedResources | Sort-Object -Culture 'en-US' -Descending -Property { $_.ResourceId.Split('/').Count }
foreach ($resource in $expandedResources) {
$formattedResources += @{
resourceId = $resource.ResourceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function Remove-Deployment {

# Pre-Filter & order items
# ========================
$rawTargetResourceIdsToRemove = $deployedTargetResources | Sort-Object -Property { $_.Split('/').Count } -Descending | Select-Object -Unique
$rawTargetResourceIdsToRemove = $deployedTargetResources | Sort-Object -Culture 'en-US' -Property { $_.Split('/').Count } -Descending | Select-Object -Unique
Write-Verbose ('Total number of deployment target resources after pre-filtering (duplicates) & ordering items [{0}]' -f $rawTargetResourceIdsToRemove.Count) -Verbose

# Format items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Invoke-AvmJsonModuleIndexGeneration {
Write-Error "Error message: $($_.Exception.Message)"
continue
}
$tags = $tagListResponse.tags | Sort-Object
$tags = $tagListResponse.tags | Sort-Object -Culture 'en-US'

$properties = [ordered]@{}
foreach ($tag in $tags) {
Expand Down Expand Up @@ -190,7 +190,7 @@ function Invoke-AvmJsonModuleIndexGeneration {
} else {
# If the module exists, merge the tags and properties
$mergedModule = $initialMergeOfJsonFilesData[$module.moduleName]
$mergedModule.tags = @(($mergedModule.tags + $module.tags) | Sort-Object -Unique)
$mergedModule.tags = @(($mergedModule.tags + $module.tags) | Sort-Object -Culture 'en-US' -Unique)

# Merge properties
foreach ($property in $module.properties.PSObject.Properties) {
Expand All @@ -205,7 +205,7 @@ function Invoke-AvmJsonModuleIndexGeneration {
$mergedModuleIndexData = $initialMergeOfJsonFilesData.Values

# Sort the modules by their names
$sortedMergedModuleIndexData = $mergedModuleIndexData | Sort-Object moduleName
$sortedMergedModuleIndexData = $mergedModuleIndexData | Sort-Object -Culture 'en-US' -Property 'moduleName'

Write-Verbose "Convert mergedModuleIndexData variable to JSON and save as 'moduleIndex.json'" -Verbose
$sortedMergedModuleIndexData | ConvertTo-Json -Depth 10 | Out-File -FilePath $moduleIndexJsonFilePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function Get-TemplateFileToPublish {

$TemplateFilesToPublish = $relevantPaths | ForEach-Object {
Find-TemplateFile -Path $_ -Verbose
} | Sort-Object -Unique -Descending
} | Sort-Object -Culture 'en-US' -Unique -Descending

if ($TemplateFilesToPublish.Count -eq 0) {
Write-Verbose 'No template file found in the modified module.' -Verbose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function Add-YamlListToFile {
throw "No key-value pairs found in List: $ListName"
}
# Process key value pairs in the list
foreach ($Key in ($KeyValuePair.Keys.split(' ') | Sort-Object)) {
foreach ($Key in ($KeyValuePair.Keys.split(' ') | Sort-Object -Culture 'en-US')) {
Write-Verbose ('Setting environment variable [{0}] with value [{1}]' -f $Key, $KeyValuePair[$Key]) -Verbose
Write-Output "$Key=$($KeyValuePair[$Key])" | Out-File -FilePath $OutputFilePath -Encoding 'utf-8' -Append
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Install-CustomModule {
$alreadyInstalled = $alreadyInstalled | Where-Object { $_.Version -eq $Module.Version }
} else {
# Get latest in case of multiple
$alreadyInstalled = ($alreadyInstalled | Sort-Object -Property Version -Descending)[0]
$alreadyInstalled = ($alreadyInstalled | Sort-Object -Culture 'en-US' -Property 'Version' -Descending)[0]
}
Write-Verbose ('Module [{0}] already installed with version [{1}]' -f $alreadyInstalled.Name, $alreadyInstalled.Version) -Verbose
continue
Expand Down
14 changes: 7 additions & 7 deletions avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function Set-ResourceTypesSection {

$RelevantResourceTypeObjects = Get-NestedResourceList $TemplateFileContent | Where-Object {
$_.type -notin $ResourceTypesToExclude -and $_
} | Select-Object 'Type', 'ApiVersion' -Unique | Sort-Object Type -Culture 'en-US'
} | Select-Object 'Type', 'ApiVersion' -Unique | Sort-Object -Culture 'en-US' -Property 'Type'

$ProgressPreference = 'SilentlyContinue'
$VerbosePreference = 'SilentlyContinue'
Expand Down Expand Up @@ -277,9 +277,9 @@ function Set-DefinitionSection {
# Filter to relevant items
if (-not $Properties) {
# Top-level invocation
[array] $categoryParameters = $TemplateFileContent.parameters.Values | Where-Object { $_.metadata.description -like "$category. *" } | Sort-Object -Property 'Name' -Culture 'en-US'
[array] $categoryParameters = $TemplateFileContent.parameters.Values | Where-Object { $_.metadata.description -like "$category. *" } | Sort-Object -Culture 'en-US' -Property 'Name'
} else {
$categoryParameters = $Properties.Values | Where-Object { $_.metadata.description -like "$category. *" } | Sort-Object -Property 'Name' -Culture 'en-US'
$categoryParameters = $Properties.Values | Where-Object { $_.metadata.description -like "$category. *" } | Sort-Object -Culture 'en-US' -Property 'Name'
}

$tableSectionContent += @(
Expand Down Expand Up @@ -657,13 +657,13 @@ function Set-CrossReferencesSection {
$dependencies = $CrossReferencedModuleList[$FullModuleIdentifier]

if ($dependencies.Keys -contains 'localPathReferences' -and $dependencies['localPathReferences']) {
foreach ($reference in ($dependencies['localPathReferences'] | Sort-Object)) {
foreach ($reference in ($dependencies['localPathReferences'] | Sort-Object -Culture 'en-US')) {
$SectionContent += ("| ``{0}`` | {1} |" -f $reference, 'Local reference')
}
}

if ($dependencies.Keys -contains 'remoteReferences' -and $dependencies['remoteReferences']) {
foreach ($reference in ($dependencies['remoteReferences'] | Sort-Object)) {
foreach ($reference in ($dependencies['remoteReferences'] | Sort-Object -Culture 'en-US')) {
$SectionContent += ("| ``{0}`` | {1} |" -f $reference, 'Remote reference')
}
}
Expand Down Expand Up @@ -1283,11 +1283,11 @@ function Set-UsageExamplesSection {
$moduleNameCamelCase = $First.Tolower() + (Get-Culture).TextInfo.ToTitleCase($Rest) -Replace '-'
}

$testFilePaths = (Get-ChildItem -Path $ModuleRoot -Recurse -Filter 'main.test.bicep').FullName | Sort-Object
$testFilePaths = (Get-ChildItem -Path $ModuleRoot -Recurse -Filter 'main.test.bicep').FullName | Sort-Object -Culture 'en-US'

$RequiredParametersList = $TemplateFileContent.parameters.Keys | Where-Object {
Get-IsParameterRequired -TemplateFileContent $TemplateFileContent -Parameter $TemplateFileContent.parameters[$_]
} | Sort-Object
} | Sort-Object -Culture 'en-US'

############################
## Process test files ##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function ConvertTo-OrderedHashtable {
return $JSONObject # E.g. in primitive data types [1,2,3]
}

foreach ($currentLevelKey in ($JSONObject.Keys | Sort-Object)) {
foreach ($currentLevelKey in ($JSONObject.Keys | Sort-Object -Culture 'en-US')) {

if ($null -eq $JSONObject[$currentLevelKey]) {
# Handle case in which the value is 'null' and hence has no type
Expand All @@ -83,7 +83,7 @@ function ConvertTo-OrderedHashtable {
foreach ($array in $arrayElements) {
if ($array.Count -gt 1) {
# Only sort for arrays with more than one item. Otherwise single-item arrays are casted
$array = $array | Sort-Object
$array = $array | Sort-Object -Culture 'en-US'
}
$arrayOutput += , (ConvertTo-OrderedHashtable -JSONInputObject ($array | ConvertTo-Json -Depth 99))
}
Expand All @@ -97,13 +97,13 @@ function ConvertTo-OrderedHashtable {
# Case: Primitive data types
$primitiveElements = $JSONObject[$currentLevelKey] | Where-Object { $_.GetType().BaseType.Name -notin @('Array', 'Hashtable') } | ConvertTo-Json -Depth 99 | ConvertFrom-Json -AsHashtable -NoEnumerate -Depth 99
if ($primitiveElements.Count -gt 1) {
$primitiveElements = $primitiveElements | Sort-Object
$primitiveElements = $primitiveElements | Sort-Object -Culture 'en-US'
}
$arrayOutput += $primitiveElements

if ($array.Count -gt 1) {
# Only sort for arrays with more than one item. Otherwise single-item arrays are casted
$arrayOutput = $arrayOutput | Sort-Object
$arrayOutput = $arrayOutput | Sort-Object -Culture 'en-US'
}
$orderedLevel[$currentLevelKey] = $arrayOutput
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ function Get-ReferenceObject {
}

return @{
resourceReferences = $resultSet.resourceReferences | Sort-Object -Unique
remoteReferences = $resultSet.remoteReferences | Sort-Object -Unique
localPathReferences = $resultSet.localPathReferences | Sort-Object -Unique
resourceReferences = $resultSet.resourceReferences | Sort-Object -Culture 'en-US' -Unique
remoteReferences = $resultSet.remoteReferences | Sort-Object -Culture 'en-US' -Unique
localPathReferences = $resultSet.localPathReferences | Sort-Object -Culture 'en-US' -Unique
}
}
#endregion
Expand Down Expand Up @@ -155,7 +155,7 @@ function Get-CrossReferencedModuleList {
$moduleTemplatePaths = (Get-ChildItem -Path $path -Recurse -File -Filter '*.bicep').FullName | Where-Object {
# No files inthe [/utilities/tools/] folder and none in the [/tests/] folder
$_ -notmatch '.*[\\|\/]tools[\\|\/].*|.*[\\|\/]tests[\\|\/].*'
} | Sort-Object
} | Sort-Object -Culture 'en-US'
$templateMap = @{}
foreach ($moduleTemplatePath in $moduleTemplatePaths) {
$templateMap[$moduleTemplatePath] = Get-Content -Path $moduleTemplatePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Get-SpecsAlignedResourceName {
$rawProviderNamespace, $rawResourceType = $reducedResourceIdentifier -Split '[\/|\\]', 2 # e.g. 'keyvault' & 'vaults/keys'

# Find provider namespace
$foundProviderNamespaceMatches = ($specs.Keys | Sort-Object) | Where-Object { $_ -like "Microsoft.$rawProviderNamespace*" }
$foundProviderNamespaceMatches = ($specs.Keys | Sort-Object -Culture 'en-US') | Where-Object { $_ -like "Microsoft.$rawProviderNamespace*" }

if (-not $foundProviderNamespaceMatches) {
$providerNamespace = "Microsoft.$rawProviderNamespace"
Expand All @@ -86,7 +86,7 @@ function Get-SpecsAlignedResourceName {
}

# Find resource type
$innerResourceTypes = $specs[$providerNamespace].Keys | Sort-Object
$innerResourceTypes = $specs[$providerNamespace].Keys | Sort-Object -Culture 'en-US'

$rawResourceTypeElem = $rawResourceType -split '[\/|\\]'
$reducedResourceTypeElements = $rawResourceTypeElem | ForEach-Object { Get-ReducedWordString -StringToReduce $_ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function Convert-TokensInFileList {

process {
# Combine All Input Token Types, Remove Duplicates and Only Select entries with on empty values
$FilteredTokens = ($Tokens | Sort-Object -Unique).Clone()
$FilteredTokens = ($Tokens | Sort-Object -Culture 'en-US' -Unique).Clone()
@($FilteredTokens.Keys) | ForEach-Object {
if ([String]::IsNullOrEmpty($FilteredTokens[$_])) {
$FilteredTokens.Remove($_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function Set-PesterGitHubOutput {
'| Name | Error | Source |',
'| :-- | :-- | :-- |'
)
foreach ($failedTest in ($failedTests | Sort-Object -Property { $PSItem.ExpandedName })) {
foreach ($failedTest in ($failedTests | Sort-Object -Culture 'en-US' -Property { $PSItem.ExpandedName })) {

$intermediateNameElements = $failedTest.Path
$intermediateNameElements[-1] = '**{0}**' -f $failedTest.ExpandedName
Expand Down Expand Up @@ -175,7 +175,7 @@ function Set-PesterGitHubOutput {
'| Name | Source |',
'| :-- | :-- |'
)
foreach ($passedTest in ($passedTests | Sort-Object -Property { $PSItem.ExpandedName }) ) {
foreach ($passedTest in ($passedTests | Sort-Object -Culture 'en-US' -Property { $PSItem.ExpandedName }) ) {

$intermediateNameElements = $passedTest.Path
$intermediateNameElements[-1] = '**{0}**' -f $passedTest.ExpandedName
Expand Down Expand Up @@ -221,7 +221,7 @@ function Set-PesterGitHubOutput {
'| Name | Reason | Source |',
'| :-- | :-- | :-- |'
)
foreach ($skippedTest in ($skippedTests | Sort-Object -Property { $PSItem.ExpandedName }) ) {
foreach ($skippedTest in ($skippedTests | Sort-Object -Culture 'en-US' -Property { $PSItem.ExpandedName }) ) {

$intermediateNameElements = $skippedTest.Path
$intermediateNameElements[-1] = '**{0}**' -f $skippedTest.ExpandedName
Expand Down Expand Up @@ -269,7 +269,7 @@ function Set-PesterGitHubOutput {
'| Name | Warning | Source |',
'| :-- | :-- | :-- |'
)
foreach ($test in ($testsWithWarnings | Sort-Object -Property { $PSItem.ExpandedName }) ) {
foreach ($test in ($testsWithWarnings | Sort-Object -Culture 'en-US' -Property { $PSItem.ExpandedName }) ) {
foreach ($warning in $test.StandardOutput.Warning) {
$intermediateNameElements = $test.Path
$intermediateNameElements[-1] = '**{0}**' -f $test.ExpandedName
Expand Down
Loading

0 comments on commit bc8d57b

Please sign in to comment.