diff --git a/shared/scripts/sync-consumers.ps1 b/shared/scripts/sync-consumers.ps1 index eb5067c..ed0995b 100644 --- a/shared/scripts/sync-consumers.ps1 +++ b/shared/scripts/sync-consumers.ps1 @@ -12,20 +12,43 @@ if ($Push -and -not $Commit) { throw 'The -Push switch requires -Commit so that only generated synchronization changes are pushed.' } +function New-ConsumerProject { + param( + [Parameter(Mandatory = $true)] + [string]$Path, + + [string]$Destination = 'shared' + ) + + return [pscustomobject]@{ Path = $Path; Destination = $Destination } +} + +# Destination defaults to 'shared' (the snapshot folder name most consumers +# use). The engine/media-backend family below mounts the same snapshot at +# 'engine' instead - historically a git submodule, converted to this same +# vendored-copy pattern for consistency and to drop the private-submodule +# checkout auth dependency in CI. $consumerProjects = @( - 'Original/AutoCode', - 'Original/SimpleCollection', - 'Original/CollabTable', - 'Original/GameStream', - 'Original/SyncServer', - 'Original/UnraidMonitor', - 'Original/PubliSafe', - 'Forks/Bitmagnet', - 'Forks/Heretic', - 'Original/InfiniteVideo', - 'Forks/MegaBasterd', - 'Forks/HordeWorker', - 'Original/OutdoorGames' + New-ConsumerProject 'Original/AutoCode' + New-ConsumerProject 'Original/SimpleCollection' + New-ConsumerProject 'Original/CollabTable' + New-ConsumerProject 'Original/GameStream' + New-ConsumerProject 'Original/SyncServer' + New-ConsumerProject 'Original/UnraidMonitor' + New-ConsumerProject 'Original/PubliSafe' + New-ConsumerProject 'Forks/Bitmagnet' + New-ConsumerProject 'Forks/Heretic' + New-ConsumerProject 'Original/InfiniteVideo' + New-ConsumerProject 'Forks/MegaBasterd' + New-ConsumerProject 'Forks/HordeWorker' + New-ConsumerProject 'Original/OutdoorGames' + New-ConsumerProject 'Original/KioskDisplay' -Destination 'engine' + New-ConsumerProject 'Original/MediaAnalyzer' -Destination 'engine' + New-ConsumerProject 'Original/MediaTools' -Destination 'engine' + New-ConsumerProject 'Original/MediaViewer' -Destination 'engine' + New-ConsumerProject 'Central/MediaServant' -Destination 'engine' + New-ConsumerProject 'Central/ModerationHub' -Destination 'engine' + New-ConsumerProject 'Central/ProjectConfigurator' -Destination 'engine' ) function Invoke-GitText { @@ -216,7 +239,9 @@ Write-Host "Synchronizing $($sourceFiles.Count) tracked shared files from $sourc $failures = New-Object 'System.Collections.Generic.List[string]' -foreach ($relativeProject in $consumerProjects) { +foreach ($consumerProject in $consumerProjects) { + $relativeProject = $consumerProject.Path + $destination = $consumerProject.Destination $projectRoot = Join-Path $workspaceRoot ($relativeProject -replace '/', '\') if (-not (Test-Path -LiteralPath $projectRoot -PathType Container)) { $failures.Add("${relativeProject}: project directory not found") @@ -225,19 +250,20 @@ foreach ($relativeProject in $consumerProjects) { try { $projectRoot = Resolve-FullPath $projectRoot - $destinationRoot = Join-Path $projectRoot 'shared' + $destinationRoot = Join-Path $projectRoot $destination + $isLegacyEligible = $destination -eq 'shared' $legacyDirectoryName = ('Shared' + 'Code') $projectDirectories = @(Get-ChildItem -LiteralPath $projectRoot -Directory -Force) - $destinationEntry = $projectDirectories | Where-Object { $_.Name -ceq 'shared' } - $legacyEntry = $projectDirectories | Where-Object { $_.Name -ceq $legacyDirectoryName } + $destinationEntry = $projectDirectories | Where-Object { $_.Name -ceq $destination } + $legacyEntry = if ($isLegacyEligible) { $projectDirectories | Where-Object { $_.Name -ceq $legacyDirectoryName } } else { $null } if ($null -ne $destinationEntry -and $null -ne $legacyEntry) { - throw "Both shared and the legacy shared snapshot directory exist. Remove the legacy directory before synchronizing." + throw "Both $destination and the legacy shared snapshot directory exist. Remove the legacy directory before synchronizing." } - $dirtyshared = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', 'shared')) - $dirtyLegacy = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $legacyDirectoryName)) - if (($dirtyshared.Count -gt 0 -or $dirtyLegacy.Count -gt 0) -and -not $Force) { - throw "shared has local changes. Commit them or rerun with -Force." + $dirtyDestination = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $destination)) + $dirtyLegacy = if ($isLegacyEligible) { @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $legacyDirectoryName)) } else { @() } + if (($dirtyDestination.Count -gt 0 -or $dirtyLegacy.Count -gt 0) -and -not $Force) { + throw "$destination has local changes. Commit them or rerun with -Force." } if ($null -ne $legacyEntry) { @@ -248,11 +274,11 @@ foreach ($relativeProject in $consumerProjects) { New-Item -ItemType Directory -Force -Path $destinationRoot | Out-Null - $existingSharedFiles = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', 'shared') | Where-Object { $_ -like 'shared/*' }) - foreach ($existingSharedFile in $existingSharedFiles) { - $relativeSharedFile = $existingSharedFile.Substring('shared/'.Length).Replace('\', '/') - if (-not $sourceFileSet.ContainsKey($relativeSharedFile)) { - $stalePath = Join-Path $destinationRoot ($relativeSharedFile -replace '/', '\') + $existingDestinationFiles = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', $destination) | Where-Object { $_ -like "$destination/*" }) + foreach ($existingDestinationFile in $existingDestinationFiles) { + $relativeDestinationFile = $existingDestinationFile.Substring("$destination/".Length).Replace('\', '/') + if (-not $sourceFileSet.ContainsKey($relativeDestinationFile)) { + $stalePath = Join-Path $destinationRoot ($relativeDestinationFile -replace '/', '\') if (Test-Path -LiteralPath $stalePath -PathType Leaf) { Remove-Item -LiteralPath $stalePath -Force } @@ -315,15 +341,15 @@ foreach ($relativeProject in $consumerProjects) { } } - $null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', 'shared') + $null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $destination) foreach ($lockFile in $lockFiles) { $null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $lockFile) } - $targetPaths = @('shared') + $lockFiles + $targetPaths = @($destination) + $lockFiles $stagedChanges = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments (@('diff', '--cached', '--name-only', '--') + $targetPaths)) if ($Commit -and $stagedChanges.Count -gt 0) { - $commitMessage = "Sync shared snapshot from $sourceCommit" + $commitMessage = "Sync $destination snapshot from $sourceCommit" $commitArguments = @('commit', '--only', '-m', $commitMessage, '--') + $targetPaths $commitOutput = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments $commitArguments) $commitOutput | ForEach-Object { Write-Host " $_" }