Files
renovate-test/script/renovate-update.ps1
T

44 lines
2.6 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Renovate-Lauf gegen ein Forgejo (lokal per script\forgejo-up.ps1 gestartet).
# Jeder Lauf erzeugt einen neuen Branch + PR mit Zeitstempel: renovate/<yyyy-MM-dd-HH-mm-ss-fff>-all
$endpoint = 'http://localhost:3000'
$repo = 'renovate/monorepo'
$tokenFile = Join-Path $PSScriptRoot '.forgejo-token'
# Renovate braucht Node.js >= 24.11
if ([version](node -v).TrimStart('v') -lt [version]'24.11.0') { throw "Renovate braucht Node.js >= 24.11, gefunden: $(node -v). Z. B.: volta install node@24" }
# Forgejo muss laufen und ein Token muss vorhanden sein
try { Invoke-WebRequest "$endpoint/api/healthz" -UseBasicParsing | Out-Null } catch { throw "Forgejo unter $endpoint nicht erreichbar – zuerst .\script\forgejo-up.ps1 ausführen" }
if (-not (Test-Path $tokenFile)) { throw "$tokenFile fehlt – zuerst .\script\forgejo-up.ps1 ausführen" }
$token = (Get-Content $tokenFile -Raw).Trim()
$now = Get-Date
$ts = $now.ToString('yyyy-MM-dd-HH-mm-ss-fff') # für den Branch-Namen (keine ':' oder Leerzeichen erlaubt)
$prTimestamp = $now.ToString('yyyy-MM-dd HH:mm:ss.fff') # für den PR-Titel
$gitUrl = $endpoint -replace '://', "://renovate:$token@"
$gitUrl = "$gitUrl/$repo.git"
Push-Location (Join-Path $PSScriptRoot '..') # Repo-Root
# 1. Lokalen Stand von main nach Forgejo pushen (ohne Credential-Helper, die Zugangsdaten stehen in der URL)
git -c credential.helper= push $gitUrl main:main
if ($LASTEXITCODE -ne 0) { Pop-Location; throw 'git push fehlgeschlagen' }
# 2. Renovate laufen lassen. Branch-Präfix mit Zeitstempel => jeder Lauf erzeugt einen neuen Branch + PR.
# branch-prefix-old verhindert, dass Renovate Branches früherer Läufe wiederverwendet.
# Per Env-Variable: der Commit-Autor und der Zeitstempel im PR-Titel (commitMessageSuffix gibt es nicht als CLI-Flag).
$env:RENOVATE_GIT_AUTHOR = 'Renovate Bot <renovate@localhost>'
$env:RENOVATE_COMMIT_MESSAGE_SUFFIX = $prTimestamp
npx --yes renovate@44.149.3 `
--platform=forgejo --endpoint="$endpoint/api/v1" --token=$token `
--branch-prefix="renovate/$ts-" --branch-prefix-old="renovate/$ts-" `
$repo
$renovateExitCode = $LASTEXITCODE
Remove-Item Env:RENOVATE_GIT_AUTHOR, Env:RENOVATE_COMMIT_MESSAGE_SUFFIX
if ($renovateExitCode -ne 0) { Pop-Location; throw 'Renovate fehlgeschlagen' }
# 3. Renovate-Branches ins lokale Repo holen (als forgejo/renovate/...)
git -c credential.helper= fetch -q --prune $gitUrl '+refs/heads/renovate/*:refs/remotes/forgejo/renovate/*'
Write-Host "`nNeuer Branch:" -ForegroundColor Cyan
git branch -r --list "forgejo/renovate/$ts-*"
Write-Host "PRs: $endpoint/$repo/pulls (Login: renovate / renovate-local-123)"
Pop-Location