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,12 @@
|
||||
# Stops the local Forgejo. With -Purge, the container, the data volume and .forgejo-token are deleted as well.
|
||||
param([switch]$Purge)
|
||||
|
||||
podman stop renovate-forgejo 2>$null | Out-Null
|
||||
if ($Purge) {
|
||||
podman rm -f renovate-forgejo 2>$null | Out-Null
|
||||
podman volume rm -f renovate-forgejo-data 2>$null | Out-Null
|
||||
Remove-Item (Join-Path $PSScriptRoot '.forgejo-token') -ErrorAction SilentlyContinue
|
||||
Write-Host 'Forgejo removed including all data' -ForegroundColor Cyan
|
||||
} else {
|
||||
Write-Host 'Forgejo stopped (data is kept; use -Purge to delete it)' -ForegroundColor Cyan
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# Resets the local Forgejo completely: delete everything (including repos, PRs, tokens) and start fresh.
|
||||
& (Join-Path $PSScriptRoot 'forgejo-down.ps1') -Purge
|
||||
& (Join-Path $PSScriptRoot 'forgejo-up.ps1')
|
||||
@@ -0,0 +1,35 @@
|
||||
# Starts a local Forgejo (Git server) in Podman, creates the bot user "renovate"
|
||||
# and stores a fresh access token in .forgejo-token (read by renovate-update.ps1).
|
||||
$ts = Get-Date -Format 'yyyy-MM-dd-HH-mm-ss-fff'
|
||||
$tokenFile = Join-Path $PSScriptRoot '.forgejo-token'
|
||||
$username = 'renovate'
|
||||
$password = 'renovate'
|
||||
|
||||
# 1. Start the container - create it on first run.
|
||||
# ENABLE_PUSH_CREATE_USER: a repository is created automatically on the first "git push".
|
||||
podman start renovate-forgejo 2>$null | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
podman run -d --name renovate-forgejo -p 3000:3000 -v renovate-forgejo-data:/data `
|
||||
-e FORGEJO__security__INSTALL_LOCK=true `
|
||||
-e FORGEJO__repository__ENABLE_PUSH_CREATE_USER=true `
|
||||
-e FORGEJO__repository__DEFAULT_BRANCH=main `
|
||||
codeberg.org/forgejo/forgejo:11 | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not start the Forgejo container' }
|
||||
}
|
||||
Write-Host 'Waiting for Forgejo ...'
|
||||
do {
|
||||
Start-Sleep -Seconds 1
|
||||
try { $ready = (Invoke-WebRequest 'http://localhost:3000/api/healthz' -UseBasicParsing).StatusCode -eq 200 } catch { $ready = $false }
|
||||
} until ($ready)
|
||||
|
||||
# 2. Create the bot user (ignore the error if it already exists) and generate a fresh access token
|
||||
podman exec -u git renovate-forgejo forgejo admin user create --admin --username $username `
|
||||
--password $password --email renovate@localhost --must-change-password=false 2>$null | Out-Null
|
||||
$token = podman exec -u git renovate-forgejo forgejo admin user generate-access-token `
|
||||
--username $username --token-name "renovate-$ts" --scopes all --raw
|
||||
Set-Content -Path $tokenFile -Value $token -NoNewline
|
||||
|
||||
Write-Host "`nForgejo is running: http://localhost:3000" -ForegroundColor Cyan
|
||||
Write-Host " Username: $username"
|
||||
Write-Host " Password: $password"
|
||||
Write-Host " Token saved to $tokenFile"
|
||||
@@ -0,0 +1,55 @@
|
||||
# Check only: Renovate runs with the "local" platform directly on this repository
|
||||
# and changes nothing. Found updates are read from the JSON report and printed.
|
||||
# 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 (working directory)
|
||||
# renovate.log console output at debug level
|
||||
# renovate-report.json Renovate report
|
||||
# info.json start, end and duration
|
||||
# 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" }
|
||||
|
||||
$startedAt = Get-Date
|
||||
$ts = $startedAt.ToString('yyyy-MM-dd-HH-mm-ss-fff')
|
||||
Push-Location (Join-Path $PSScriptRoot '../..') # repository root
|
||||
$outDir = "renovate/results/$ts"
|
||||
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
|
||||
# The local platform reads the working directory, so store the renovate.json from there
|
||||
Copy-Item renovate.json "$outDir/renovate.json"
|
||||
|
||||
# Write the Renovate command to command.ps1 and run it.
|
||||
# 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:LOG_FILE = 'renovate/results/__TS__/renovate.log'
|
||||
$env:LOG_FILE_LEVEL = 'debug'
|
||||
$env:LOG_FILE_FORMAT = 'pretty'
|
||||
npx --yes renovate@44.149.3 `
|
||||
--platform=local --dry-run=lookup `
|
||||
--report-type=file --report-path=renovate/results/__TS__/renovate-report.json
|
||||
'@
|
||||
$command = $command.Replace('__TS__', $ts)
|
||||
Set-Content -Path "$outDir/command.ps1" -Value $command
|
||||
& "./$outDir/command.ps1"
|
||||
Remove-Item Env:LOG_FILE, Env:LOG_FILE_LEVEL, Env:LOG_FILE_FORMAT
|
||||
|
||||
$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)
|
||||
} | ConvertTo-Json | Set-Content -Path "$outDir/info.json"
|
||||
|
||||
Write-Host "`nAvailable updates:" -ForegroundColor Cyan
|
||||
$packageFiles = (Get-Content "$outDir/renovate-report.json" -Raw -Encoding UTF8 | ConvertFrom-Json).repositories.local.packageFiles
|
||||
foreach ($manager in $packageFiles.PSObject.Properties) {
|
||||
foreach ($file in $manager.Value) {
|
||||
foreach ($dep in $file.deps) {
|
||||
foreach ($update in $dep.updates) {
|
||||
Write-Host " [$($manager.Name)] $($file.packageFile): $($dep.depName) $($dep.currentValue) -> $($update.newValue) ($($update.updateType))"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Host "Run details: $outDir"
|
||||
Pop-Location
|
||||
@@ -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