From 08ec03b6ec9e52566f334b3346caf1eeb3a2c093 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sun, 15 Nov 2026 13:18:42 +0100 Subject: [PATCH] feat: discover shared sync consumers dynamically - Scan workspace repositories for vendored snapshots - Verify tag suggestions count only library media --- shared/backend/media/routes_db_test.go | 17 +- shared/scripts/sync-consumers.ps1 | 296 ++++++++++++++----------- 2 files changed, 177 insertions(+), 136 deletions(-) diff --git a/shared/backend/media/routes_db_test.go b/shared/backend/media/routes_db_test.go index 3459c57..cebebfe 100644 --- a/shared/backend/media/routes_db_test.go +++ b/shared/backend/media/routes_db_test.go @@ -348,10 +348,6 @@ func TestTagsAgainstPostgres(t *testing.T) { t.Fatalf("tags = %v, want Funny at 1 ahead of Quiet at -1", tags) } - suggestions := decode(t, h.do(http.MethodGet, "/tags/suggestions?limit=5", "", ""))["tags"].([]any) - if len(suggestions) == 0 { - t.Fatal("suggestions are empty") - } // A tag keeps its rows after its media is hidden or leaves the library. Only the library's // media is listed for the tag, so a tag's examples never point at a thumbnail that is not found. h.insertMedia(t, "rt-tags", "video", "tagged/clip.mp4", true) @@ -367,7 +363,18 @@ func TestTagsAgainstPostgres(t *testing.T) { t.Fatalf("media for the tag = %v, want only rt-tags (the hidden and unprocessed items are not listed)", listed) } - // Without a limit, suggestions list every tag, not only the first 1000. + // Suggestions count the library's media, so Funny and Quiet count rt-tags only: the hidden and + // unprocessed items above are not in the library. + suggestions := decode(t, h.do(http.MethodGet, "/tags/suggestions?limit=5", "", ""))["tags"].([]any) + if len(suggestions) != 2 || suggestions[0].(map[string]any)["tag"] != "Funny" || suggestions[0].(map[string]any)["count"] != float64(1) || suggestions[1].(map[string]any)["tag"] != "Quiet" || suggestions[1].(map[string]any)["count"] != float64(1) { + t.Fatalf("suggestions = %v, want Funny and Quiet at 1 each", suggestions) + } + + // Without a limit, suggestions list every tag, not only the first 1000. The bulk tags sit on a + // library item, because a tag on media that is not in the library is not suggested. + if _, err := h.pool.Exec(context.Background(), `INSERT INTO media (media_key, media_type, file_path, active, content_scanner_processed) VALUES ('rt-many', 'video', 'many/clip.mp4', TRUE, TRUE)`); err != nil { + t.Fatalf("insert many media: %v", err) + } if _, err := h.pool.Exec(context.Background(), `INSERT INTO media_tags (media_key, tag, user_id) SELECT 'rt-many', 'bulk ' || g, NULL FROM generate_series(1, 1001) AS g`); err != nil { t.Fatalf("insert many tags: %v", err) } diff --git a/shared/scripts/sync-consumers.ps1 b/shared/scripts/sync-consumers.ps1 index a631637..58d076f 100644 --- a/shared/scripts/sync-consumers.ps1 +++ b/shared/scripts/sync-consumers.ps1 @@ -1,6 +1,25 @@ +<# +.SYNOPSIS +Copies this shared repository's tracked files into every consumer project's vendored snapshot. + +.DESCRIPTION +Consumers are found by scanning the workspace, so the folder names do not matter. A consumer is a +git repository, at most three folders below the workspace root, that has a 'shared' folder (or the +legacy snapshot folder). The workspace root defaults to the folder that contains this repository. + +Without -Commit the changes are only staged in each consumer. -Commit commits them, and -Push pushes +each committed consumer's main branch. + +.PARAMETER Consumers +Consumer paths relative to the workspace root, for example 'Central/ProjectConfigurator'. + +.PARAMETER ConsumersFile +A JSON file of the form {"consumers": ["Central/ProjectConfigurator", ...]}. +#> [CmdletBinding()] param( [string]$SourceRepository, + [string]$WorkspaceRoot, [string[]]$Consumers, [string]$ConsumersFile, [switch]$Force, @@ -14,77 +33,16 @@ 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 every consumer -# uses) - originally a git submodule, converted to this vendored-copy pattern -# for consistency and to drop the private-submodule checkout auth dependency -# in CI. Some consumers used to mount a shared multi-flavor webui at a separate 'engine' -# folder; each is now its own independent frontend/backend and vendors this snapshot the same -# way as every other consumer below. -$consumerProjects = @( - New-ConsumerProject 'Original/MediaDesktop' - 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 'Fork/Bitmagnet' - New-ConsumerProject 'Fork/Heretic' - New-ConsumerProject 'Original/InfiniteVideo' - New-ConsumerProject 'Fork/MegaBasterd' - New-ConsumerProject 'Fork/HordeWorker' - New-ConsumerProject 'Original/KioskDisplay' - New-ConsumerProject 'Original/CraftStudio' - New-ConsumerProject 'Original/MediaViewer' - New-ConsumerProject 'Core/CarrierNode' - New-ConsumerProject 'Core/ContentScanner' - New-ConsumerProject 'Core/ModerationHub' - New-ConsumerProject 'Core/ProjectConfigurator' - New-ConsumerProject 'Core/AuthGuard' - New-ConsumerProject 'Core/OmniLogger' -) - -# Targets are chosen per run. Without -Consumers or -ConsumersFile every -# catalogue entry is synchronized. The file is the one AutoCode exports from its -# Shared sync panel: {"consumers": ["Original/MediaDesktop", ...]}. OutdoorGames -# is not in the catalogue because it runs without the shared packages. if ($Consumers -and $ConsumersFile) { throw 'Pass either -Consumers or -ConsumersFile, not both.' } -$requestedConsumers = $Consumers -if ($ConsumersFile) { - $targetFile = Get-Content -LiteralPath $ConsumersFile -Raw | ConvertFrom-Json - if ($null -eq $targetFile.consumers) { - throw "'$ConsumersFile' has no 'consumers' array." - } - $requestedConsumers = @($targetFile.consumers) -} +# The snapshot folder every consumer vendors, and the name older consumers used before it was renamed. +$snapshotFolder = 'shared' +$legacySnapshotFolder = ('Shared' + 'Code') -$selectedConsumers = $consumerProjects -if ($null -ne $requestedConsumers) { - $catalogPaths = @($consumerProjects | ForEach-Object { $_.Path }) - $unknownConsumers = @($requestedConsumers | Where-Object { $catalogPaths -notcontains $_ }) - if ($unknownConsumers.Count -gt 0) { - throw "Unknown consumer(s): $($unknownConsumers -join ', '). Choose from: $($catalogPaths -join ', ')." - } - $selectedConsumers = @($consumerProjects | Where-Object { $requestedConsumers -contains $_.Path }) - if ($selectedConsumers.Count -eq 0) { - throw 'No consumers selected; nothing to synchronize.' - } -} +# How many folders below the workspace root a consumer may sit (Central/ProjectConfigurator is two). +$maxConsumerDepth = 3 function Invoke-GitText { param( @@ -121,6 +79,19 @@ function Resolve-FullPath { return (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path } +# Joins a relative path written with '/' onto a base path, using the platform's separator. +function Join-RelativePath { + param( + [Parameter(Mandatory = $true)] + [string]$BasePath, + + [Parameter(Mandatory = $true)] + [string]$RelativePath + ) + + return [IO.Path]::Combine($BasePath, $RelativePath.Replace('/', [IO.Path]::DirectorySeparatorChar)) +} + function Get-RelativePath { param( [Parameter(Mandatory = $true)] @@ -130,13 +101,58 @@ function Get-RelativePath { [string]$TargetPath ) - $base = (Resolve-FullPath $BasePath).TrimEnd('\') + '\' + $separator = [IO.Path]::DirectorySeparatorChar + $base = (Resolve-FullPath $BasePath).TrimEnd($separator) + $separator $target = Resolve-FullPath $TargetPath if (-not $target.StartsWith($base, [System.StringComparison]::OrdinalIgnoreCase)) { throw "'$TargetPath' is not inside '$BasePath'." } - return $target.Substring($base.Length).Replace('\', '/') + return $target.Substring($base.Length).Replace($separator, '/') +} + +# Lists consumers as paths relative to $Root. Repositories are not searched inside, and the source +# repository is skipped. +function Find-ConsumerProjects { + param( + [Parameter(Mandatory = $true)] + [string]$Root, + + [Parameter(Mandatory = $true)] + [string]$SourceRoot + ) + + $found = New-Object 'System.Collections.Generic.List[string]' + $pending = New-Object 'System.Collections.Generic.Queue[object]' + $pending.Enqueue([pscustomobject]@{ Path = $Root; Depth = 0 }) + + while ($pending.Count -gt 0) { + $current = $pending.Dequeue() + $children = @(Get-ChildItem -LiteralPath $current.Path -Directory -Force -ErrorAction SilentlyContinue) + foreach ($child in $children) { + if ($child.Name.StartsWith('.') -or $child.Name -eq 'node_modules') { + continue + } + if ($child.FullName -ieq $SourceRoot) { + continue + } + + if (Test-Path -LiteralPath (Join-Path $child.FullName '.git')) { + $hasSnapshot = (Test-Path -LiteralPath (Join-RelativePath $child.FullName $snapshotFolder) -PathType Container) -or + (Test-Path -LiteralPath (Join-RelativePath $child.FullName $legacySnapshotFolder) -PathType Container) + if ($hasSnapshot) { + $found.Add((Get-RelativePath -BasePath $Root -TargetPath $child.FullName)) + } + continue + } + + if ($current.Depth + 1 -lt $maxConsumerDepth) { + $pending.Enqueue([pscustomobject]@{ Path = $child.FullName; Depth = $current.Depth + 1 }) + } + } + } + + return @($found | Sort-Object) } function Write-Utf8NoBom { @@ -192,7 +208,7 @@ function Convert-ToConsumerWebUiSources { [string]$WebUiRoot ) - $stylesPath = Join-Path $WebUiRoot 'src/lib/styles.css' + $stylesPath = Join-RelativePath $WebUiRoot 'src/lib/styles.css' if (Test-Path -LiteralPath $stylesPath) { $styles = Get-Content -LiteralPath $stylesPath -Raw $styles = $styles.Replace("@import '@gabriel20xx/design-tokens/theme.css';", "@import '../../../design-tokens/theme.css';") @@ -200,7 +216,7 @@ function Convert-ToConsumerWebUiSources { Write-Utf8NoBom -Path $stylesPath -Content $styles } - $svelteConfigPath = Join-Path $WebUiRoot 'svelte.config.js' + $svelteConfigPath = Join-RelativePath $WebUiRoot 'svelte.config.js' if (Test-Path -LiteralPath $svelteConfigPath) { Write-Utf8NoBom -Path $svelteConfigPath -Content "export default {};`n" } @@ -233,36 +249,22 @@ function Test-LocalSharedDependency { return $false } +# The source must be the root of its own git repository. A consumer's snapshot is copied from this +# repository and has no .git folder, so running the script from inside a snapshot fails here. if ([string]::IsNullOrWhiteSpace($SourceRepository)) { - $scriptParent = Resolve-FullPath (Join-Path $PSScriptRoot '..') - $scriptParentGitRoot = (Invoke-GitText -WorkingDirectory $scriptParent -Arguments @('rev-parse', '--show-toplevel') | Select-Object -First 1).Trim() - $scriptParentGitRoot = Resolve-FullPath $scriptParentGitRoot - if ($scriptParentGitRoot -ieq $scriptParent) { - $SourceRepository = $scriptParent - } - else { - $workspaceRoot = Split-Path -Parent (Split-Path -Parent $scriptParentGitRoot) - $SourceRepository = Join-Path $workspaceRoot 'shared' - } + $SourceRepository = Join-Path $PSScriptRoot '..' } - $sourceRoot = Resolve-FullPath $SourceRepository -$sourceRepositoryRoot = (Invoke-GitText -WorkingDirectory $sourceRoot -Arguments @('rev-parse', '--show-toplevel') | Select-Object -First 1).Trim() -$sourceRoot = Resolve-FullPath $sourceRepositoryRoot - -# The workspace root is the ancestor directory that contains both 'Original' -# and 'Fork' (every consumer project lives under one of those, or under -# 'Core' for the central infrastructure services). Walk up from the shared -# repo instead of assuming a fixed nesting depth, since the workspace layout has -# changed before and may change again. -$workspaceRoot = Split-Path -Parent $sourceRoot -while ($workspaceRoot -and -not ((Test-Path -LiteralPath (Join-Path $workspaceRoot 'Original') -PathType Container) -and (Test-Path -LiteralPath (Join-Path $workspaceRoot 'Fork') -PathType Container))) { - $parent = Split-Path -Parent $workspaceRoot - if (-not $parent -or $parent -eq $workspaceRoot) { - throw "Could not locate the workspace root (a directory containing both 'Original' and 'Fork') above $sourceRoot." - } - $workspaceRoot = $parent +if (-not (Test-Path -LiteralPath (Join-Path $sourceRoot '.git'))) { + throw "'$sourceRoot' is not the root of a git repository. Pass -SourceRepository with the root of the shared repository." } + +# By default the workspace is the folder that holds the shared repository. +if ([string]::IsNullOrWhiteSpace($WorkspaceRoot)) { + $WorkspaceRoot = Split-Path -Parent $sourceRoot +} +$workspaceRoot = Resolve-FullPath $WorkspaceRoot + $sourceCommit = (Invoke-GitText -WorkingDirectory $sourceRoot -Arguments @('rev-parse', '--short', 'HEAD') | Select-Object -First 1).Trim() $sourceFiles = @(Invoke-GitText -WorkingDirectory $sourceRoot -Arguments @('ls-files') | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) @@ -271,36 +273,61 @@ foreach ($sourceFile in $sourceFiles) { $sourceFileSet[$sourceFile.Replace('\', '/')] = $true } -Write-Host "Synchronizing $($sourceFiles.Count) tracked shared files from $sourceCommit." +$discoveredConsumers = @(Find-ConsumerProjects -Root $workspaceRoot -SourceRoot $sourceRoot) +if ($discoveredConsumers.Count -eq 0) { + throw "No consumer repositories with a '$snapshotFolder' folder were found under '$workspaceRoot' (searched $maxConsumerDepth folders deep)." +} + +$requestedConsumers = $null +if ($ConsumersFile) { + $targetFile = Get-Content -LiteralPath $ConsumersFile -Raw | ConvertFrom-Json + if ($null -eq $targetFile.consumers) { + throw "'$ConsumersFile' has no 'consumers' array." + } + $requestedConsumers = @($targetFile.consumers) +} +elseif ($Consumers) { + $requestedConsumers = @($Consumers) +} + +$selectedConsumers = $discoveredConsumers +if ($null -ne $requestedConsumers) { + $requestedConsumers = @($requestedConsumers | ForEach-Object { ([string]$_).Replace('\', '/').Trim('/') }) + $unknownConsumers = @($requestedConsumers | Where-Object { $discoveredConsumers -notcontains $_ }) + if ($unknownConsumers.Count -gt 0) { + throw "Unknown consumer(s): $($unknownConsumers -join ', '). Found: $($discoveredConsumers -join ', ')." + } + $selectedConsumers = @($discoveredConsumers | Where-Object { $requestedConsumers -contains $_ }) + if ($selectedConsumers.Count -eq 0) { + throw 'No consumers selected; nothing to synchronize.' + } +} + +Write-Host "Workspace: $workspaceRoot" +Write-Host "Synchronizing $($sourceFiles.Count) tracked shared files from $sourceCommit into $($selectedConsumers.Count) consumer(s):" +$selectedConsumers | ForEach-Object { Write-Host " $_" } $failures = New-Object 'System.Collections.Generic.List[string]' +$changedConsumers = New-Object 'System.Collections.Generic.List[string]' +$unchangedConsumers = New-Object 'System.Collections.Generic.List[string]' -foreach ($consumerProject in $selectedConsumers) { - $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") - continue - } - +foreach ($relativeProject in $selectedConsumers) { try { - $projectRoot = Resolve-FullPath $projectRoot - $destinationRoot = Join-Path $projectRoot $destination - $isLegacyEligible = $destination -eq 'shared' - $legacyDirectoryName = ('Shared' + 'Code') + $projectRoot = Resolve-FullPath (Join-RelativePath $workspaceRoot $relativeProject) + $destinationRoot = Join-RelativePath $projectRoot $snapshotFolder + $projectDirectories = @(Get-ChildItem -LiteralPath $projectRoot -Directory -Force) - $destinationEntry = $projectDirectories | Where-Object { $_.Name -ceq $destination } - $legacyEntry = if ($isLegacyEligible) { $projectDirectories | Where-Object { $_.Name -ceq $legacyDirectoryName } } else { $null } + $destinationEntry = $projectDirectories | Where-Object { $_.Name -ceq $snapshotFolder } + $legacyEntry = $projectDirectories | Where-Object { $_.Name -ceq $legacySnapshotFolder } if ($null -ne $destinationEntry -and $null -ne $legacyEntry) { - throw "Both $destination and the legacy shared snapshot directory exist. Remove the legacy directory before synchronizing." + throw "Both $snapshotFolder and the legacy snapshot directory exist. Remove the legacy directory before synchronizing." } - $dirtyDestination = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $destination)) - $dirtyLegacy = if ($isLegacyEligible) { @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $legacyDirectoryName)) } else { @() } + $dirtyDestination = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $snapshotFolder)) + $dirtyLegacy = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('status', '--porcelain', '--', $legacySnapshotFolder)) $hasLocalChanges = $dirtyDestination.Count -gt 0 -or $dirtyLegacy.Count -gt 0 if ($hasLocalChanges -and -not $Force) { - throw "$destination has local changes. Commit them or rerun with -Force." + throw "$snapshotFolder has local changes. Commit them or rerun with -Force." } if ($hasLocalChanges) { # -Force replaces the snapshot, so keep a copy of what it replaces first. @@ -309,7 +336,7 @@ foreach ($consumerProject in $selectedConsumers) { foreach ($existingEntry in @($destinationEntry, $legacyEntry) | Where-Object { $null -ne $_ }) { Copy-Item -LiteralPath $existingEntry.FullName -Destination (Join-Path $backupRoot $existingEntry.Name) -Recurse -Force } - Write-Host " Backed up the local $destination changes in $relativeProject to $backupRoot before overwriting." + Write-Host " Backed up the local $snapshotFolder changes in $relativeProject to $backupRoot before overwriting." } if ($null -ne $legacyEntry) { @@ -320,11 +347,12 @@ foreach ($consumerProject in $selectedConsumers) { New-Item -ItemType Directory -Force -Path $destinationRoot | Out-Null - $existingDestinationFiles = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', $destination) | Where-Object { $_ -like "$destination/*" }) + $existingDestinationFiles = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', $snapshotFolder) | + Where-Object { $_.StartsWith("$snapshotFolder/", [System.StringComparison]::Ordinal) }) foreach ($existingDestinationFile in $existingDestinationFiles) { - $relativeDestinationFile = $existingDestinationFile.Substring("$destination/".Length).Replace('\', '/') + $relativeDestinationFile = $existingDestinationFile.Substring($snapshotFolder.Length + 1).Replace('\', '/') if (-not $sourceFileSet.ContainsKey($relativeDestinationFile)) { - $stalePath = Join-Path $destinationRoot ($relativeDestinationFile -replace '/', '\') + $stalePath = Join-RelativePath $destinationRoot $relativeDestinationFile if (Test-Path -LiteralPath $stalePath -PathType Leaf) { Remove-Item -LiteralPath $stalePath -Force } @@ -332,25 +360,26 @@ foreach ($consumerProject in $selectedConsumers) { } foreach ($sourceFile in $sourceFiles) { - $sourcePath = Join-Path $sourceRoot ($sourceFile -replace '/', '\') - $destinationPath = Join-Path $destinationRoot ($sourceFile -replace '/', '\') + $sourcePath = Join-RelativePath $sourceRoot $sourceFile + $destinationPath = Join-RelativePath $destinationRoot $sourceFile $destinationDirectory = Split-Path -Parent $destinationPath New-Item -ItemType Directory -Force -Path $destinationDirectory | Out-Null Copy-Item -LiteralPath $sourcePath -Destination $destinationPath -Force } - $webUiPackagePath = Join-Path $destinationRoot 'packages/web-ui/package.json' + $webUiPackagePath = Join-RelativePath $destinationRoot 'packages/web-ui/package.json' if (Test-Path -LiteralPath $webUiPackagePath) { Convert-ToConsumerWebUiPackage -PackagePath $webUiPackagePath - Convert-ToConsumerWebUiSources -WebUiRoot (Join-Path $destinationRoot 'packages/web-ui') + Convert-ToConsumerWebUiSources -WebUiRoot (Join-RelativePath $destinationRoot 'packages/web-ui') } $lockFiles = @() - $sharedPrefix = ((Resolve-FullPath $destinationRoot).TrimEnd('\') + '\') + $separator = [IO.Path]::DirectorySeparatorChar + $sharedPrefix = (Resolve-FullPath $destinationRoot).TrimEnd($separator) + $separator $packageFiles = @(Get-ChildItem -LiteralPath $projectRoot -Recurse -File -Filter 'package.json' -Force | Where-Object { - $_.FullName -notlike "$sharedPrefix*" -and - $_.FullName -notmatch '\\node_modules\\' + -not $_.FullName.StartsWith($sharedPrefix, [System.StringComparison]::OrdinalIgnoreCase) -and + $_.FullName -notmatch '[\\/]node_modules[\\/]' }) foreach ($packageFile in $packageFiles) { @@ -367,7 +396,7 @@ foreach ($consumerProject in $selectedConsumers) { $relativeLockPath = Get-RelativePath -BasePath $projectRoot -TargetPath $lockPath $trackedLock = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('ls-files', '--', $relativeLockPath)) $shouldStageLock = $trackedLock.Count -gt 0 - Write-Host " Updating $relativeProject/$(Get-RelativePath -BasePath $projectRoot -TargetPath $lockPath)" + Write-Host " Updating $relativeProject/$relativeLockPath" Push-Location -LiteralPath $packageFile.DirectoryName try { & npm install --package-lock-only --ignore-scripts --prefer-offline @@ -387,15 +416,15 @@ foreach ($consumerProject in $selectedConsumers) { } } - $null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $destination) + $null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $snapshotFolder) foreach ($lockFile in $lockFiles) { $null = Invoke-GitText -WorkingDirectory $projectRoot -Arguments @('add', '--', $lockFile) } - $targetPaths = @($destination) + $lockFiles + $targetPaths = @($snapshotFolder) + $lockFiles $stagedChanges = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments (@('diff', '--cached', '--name-only', '--') + $targetPaths)) if ($Commit -and $stagedChanges.Count -gt 0) { - $commitMessage = "Sync $destination snapshot from $sourceCommit" + $commitMessage = "Sync $snapshotFolder snapshot from $sourceCommit" $commitArguments = @('commit', '--only', '-m', $commitMessage, '--') + $targetPaths $commitOutput = @(Invoke-GitText -WorkingDirectory $projectRoot -Arguments $commitArguments) $commitOutput | ForEach-Object { Write-Host " $_" } @@ -411,9 +440,11 @@ foreach ($consumerProject in $selectedConsumers) { } if ($stagedChanges.Count -gt 0) { + $changedConsumers.Add($relativeProject) Write-Host "Synced $relativeProject." } else { + $unchangedConsumers.Add($relativeProject) Write-Host "$relativeProject is already synchronized." } } @@ -424,6 +455,9 @@ foreach ($consumerProject in $selectedConsumers) { } } +Write-Host '' +Write-Host "Changed: $($changedConsumers.Count); already synchronized: $($unchangedConsumers.Count); failed: $($failures.Count)." + if ($failures.Count -gt 0) { throw "shared synchronization failed for $($failures.Count) project(s): $($failures -join '; ')" }