Move script, example-configurations and results (formerly reports) into renovate/
This commit is contained in:
1 parent
c45f0e927b
commit
2267b21544
14 files changed
+83
-52
No files matched your search
@@ -0,0 +1,80 @@
|
||||
# Renovate run against a Forgejo (started locally via renovate\script\forgejo-up.ps1).
|
||||
# Every run creates new branches + PRs with a timestamp: renovate/<yyyy-MM-dd-HH-mm-ss-fff>-<group>
|
||||
# Everything about the run is stored in renovate/results/<timestamp>/:
|
||||
# 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'
|
||||
|
||||
# Renovate requires Node.js >= 24.11
|
||||
if ([version](node -v).TrimStart('v') -lt [version]'24.11.0') { throw "Renovate requires Node.js >= 24.11, found: $(node -v). E.g.: volta install node@24" }
|
||||
# Forgejo must be running and a token must exist
|
||||
try { Invoke-WebRequest "$endpoint/api/healthz" -UseBasicParsing | Out-Null } catch { throw "Forgejo is not reachable at $endpoint - run .\renovate\script\forgejo-up.ps1 first" }
|
||||
if (-not (Test-Path $tokenFile)) { throw "$tokenFile is missing - run .\renovate\script\forgejo-up.ps1 first" }
|
||||
|
||||
$token = (Get-Content $tokenFile -Raw).Trim()
|
||||
$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"
|
||||
Push-Location (Join-Path $PSScriptRoot '../..') # repository root
|
||||
$outDir = "renovate/results/$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 | Set-Content -Path "$outDir/renovate.json"
|
||||
|
||||
# 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. 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 <renovate@localhost>'
|
||||
$env:RENOVATE_COMMIT_MESSAGE_SUFFIX = '__PR_TIMESTAMP__'
|
||||
$env:LOG_FILE = 'renovate/results/__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=$((Get-Content renovate/script/.forgejo-token -Raw).Trim()) `
|
||||
--branch-prefix=renovate/__TS__- --branch-prefix-old=renovate/__TS__- `
|
||||
--report-type=file --report-path=renovate/results/__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
|
||||
|
||||
# 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 "Run details: $outDir"
|
||||
Pop-Location
|
||||
Reference in new issue
Block a user