Skip to content

Commit

Permalink
Merge pull request #2291 from microsoftgraph/po/ResolveCmdletName
Browse files Browse the repository at this point in the history
Resolve duplicate command names in `Users.Functions`
  • Loading branch information
timayabi2020 authored Sep 7, 2023
2 parents 41a1af7 + 35eda6c commit 31bea4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .azure-pipelines/generation-templates/workload-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ steps:
script: |
. $(System.DefaultWorkingDirectory)/tools/GenerateModules.ps1 -SkipGeneration -Test
- task: PowerShell@2
displayName: Find Duplicate Commands
inputs:
targetType: inline
pwsh: true
script: |
. $(System.DefaultWorkingDirectory)/tools/PostGeneration/FindDuplicateCommand.ps1 -SourcePath "$(System.DefaultWorkingDirectory)/src/"
- ${{ if eq(parameters.Sign, true) }}:
- template: ../common-templates/esrp/strongname.yml
parameters:
Expand Down
4 changes: 2 additions & 2 deletions src/Users.Functions/Users.Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ directive:
subject: $1AllowedCalendarSharingRoles
- where:
verb: Get
subject: ^(UserChatMessage)$
subject: ^(User)(ChatMessage|OnlineMeetingTranscript|OnlineMeetingRecording)$
set:
subject: All$1
subject: All$1$2
```
8 changes: 4 additions & 4 deletions tools/PostGeneration/FindDuplicateCommand.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ if (!(Test-Path $SourcePath)) {
Write-Error "SourcePath is not valid or does not exist. Please ensure that $SourcePath exists then try again."
}

$psd1s = Get-ChildItem -Path $SourcePath -Filter "Microsoft.Graph.*.psd1" -Recurse | where { $_.BaseName -ne "Microsoft.Graph.Authentication" }
$allModules = (Invoke-Expression (($psd1s.FullName | ForEach-Object{ Get-Content $_}) | Out-String ))
$psd1s = Get-ChildItem -Path $SourcePath -Filter "Microsoft.Graph.*.psd1" -Recurse | Where-Object { $_.BaseName -ne "Microsoft.Graph.Authentication" }
$allModules = Import-PowerShellDataFile $psd1s.FullName
$unique = $allModules.FunctionsToExport | Select-Object -unique
$duplicates = Compare-object -ReferenceObject $unique -DifferenceObject $allModules.FunctionsToExport

if ($duplicates.Count -gt 0) {
Write-Host "The following functions are duplicated in the psd1 files:"
$duplicates.InputObject | %{
$duplicates.InputObject | ForEach-Object {
$duplicateCommand = $_
Write-Host "$duplicateCommand is duplicated in:"
Write-Host ($allModules | where { $_.FunctionsToExport -contains $duplicateCommand }).RootModule
Write-Host ($allModules | Where-Object { $_.FunctionsToExport -contains $duplicateCommand }).RootModule
Write-Host "********************************"
}
Write-Error "Please ensure that the functions are unique and try again."
Expand Down

0 comments on commit 31bea4e

Please sign in to comment.