-
Notifications
You must be signed in to change notification settings - Fork 627
Expand file tree
/
Copy pathpersist-to-cache.ps1
More file actions
88 lines (78 loc) · 2.56 KB
/
persist-to-cache.ps1
File metadata and controls
88 lines (78 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<#
.SYNOPSIS Push output/ai/ contents to the data-cache branch.
.DESCRIPTION Copies all files from output/ai/ to .data-cache/, then commits and pushes.
Run this manually or as a CI step after skills have written their outputs.
.EXAMPLE pwsh scripts/persist-to-cache.ps1
.EXAMPLE pwsh scripts/persist-to-cache.ps1 -NoPush # copy only, no git operations
#>
#requires -Version 7.0
param([switch]$NoPush)
$ErrorActionPreference = 'Stop'
$source = 'output/ai'
$dest = '.data-cache'
if (-not (Test-Path $source)) {
Write-Host "ℹ️ No output/ai/ directory — nothing to persist"
exit 0
}
if (-not (Test-Path $dest)) {
Write-Host "❌ .data-cache/ not found — is the data-cache worktree set up?"
exit 2
}
# Copy all files from output/ai/ to .data-cache/, preserving structure
$files = Get-ChildItem $source -Recurse -File
if ($files.Count -eq 0) {
Write-Host "ℹ️ output/ai/ is empty — nothing to persist"
exit 0
}
$resolvedSource = (Resolve-Path $source).Path
foreach ($file in $files) {
$relativePath = [System.IO.Path]::GetRelativePath($resolvedSource, $file.FullName)
$destPath = Join-Path $dest $relativePath
New-Item -ItemType Directory -Force (Split-Path $destPath) | Out-Null
Copy-Item $file.FullName $destPath -Force
Write-Host " 📄 $relativePath"
}
Write-Host "✅ Copied $($files.Count) file(s) to $dest"
if ($NoPush) {
Write-Host "ℹ️ Push skipped (-NoPush)"
exit 0
}
Push-Location $dest
try {
git add -A
git diff --cached --quiet 2>&1
if ($LASTEXITCODE -gt 1) {
Write-Host "❌ git diff --cached --quiet failed (exit code $LASTEXITCODE)"
exit 1
}
if ($LASTEXITCODE -eq 0) {
Write-Host "ℹ️ No changes to commit"
exit 0
}
git commit -m "ai: persist output from $(Get-Date -Format 'yyyy-MM-dd HH:mm')"
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ git commit failed (exit code $LASTEXITCODE)"
exit 1
}
$pushed = $false
for ($i = 0; $i -lt 3; $i++) {
git push 2>&1
if ($LASTEXITCODE -eq 0) { $pushed = $true; break }
if ($i -lt 2) {
Write-Host "⚠️ Push failed (attempt $($i + 1)/3), rebasing..."
git pull --rebase
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ git pull --rebase failed (exit code $LASTEXITCODE)"
exit 1
}
}
}
if ($pushed) {
Write-Host "✅ Pushed to data-cache"
} else {
Write-Host "❌ Push failed after 3 attempts"
exit 1
}
} finally {
Pop-Location
}