Spaces:
Running
Running
Eric Putnam
Claude Opus 5 (1M context)
feat: deploy simpledocreview as a browser-only static space
3d968d9 | <# | |
| .SYNOPSIS | |
| Sync upstream, build the static site, verify it, commit, and push to Hugging Face. | |
| .DESCRIPTION | |
| The one command to run after updating SimpleDocReview: | |
| .\scripts\deploy.ps1 | |
| It re-mirrors app/ from the local upstream checkout, builds the site into the | |
| repository root, runs the parity and browser checks, commits with the | |
| upstream commit in the message, and pushes to the Hugging Face Space remote. | |
| The Space serves files directly with no build step of its own, so what you | |
| push is exactly what visitors get - which is also why the checks run before | |
| the push rather than after it. A broken deploy is live immediately. | |
| .PARAMETER UpstreamPath | |
| Local SimpleDocReview checkout. Defaults to C:\dev\SimpleDocReview. | |
| .PARAMETER Message | |
| Commit message. Defaults to "chore: sync simpledocreview @ <sha>". | |
| .PARAMETER Remote | |
| Git remote to push to. Defaults to 'hf' (the Hugging Face Space). | |
| .PARAMETER AlsoPushOrigin | |
| Additionally push to 'origin' (the GitHub mirror of this deployment repo). | |
| .PARAMETER SkipSync | |
| Do not re-mirror app/; build and deploy what is already there. | |
| .PARAMETER SkipBuild | |
| Do not rebuild; verify, commit, and push the site already at the repo root. | |
| .PARAMETER SkipTests | |
| Do not run the parity and browser checks. They are the only thing standing | |
| between an upstream change and a Space that quietly behaves differently, so | |
| skip them only when you have just run them by hand. | |
| .PARAMETER AllowDirty | |
| Pass through to sync-upstream.ps1: allow a dirty upstream working tree. | |
| .PARAMETER DryRun | |
| Sync, build, and verify, show what would be committed, but do not commit or push. | |
| .EXAMPLE | |
| .\scripts\deploy.ps1 | |
| .EXAMPLE | |
| .\scripts\deploy.ps1 -Message "fix: correct the vague-language snippet" -AlsoPushOrigin | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [string] $UpstreamPath = 'C:\dev\SimpleDocReview', | |
| [string] $Message, | |
| [string] $Remote = 'hf', | |
| [switch] $AlsoPushOrigin, | |
| [switch] $SkipSync, | |
| [switch] $SkipBuild, | |
| [switch] $SkipTests, | |
| [switch] $AllowDirty, | |
| [switch] $DryRun | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| $repoRoot = Split-Path -Parent $PSScriptRoot | |
| if (-not $SkipSync) { | |
| $syncArgs = @{ UpstreamPath = $UpstreamPath } | |
| if ($AllowDirty) { $syncArgs['AllowDirty'] = $true } | |
| & (Join-Path $PSScriptRoot 'sync-upstream.ps1') @syncArgs | |
| Write-Host '' | |
| } | |
| if (-not $SkipBuild) { | |
| & (Join-Path $PSScriptRoot 'build-static.ps1') | |
| Write-Host '' | |
| } | |
| if (-not $SkipTests) { | |
| Push-Location $repoRoot | |
| try { | |
| Write-Host 'Checking the browser API against the real app.py' -ForegroundColor Cyan | |
| & node (Join-Path $repoRoot 'tests\parity\run-parity.mjs') | |
| if ($LASTEXITCODE -ne 0) { | |
| throw 'Parity check failed: the browser API no longer matches app.py. Nothing was deployed.' | |
| } | |
| Write-Host '' | |
| Write-Host 'Checking the built site in a browser' -ForegroundColor Cyan | |
| & node (Join-Path $repoRoot 'tests\browser\run-browser-check.mjs') | |
| if ($LASTEXITCODE -ne 0) { | |
| throw 'Browser check failed. Nothing was deployed.' | |
| } | |
| Write-Host '' | |
| } | |
| finally { Pop-Location } | |
| } | |
| Push-Location $repoRoot | |
| try { | |
| # Verify the target remote exists before doing anything that needs undoing. | |
| $remotes = & git remote | |
| if ($remotes -notcontains $Remote) { | |
| $missingRemoteMessage = @" | |
| Git remote '$Remote' is not configured. | |
| Create the Space at https://huggingface.co/new-space (choose the Static SDK, | |
| Blank template), then wire it up: | |
| git remote add $Remote https://huggingface.co/spaces/<user>/<space-name> | |
| See DEPLOY.md for the full first-time setup. | |
| "@ | |
| # A dry run only reports, so a missing remote is a warning there and a | |
| # hard stop for a real deploy. | |
| if ($DryRun) { Write-Warning $missingRemoteMessage } else { throw $missingRemoteMessage } | |
| } | |
| $changes = & git status --porcelain | |
| if ([string]::IsNullOrWhiteSpace(($changes -join ''))) { | |
| Write-Host 'Nothing to deploy - working tree is clean.' -ForegroundColor Yellow | |
| return | |
| } | |
| if (-not $Message) { | |
| $upstreamJsonPath = Join-Path $repoRoot 'UPSTREAM.json' | |
| if (Test-Path -LiteralPath $upstreamJsonPath) { | |
| $u = Get-Content -LiteralPath $upstreamJsonPath -Raw | ConvertFrom-Json | |
| $short = if ($u.commit.Length -ge 7) { $u.commit.Substring(0, 7) } else { $u.commit } | |
| $Message = "chore: sync simpledocreview @ $short" | |
| } | |
| else { | |
| $Message = 'chore: sync simpledocreview' | |
| } | |
| } | |
| if ($DryRun) { | |
| Write-Host '--- dry run, nothing committed or pushed ---' -ForegroundColor Yellow | |
| Write-Host "Would commit: $Message" | |
| Write-Host "Would push to: $Remote$(if ($AlsoPushOrigin) { ' and origin' })" | |
| Write-Host '' | |
| $changed = (& git status --porcelain).Count | |
| Write-Host "$changed path(s) changed. Summary by top-level entry:" | |
| & git status --porcelain | | |
| ForEach-Object { ($_.Substring(3) -split '[/\\]')[0].Trim('"') } | | |
| Group-Object | | |
| Sort-Object -Property Count -Descending | | |
| ForEach-Object { Write-Host (" {0,5} {1}" -f $_.Count, $_.Name) } | |
| return | |
| } | |
| & git add -A | |
| if ($LASTEXITCODE -ne 0) { throw 'git add failed' } | |
| & git commit -m $Message | |
| if ($LASTEXITCODE -ne 0) { throw 'git commit failed' } | |
| $branch = (& git rev-parse --abbrev-ref HEAD).Trim() | |
| Write-Host '' | |
| Write-Host "Pushing $branch -> $Remote" -ForegroundColor Cyan | |
| & git push $Remote $branch | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "Push to '$Remote' failed. If the Space has commits this repo lacks, run: git pull --rebase $Remote $branch" | |
| } | |
| if ($AlsoPushOrigin) { | |
| Write-Host "Pushing $branch -> origin" -ForegroundColor Cyan | |
| & git push origin $branch | |
| if ($LASTEXITCODE -ne 0) { throw 'Push to origin failed.' } | |
| } | |
| Write-Host '' | |
| Write-Host 'Deployed. A Static Space serves files directly, so the update is live' -ForegroundColor Green | |
| Write-Host 'as soon as the push lands - no build wait.' -ForegroundColor Green | |
| } | |
| finally { Pop-Location } | |