param( [string]$Remote = "git@gitea.itworx.tech:Jens/ForgeFlow.git", [string]$Branch = "main" ) $ErrorActionPreference = "Stop" $source = $PSScriptRoot $manifest = Get-Content (Join-Path $source "package.json") -Raw | ConvertFrom-Json if ($manifest.name -ne "forgeflow") { throw "Run this script from an extracted ForgeFlow source release." } $version = [string]$manifest.version $temp = Join-Path ([IO.Path]::GetTempPath()) ("forgeflow-publish-" + [guid]::NewGuid().ToString("N")) $clone = Join-Path $temp "ForgeFlow" try { Write-Host "Validating ForgeFlow $version before publishing..." -ForegroundColor Cyan Push-Location $source try { & cmd.exe /d /s /c "npm install --no-audit --no-fund" if ($LASTEXITCODE -ne 0) { throw "npm install failed." } & cmd.exe /d /s /c "npm run check" if ($LASTEXITCODE -ne 0) { throw "ForgeFlow quality gate failed." } } finally { Pop-Location } New-Item -ItemType Directory -Force -Path $temp | Out-Null Write-Host "Cloning $Remote..." -ForegroundColor Cyan & git clone --branch $Branch --single-branch $Remote $clone if ($LASTEXITCODE -ne 0) { throw "Could not clone the ForgeFlow update repository." } & robocopy.exe $source $clone /MIR /R:2 /W:1 /NFL /NDL /NJH /NJS /NP /XD .git node_modules dist /XF *.zip *.sha256 if ($LASTEXITCODE -gt 7) { throw "Robocopy failed with exit code $LASTEXITCODE." } Push-Location $clone try { & git add -A $changes = & git status --porcelain if (-not $changes) { Write-Host "Gitea already contains ForgeFlow $version; nothing to publish." -ForegroundColor Yellow exit 0 } & git commit -m "Release ForgeFlow $version" if ($LASTEXITCODE -ne 0) { throw "Could not create the release commit." } & git push origin $Branch if ($LASTEXITCODE -ne 0) { throw "Could not push ForgeFlow $version to Gitea." } Write-Host "ForgeFlow $version is now available on Gitea for the built-in updater." -ForegroundColor Green } finally { Pop-Location } } finally { Remove-Item -LiteralPath $temp -Recurse -Force -ErrorAction SilentlyContinue }