@@ -670,6 +670,67 @@ jobs:
670670 with :
671671 name : AzureDevOpsMigrationTools-Site2
672672 path : ./_site2
673+
674+ - name : Merge Configuration Files
675+ run : |
676+ # Find all files matching the pattern in a safe way
677+ $files = Get-ChildItem -Path "." -Recurse -Filter "staticwebapp.*.json" -ErrorAction Stop
678+
679+ if ($files.Count -eq 0) {
680+ Write-Host "No files matching the pattern 'staticwebapp.*.json' were found."
681+ exit 1
682+ }
683+
684+ # Output each file's full name (for verification/debugging purposes)
685+ $files | ForEach-Object {
686+ Write-Host "Found file: $($_.FullName)"
687+ }
688+
689+ # Paths to main and environment-specific config files
690+ $rootConfig = "./_site/staticwebapp.config.json"
691+ $environmentConfig = "./_site/staticwebapp.config.${{ (needs.Setup.outputs.nkdAgility_AzureSitesEnvironment) }}.json"
692+ # $routesConfig = "./_site/staticwebapp.config.routes.json"
693+
694+ # Check if both target files exist
695+ if ((Test-Path -Path $rootConfig -ErrorAction Stop) -and (Test-Path -Path $environmentConfig -ErrorAction Stop)) {
696+ try {
697+ # Run jq to merge files and capture the output
698+ $mergedContent = & jq -s 'reduce .[] as $item ({}; . * $item)' $rootConfig $environmentConfig # $routesConfig
699+
700+ if ($mergedContent -ne "") {
701+ # Write the merged content to the output file
702+ $mergedContent | Set-Content -Path "./staticwebapp.config.json"
703+ Write-Host "Merged JSON files successfully."
704+ }
705+ else {
706+ Write-Host "jq command produced empty output. Check JSON structures in input files."
707+ exit 1
708+ }
709+ }
710+ catch {
711+ Write-Host "Error merging JSON files with jq: $_"
712+ exit 1
713+ }
714+ }
715+ else {
716+ Write-Host "One or both of the specified config files were not found:"
717+ if (!(Test-Path -Path $rootConfig)) { Write-Host " - $rootConfig not found" }
718+ if (!(Test-Path -Path $environmentConfig)) { Write-Host " - $environmentConfig not found" }
719+ exit 1
720+ }
721+
722+ # Verify and read the merged file content
723+ try {
724+ $content = Get-Content -Path "./staticwebapp.config.json" -ErrorAction Stop
725+ Write-Host "Content of merged config file:"
726+ Write-Output $content
727+ }
728+ catch {
729+ Write-Host "Error reading the merged config file: $_"
730+ exit 1
731+ }
732+
733+
673734 - name : " Find files"
674735 shell : pwsh
675736 run : |
0 commit comments