Param( [Parameter(Mandatory=$true)] [string]$ProjectRoot, [Parameter(Mandatory=$true)] [string]$VersionsDir, [Parameter(Mandatory=$true)] [string]$Timestamp, [Parameter(Mandatory=$true)] [string]$DeployZip ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' function Get-RelPath($base, $full){ return Resolve-Path -LiteralPath $full | ForEach-Object { $_.Path.Substring((Resolve-Path $base).Path.Length).TrimStart('\','/') } } if(!(Test-Path $VersionsDir)){ New-Item -ItemType Directory -Force -Path $VersionsDir | Out-Null } $srcZip = Join-Path $VersionsDir ("waouw-deploy-$Timestamp-src.zip") $srcReport = Join-Path $VersionsDir ("waouw-deploy-$Timestamp-src.txt") # Build file list with exclusions $excludes = @( '(^|[\\/])Versions([\\/]|$)', 'version_counter.txt$', '\\.git(\\|$)', '\\.vscode(\\|$)', '\\.idea(\\|$)', '\\node_modules(\\|$)', '\\dist(\\|$)', '\\__pycache__(\\|$)', '\\.pytest_cache(\\|$)', '\\.mypy_cache(\\|$)', '\\backend\\secure(\\|$)', '\\backend\\logs(\\|$)', '\\tools(\\|$)', '\\.DS_Store$' ) $allFiles = Get-ChildItem -LiteralPath $ProjectRoot -Recurse -File -Force $files = $allFiles | Where-Object { $rel = Get-RelPath $ProjectRoot $_.FullName if ($rel -match '(^|[\\/])Versions([\\/]|$)') { return $false } -not ($excludes | Where-Object { $rel -match $_ }) } # Write zip if(Test-Path $srcZip){ Remove-Item -LiteralPath $srcZip -Force } Add-Type -AssemblyName System.IO.Compression.FileSystem $zip = [System.IO.Compression.ZipFile]::Open($srcZip, 'Create') foreach($f in $files){ $rel = Get-RelPath $ProjectRoot $f.FullName $rel = $rel -replace '\\','/' [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $f.FullName, $rel, [System.IO.Compression.CompressionLevel]::Optimal) | Out-Null } $zip.Dispose() # Compute hashes for diff function HashMapFromZip($zipPath){ $map = @{} if(!(Test-Path $zipPath)){ return $map } $tmp = New-Item -ItemType Directory -Force -Path ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())) Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $tmp.FullName) $files = Get-ChildItem -LiteralPath $tmp.FullName -Recurse -File foreach($f in $files){ $rel = Get-RelPath $tmp.FullName $f.FullName $hash = (Get-FileHash -Algorithm SHA256 -LiteralPath $f.FullName).Hash $map[$rel] = $hash } Remove-Item -Recurse -Force -LiteralPath $tmp.FullName return $map } $prevSrcZip = Get-ChildItem -LiteralPath $VersionsDir -Filter '*-src.zip' | Sort-Object LastWriteTime -Descending | Select-Object -Skip 1 -First 1 $prevMap = @{} if($prevSrcZip){ $prevMap = HashMapFromZip $prevSrcZip.FullName } $curMap = @{} $tmpCur = New-Item -ItemType Directory -Force -Path ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())) [System.IO.Compression.ZipFile]::ExtractToDirectory($srcZip, $tmpCur.FullName) (Get-ChildItem -LiteralPath $tmpCur.FullName -Recurse -File) | ForEach-Object { $rel = Get-RelPath $tmpCur.FullName $_.FullName $curMap[$rel] = (Get-FileHash -Algorithm SHA256 -LiteralPath $_.FullName).Hash } Remove-Item -Recurse -Force -LiteralPath $tmpCur.FullName $added = New-Object System.Collections.Generic.List[string] $removed = New-Object System.Collections.Generic.List[string] $modified = New-Object System.Collections.Generic.List[string] $allKeys = ($prevMap.Keys + $curMap.Keys) | Sort-Object -Unique foreach($k in $allKeys){ if(-not $prevMap.ContainsKey($k) -and $curMap.ContainsKey($k)){ $added.Add($k) | Out-Null } elseif($prevMap.ContainsKey($k) -and -not $curMap.ContainsKey($k)){ $removed.Add($k) | Out-Null } else{ if($prevMap[$k] -ne $curMap[$k]){ $modified.Add($k) | Out-Null } } } $baseCompare = if ($null -ne $prevSrcZip) { $prevSrcZip.Name } else { '' } $header = @( "Version: $Timestamp", "DeployZip: $DeployZip", "SourcesZip: $srcZip", "GeneratedAt: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')", "BaseCompare: $baseCompare" ) -join "`r`n" $content = @() $content += $header $content += "" $content += "[Added]" $content += ($added | Sort-Object) $content += "" $content += "[Removed]" $content += ($removed | Sort-Object) $content += "" $content += "[Modified]" $content += ($modified | Sort-Object) Set-Content -LiteralPath $srcReport -Value $content -Encoding UTF8 Write-Host "[OK] Sources archive: $srcZip" Write-Host "[OK] Report: $srcReport"