From c45f0e927baa82537cac6d0b9b66e5c43b0b58fd Mon Sep 17 00:00:00 2001 From: Demo Date: Sun, 11 Oct 2026 21:44:21 +0200 Subject: [PATCH] Store command.ps1, renovate.json and info.json per run --- script/renovate-update.ps1 | 61 +++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/script/renovate-update.ps1 b/script/renovate-update.ps1 index 24d0da3..db3aea6 100644 --- a/script/renovate-update.ps1 +++ b/script/renovate-update.ps1 @@ -1,5 +1,11 @@ # Renovate run against a Forgejo (started locally via script\forgejo-up.ps1). # Every run creates new branches + PRs with a timestamp: renovate/- +# Everything about the run is stored in reports//: +# command.ps1 the Renovate command that was executed (incl. environment variables) +# renovate.json the Renovate configuration that was used (committed state of main) +# renovate.log console output at debug level +# renovate-report.json Renovate report +# info.json start, end, duration and the created pull requests $endpoint = 'http://localhost:3000' $repo = 'renovate/renovate-test' $tokenFile = Join-Path $PSScriptRoot '.forgejo-token' @@ -11,43 +17,64 @@ try { Invoke-WebRequest "$endpoint/api/healthz" -UseBasicParsing | Out-Null } ca if (-not (Test-Path $tokenFile)) { throw "$tokenFile is missing - run .\script\forgejo-up.ps1 first" } $token = (Get-Content $tokenFile -Raw).Trim() -$now = Get-Date -$ts = $now.ToString('yyyy-MM-dd-HH-mm-ss-fff') # for the branch name (no ':' or spaces allowed) -$prTimestamp = $now.ToString('yyyy-MM-dd HH:mm:ss.fff') # for the PR title +$startedAt = Get-Date +$ts = $startedAt.ToString('yyyy-MM-dd-HH-mm-ss-fff') # for the branch name (no ':' or spaces allowed) +$prTimestamp = $startedAt.ToString('yyyy-MM-dd HH:mm:ss.fff') # for the PR title $gitUrl = $endpoint -replace '://', "://renovate:$token@" $gitUrl = "$gitUrl/$repo.git" -# Report and debug log of this run: reports// -$outDir = Join-Path (Join-Path (Join-Path $PSScriptRoot '..') 'reports') $ts -New-Item -ItemType Directory -Force -Path $outDir | Out-Null Push-Location (Join-Path $PSScriptRoot '..') # repository root +$outDir = "reports/$ts" +New-Item -ItemType Directory -Force -Path $outDir | Out-Null # 1. Push the local state of main to Forgejo (without credential helper, the credentials are in the URL) git -c credential.helper= push $gitUrl main:main if ($LASTEXITCODE -ne 0) { Pop-Location; throw 'git push failed' } +# Renovate reads the configuration from the pushed main, so store exactly that version +git show main:renovate.json --output="$outDir/renovate.json" -# 2. Run Renovate. Branch prefix with timestamp => every run creates new branches + PRs. +# 2. Write the Renovate command to command.ps1 and run it. +# Branch prefix with timestamp => every run creates new branches + PRs. # branch-prefix-old prevents Renovate from reusing branches of previous runs. # Via environment variables: the commit author, the timestamp in the PR title (commitMessageSuffix has no CLI flag) -# and the debug log file (console output in the same format, but at debug level). +# and the debug log file. LOG_FILE is relative on purpose: Renovate lowercases it, an absolute path would break +# on case-sensitive file systems. +$command = @' +# Renovate command of run __TS__ - run it from the repository root to repeat it $env:RENOVATE_GIT_AUTHOR = 'Renovate Bot ' -$env:RENOVATE_COMMIT_MESSAGE_SUFFIX = $prTimestamp -# Relative path on purpose: Renovate lowercases LOG_FILE, an absolute path would break on case-sensitive file systems -$env:LOG_FILE = "reports/$ts/renovate.log" +$env:RENOVATE_COMMIT_MESSAGE_SUFFIX = '__PR_TIMESTAMP__' +$env:LOG_FILE = 'reports/__TS__/renovate.log' $env:LOG_FILE_LEVEL = 'debug' $env:LOG_FILE_FORMAT = 'pretty' npx --yes renovate@44.149.3 ` - --platform=forgejo --endpoint="$endpoint/api/v1" --token=$token ` - --branch-prefix="renovate/$ts-" --branch-prefix-old="renovate/$ts-" ` - --report-type=file --report-path="$(Join-Path $outDir 'renovate-report.json')" ` - $repo + --platform=forgejo --endpoint=__ENDPOINT__/api/v1 --token=$((Get-Content script/.forgejo-token -Raw).Trim()) ` + --branch-prefix=renovate/__TS__- --branch-prefix-old=renovate/__TS__- ` + --report-type=file --report-path=reports/__TS__/renovate-report.json ` + __REPO__ +'@ +$command = $command.Replace('__TS__', $ts).Replace('__PR_TIMESTAMP__', $prTimestamp).Replace('__ENDPOINT__', $endpoint).Replace('__REPO__', $repo) +Set-Content -Path "$outDir/command.ps1" -Value $command +& "./$outDir/command.ps1" $renovateExitCode = $LASTEXITCODE Remove-Item Env:RENOVATE_GIT_AUTHOR, Env:RENOVATE_COMMIT_MESSAGE_SUFFIX, Env:LOG_FILE, Env:LOG_FILE_LEVEL, Env:LOG_FILE_FORMAT -if ($renovateExitCode -ne 0) { Pop-Location; throw "Renovate failed - see $outDir" } # 3. Fetch the Renovate branches into the local repository (as forgejo/renovate/...) git -c credential.helper= fetch -q --prune $gitUrl '+refs/heads/renovate/*:refs/remotes/forgejo/renovate/*' + +# 4. info.json: start, end, duration and the pull requests created by this run +$pulls = Invoke-RestMethod "$endpoint/api/v1/repos/$repo/pulls?state=open&limit=50" -Headers @{ Authorization = "token $token" } +$finishedAt = Get-Date +[ordered]@{ + startedAt = $startedAt.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz') + finishedAt = $finishedAt.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz') + durationSeconds = [math]::Round(($finishedAt - $startedAt).TotalSeconds, 1) + pullRequests = @($pulls | Where-Object { $_.head.ref -like "renovate/$ts-*" } | ForEach-Object { + [ordered]@{ number = $_.number; title = $_.title; branch = $_.head.ref; url = $_.html_url } + }) +} | ConvertTo-Json -Depth 5 | Set-Content -Path "$outDir/info.json" + +if ($renovateExitCode -ne 0) { Pop-Location; throw "Renovate failed - see $outDir" } Write-Host "`nNew branches:" -ForegroundColor Cyan git branch -r --list "forgejo/renovate/$ts-*" Write-Host "PRs: $endpoint/$repo/pulls (login: renovate / renovate)" -Write-Host "Report and debug log: $outDir" +Write-Host "Run details: $outDir" Pop-Location