|
|
| param(
|
| [string]$Space = "li2895/grok2api",
|
| [string]$Token = $env:HF_TOKEN,
|
| [string]$Branch = "main"
|
| )
|
|
|
| $ErrorActionPreference = "Stop"
|
| Set-Location (Split-Path -Parent $PSScriptRoot)
|
|
|
| if (-not $Token) {
|
| Write-Host "Missing HF token. Run first: `$env:HF_TOKEN = 'hf_xxx'" -ForegroundColor Red
|
| Write-Host "If old token leaked, revoke it at https://huggingface.co/settings/tokens" -ForegroundColor Yellow
|
| exit 1
|
| }
|
|
|
| $work = $null
|
| try {
|
| $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
| $work = Join-Path $env:TEMP "grok2api-hf-push-$stamp"
|
| if (Test-Path $work) { Remove-Item -Recurse -Force $work }
|
| New-Item -ItemType Directory -Path $work | Out-Null
|
|
|
| Write-Host "copying project to temp clean tree..."
|
| $null = robocopy . $work /E /XD .git .gocache frontend\node_modules frontend\dist data .tmp-hf-app .tmp-hf-data grok2api-7-21 grok-free-register-main .hf-adapt-backup .agents .codex /XF grok2api.png *.localbak /NFL /NDL /NJH /NJS /nc /ns /np
|
| if ($LASTEXITCODE -ge 8) { throw "robocopy failed with code $LASTEXITCODE" }
|
|
|
| $binPaths = @(
|
| "frontend\public\grok2api.png",
|
| "frontend\public\sponner\deeix-chat_deeix-ai.png",
|
| "frontend\public\sponner\rightcode.jpg"
|
| )
|
| foreach ($rel in $binPaths) {
|
| $p = Join-Path $work $rel
|
| if (Test-Path $p) {
|
| Remove-Item -Force $p
|
| Write-Host "removed binary from push tree: $rel"
|
| }
|
| }
|
|
|
| $hfReadme = Join-Path $work "README.hf.md"
|
| $spaceReadme = Join-Path $work "README.md"
|
| if (Test-Path $hfReadme) {
|
| Copy-Item -Force $hfReadme $spaceReadme
|
| Write-Host "installed README.hf.md as Space README.md"
|
| } else {
|
| throw "missing README.hf.md (HF Spaces frontmatter)"
|
| }
|
|
|
| if (-not (Test-Path (Join-Path $work "VERSION"))) {
|
| Set-Content -Path (Join-Path $work "VERSION") -Value "v3.0.7" -NoNewline
|
| }
|
|
|
| Push-Location $work
|
| git init | Out-Null
|
| git checkout -b $Branch | Out-Null
|
| git config core.autocrlf false
|
| git add -A
|
| git status --short | Select-Object -First 40
|
| git -c user.email="deploy@local" -c user.name="hf-deploy" commit -m "Deploy Grok2API v3.0.7 to Hugging Face Space" | Out-Null
|
|
|
| $url = "https://li2895:$Token@huggingface.co/spaces/$Space"
|
| Write-Host "Force pushing clean tree to https://huggingface.co/spaces/$Space ..." -ForegroundColor Cyan
|
| git push $url "HEAD:refs/heads/$Branch" --force
|
| if ($LASTEXITCODE -ne 0) { throw "git push failed with code $LASTEXITCODE" }
|
|
|
| Write-Host "SUCCESS" -ForegroundColor Green
|
| Write-Host "Open https://huggingface.co/spaces/$Space"
|
| Write-Host "Version: v3.0.7 | Wait Building -> Running, login admin + BOOTSTRAP_ADMIN_PASSWORD"
|
| Write-Host "Keep JWT_SECRET and CREDENTIAL_ENCRYPTION_KEY unchanged to retain existing accounts."
|
| }
|
| finally {
|
| Pop-Location -ErrorAction SilentlyContinue
|
| if ($work -and (Test-Path $work)) {
|
| Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue
|
| }
|
| } |