-
Notifications
You must be signed in to change notification settings - Fork 16
Added Deltareport Pipeline #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
constantinhager
wants to merge
3
commits into
dsccommunity:main
Choose a base branch
from
constantinhager:feature/deltapipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
311761a
docs(memory): refresh project context for delta report workflow
constantinhager 66dd606
feat(deltaReport): add delta report workflow to compare tenant config…
constantinhager 26c9df8
fix(InitializeModuleFolderForDeltaReport): ensure module copy failure…
constantinhager File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| task NewM365DscDeltaReport { | ||
|
|
||
| $sourceTenant = if ($env:DeltaReportSourceTenant) | ||
| { | ||
| $env:DeltaReportSourceTenant | ||
| } | ||
| else | ||
| { | ||
| Write-Error "The environment variable 'DeltaReportSourceTenant' is not set. Please specify the source tenant for the delta report." -ErrorAction Stop | ||
| } | ||
|
|
||
| $inputDirectory = if ($env:DeltaReportInputDirectory) | ||
| { | ||
| $env:DeltaReportInputDirectory | ||
| } | ||
| else | ||
| { | ||
| Join-Path -Path $OutputDirectory -ChildPath 'Export' | ||
| } | ||
|
|
||
| $reportDirectory = if ($env:DeltaReportOutputDirectory) | ||
| { | ||
| $env:DeltaReportOutputDirectory | ||
| } | ||
| else | ||
| { | ||
| Join-Path -Path $OutputDirectory -ChildPath 'DeltaReport' | ||
| } | ||
|
|
||
| if (-not (Test-Path -Path $inputDirectory)) | ||
| { | ||
| Write-Error "The input directory '$inputDirectory' does not exist. Please download the 'TenantConfig-*' artifacts first." -ErrorAction Stop | ||
| } | ||
|
|
||
| Write-Host "Looking for exported tenant configurations in '$inputDirectory'" -ForegroundColor Yellow | ||
|
|
||
| #The export creates '<Tenant>\<DscResource>\M365TenantConfig.ps1', hence the tenant is the grandparent of each configuration file. | ||
| $tenants = Get-ChildItem -Path $inputDirectory -Filter *.ps1 -File -Recurse | | ||
| Where-Object { $null -ne $_.Directory.Parent } | | ||
| Group-Object -Property { $_.Directory.Parent.FullName } | ||
|
|
||
| if ($tenants.Count -eq 0) | ||
| { | ||
| Write-Error "Could not find any exported DSC configuration (*.ps1) in '$inputDirectory'." -ErrorAction Stop | ||
| } | ||
|
|
||
| Write-Host "Found $($tenants.Count) tenant(s) in the input directory." -ForegroundColor Yellow | ||
|
|
||
| $stagingDirectory = Join-Path -Path $reportDirectory -ChildPath '_staging' | ||
| if (Test-Path -Path $reportDirectory) | ||
| { | ||
| Remove-Item -Path $reportDirectory -Recurse -Force | ||
| } | ||
| New-Item -Path $stagingDirectory -ItemType Directory -Force | Out-Null | ||
|
|
||
| $mergedConfigurations = @{} | ||
|
|
||
| foreach ($tenant in $tenants) | ||
| { | ||
| $tenantName = Split-Path -Path $tenant.Name -Leaf | ||
| Write-Host "Merging $($tenant.Count) configuration file(s) of tenant '$tenantName'" -ForegroundColor Yellow | ||
|
|
||
| $tenantStagingDirectory = Join-Path -Path $stagingDirectory -ChildPath $tenantName | ||
| New-Item -Path $tenantStagingDirectory -ItemType Directory -Force | Out-Null | ||
|
|
||
| #Join-M365DSCConfiguration merges all configurations of one folder into the base file, so the nested export structure has to be flattened first. | ||
| $baseConfigurationFile = 'M365TenantConfig.ps1' | ||
| $isBaseConfiguration = $true | ||
| foreach ($configurationFile in ($tenant.Group | Sort-Object -Property FullName)) | ||
| { | ||
| $targetName = if ($isBaseConfiguration) | ||
| { | ||
| $baseConfigurationFile | ||
| } | ||
| else | ||
| { | ||
| "$($configurationFile.Directory.Name).ps1" | ||
| } | ||
| $isBaseConfiguration = $false | ||
|
|
||
| Copy-Item -Path $configurationFile.FullName -Destination (Join-Path -Path $tenantStagingDirectory -ChildPath $targetName) -Force | ||
| } | ||
|
|
||
| #Join-M365DSCConfiguration returns the merged configuration as a string instead of writing it to disk. | ||
| $mergedConfiguration = Join-M365DSCConfiguration -ConfigurationFile $baseConfigurationFile -ConfigurationPath $tenantStagingDirectory | ||
|
|
||
| if ([System.String]::IsNullOrWhiteSpace($mergedConfiguration)) | ||
| { | ||
| Write-Error "Join-M365DSCConfiguration returned an empty configuration for tenant '$tenantName'." -ErrorAction Stop | ||
| } | ||
|
|
||
| $tenantConfigurationPath = Join-Path -Path $reportDirectory -ChildPath "$tenantName.ps1" | ||
| Set-Content -Path $tenantConfigurationPath -Value $mergedConfiguration -Encoding utf8 -Force | ||
| $mergedConfigurations.Add($tenantName, $tenantConfigurationPath) | ||
|
|
||
| Write-Host " Merged configuration written to '$tenantConfigurationPath'." -ForegroundColor Green | ||
| } | ||
|
|
||
| Remove-Item -Path $stagingDirectory -Recurse -Force | ||
|
|
||
| if (-not $mergedConfigurations.ContainsKey($sourceTenant)) | ||
| { | ||
| Write-Error "The source tenant '$sourceTenant' was not found in '$inputDirectory'. Available tenants: $($mergedConfigurations.Keys -join ', ')." -ErrorAction Stop | ||
| } | ||
|
|
||
| $destinationTenants = $mergedConfigurations.Keys | Where-Object { $_ -ne $sourceTenant } | Sort-Object | ||
| if (-not $destinationTenants) | ||
| { | ||
| Write-Error "There is no tenant to compare the source tenant '$sourceTenant' with." -ErrorAction Stop | ||
| } | ||
|
|
||
| foreach ($destinationTenant in $destinationTenants) | ||
| { | ||
| $reportPath = Join-Path -Path $reportDirectory -ChildPath "DeltaReport-$sourceTenant-vs-$destinationTenant.html" | ||
| Write-Host "Creating delta report of '$sourceTenant' against '$destinationTenant'" -ForegroundColor Yellow | ||
|
|
||
| $Parameters = @{ | ||
| Source = $mergedConfigurations[$sourceTenant] | ||
| Destination = $mergedConfigurations[$destinationTenant] | ||
| OutputPath = $reportPath | ||
| Type = 'HTML' | ||
| DriftOnly = $true | ||
| } | ||
| New-M365DSCDeltaReport @Parameters | ||
|
|
||
| Write-Host " Delta report written to '$reportPath'." -ForegroundColor Green | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| trigger: none | ||
|
|
||
| parameters: | ||
| - name: sourceTenant | ||
| displayName: Source tenant of the delta report | ||
| type: string | ||
| default: templatetenant.onmicrosoft.com | ||
|
|
||
| variables: | ||
| buildFolderName: output | ||
| defaultBranch: main | ||
| Agent.Source.Git.ShallowFetchDepth: 0 | ||
|
|
||
| resources: | ||
| pipelines: | ||
| - pipeline: exportPipeline | ||
| source: M365DSC export | ||
| trigger: none | ||
|
|
||
| pool: | ||
| vmImage: windows-latest | ||
|
|
||
| steps: | ||
| - task: PowerShell@2 | ||
| name: displayEnvVariables | ||
| displayName: Display Environment Variables | ||
| inputs: | ||
| targetType: inline | ||
| pwsh: true | ||
| script: | | ||
| dir -Path env: | Format-Table -Property Name, Value -AutoSize | Out-String | Write-Host | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| - download: exportPipeline | ||
| patterns: "**" | ||
| displayName: Download Exported Tenant Configurations | ||
|
|
||
| - task: PowerShell@2 | ||
| name: InitializeModuleFolder | ||
| displayName: Initialize Program Files Modules | ||
| inputs: | ||
| pwsh: true | ||
| filePath: ./build.ps1 | ||
| arguments: -ResolveDependency -Tasks InitializeModuleFolderForDeltaReport #-UseModuleFast | ||
|
|
||
| - task: PowerShell@2 | ||
| name: deltaReport | ||
| displayName: Create Delta Report | ||
| inputs: | ||
| pwsh: true | ||
| filePath: ./build.ps1 | ||
| arguments: -Tasks deltaReport | ||
| env: | ||
| DeltaReportInputDirectory: $(Pipeline.Workspace)/exportPipeline | ||
| DeltaReportSourceTenant: ${{ parameters.sourceTenant }} | ||
|
|
||
| - task: PublishPipelineArtifact@1 | ||
| displayName: Publish Delta Report | ||
| inputs: | ||
| targetPath: $(buildFolderName)/DeltaReport | ||
| artifact: DeltaReport | ||
| publishLocation: pipeline | ||
| parallel: true | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.