Eric Putnam
Claude Opus 5 (1M context)
feat: deploy DocEditorPlayground as a static Hugging Face Space
8a8c5bb
Raw History Blame Contribute Delete
5.45 kB
<#
.SYNOPSIS
Sync upstream, build the static site, commit, and push to Hugging Face.
.DESCRIPTION
The one command to run after updating DocEditorPlayground:
.\scripts\deploy.ps1
It re-mirrors app/ from the local upstream checkout, builds the static export
into the repository root, commits with the upstream version and 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.
.PARAMETER UpstreamPath
Local DocEditorPlayground checkout. Defaults to C:\dev\DocEditorPlayground.
.PARAMETER Message
Commit message. Defaults to "chore: sync doceditorplayground v<version> @ <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; commit and push the static output already at the repo root.
.PARAMETER AllowDirty
Pass through to sync-upstream.ps1: allow a dirty upstream working tree.
.PARAMETER Clean
Pass through to build-static.ps1: discard .build first, including node_modules.
.PARAMETER DryRun
Sync and build, show what would be committed, but do not commit or push.
.EXAMPLE
.\scripts\deploy.ps1
.EXAMPLE
.\scripts\deploy.ps1 -Message "feat: add markdown export" -AlsoPushOrigin
#>
[CmdletBinding()]
param(
[string] $UpstreamPath = 'C:\dev\DocEditorPlayground',
[string] $Message,
[string] $Remote = 'hf',
[switch] $AlsoPushOrigin,
[switch] $SkipSync,
[switch] $SkipBuild,
[switch] $AllowDirty,
[switch] $Clean,
[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) {
$buildArgs = @{}
if ($Clean) { $buildArgs['Clean'] = $true }
& (Join-Path $PSScriptRoot 'build-static.ps1') @buildArgs
Write-Host ''
}
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 doceditorplayground v$($u.appVersion) @ $short"
}
else {
$Message = 'chore: sync doceditorplayground'
}
}
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 ''
# Summarize rather than list: a rebuild touches hundreds of hashed chunks.
$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 }