fix(renovate): authenticate git with a bearer header and fail the job on repository errors #21

Merged
Defame1297 merged 1 commits from fix/renovate-git-auth into main 2026-10-26 08:45:26 +00:00
3 changed files with 50 additions and 7 deletions

No files matched your search

+40 -1
View File
@@ -50,16 +50,55 @@ jobs:
RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1/
RENOVATE_REPOSITORIES: ${{ github.repository }}
RENOVATE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Git auth: see the run block. The host the header is scoped to.
GIT_HOST_URL: ${{ github.server_url }}/
RENOVATE_GIT_AUTHOR: "Renovate Bot <[email protected]>"
# postUpgradeTasks may run exactly this one command (anchored, no wildcard); the JSON
# string holds a regex, hence the doubled backslash.
RENOVATE_ALLOWED_COMMANDS: '["^python3 scripts/bump_image_versions\\.py origin/main$"]'
# Renovate exits 0 when a repository run fails (e.g. the clone): with this it exits with
# an error-specific code instead (7 for an external host error such as a failed clone).
RENOVATE_EXIT_CODE_FOR_ERRORS: "true"
# The JSON report is checked after the run (see below).
RENOVATE_REPORT_TYPE: file
LOG_LEVEL: ${{ github.event_name == 'workflow_dispatch' && 'debug' || 'info' }}
# Fail safe: only the schedule is live. A manual dispatch is a dry run unless the input is
# exactly the string "false" (an empty input from an API or CLI dispatch stays a dry run).
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run != 'false' && 'true' || 'false' }}
run: |
# Git over HTTPS with the job token. Renovate's own rewrite puts the token in the URL
# (https://<token>@host/...), which git drops when the server redirects, and Gitea
# redirected the clone (dry run 2439). The header is sent on every request to the host,
# as lint.yml does. Renovate does not pass GIT_CONFIG_* from its environment to git
# (only an allowlist, util/exec/env.js), but it does pass HOME, so a global git config
# is the path that reaches its git children. The token is read from the environment.
git config --global "http.${GIT_HOST_URL}.extraheader" "AUTHORIZATION: bearer ${RENOVATE_TOKEN}"
report="${RUNNER_TEMP:-/tmp}/renovate-report.json"
rm -f "$report"
export RENOVATE_REPORT_PATH="$report"
if [ "$DRY_RUN" = "true" ]; then
export RENOVATE_DRY_RUN=full
fi
renovate
rc=0
renovate || rc=$?
if [ "$rc" -ne 0 ]; then
echo "::error::Renovate exited with code $rc"
exit "$rc"
fi
# Fail on a missing or unreadable report and on any ERROR (50) or FATAL (60) problem,
# global or per repository. Warnings (40) do not fail the job.
python3 -I -c '
import json, sys
try:
with open(sys.argv[1], encoding="utf-8") as handle:
report = json.load(handle)
except (OSError, ValueError) as err:
sys.exit("::error::no readable Renovate report: " + str(err))
problems = list(report.get("problems", []))
for repo in report.get("repositories", {}).values():
problems.extend(repo.get("problems", []))
bad = [p for p in problems if p.get("level", 0) >= 50]
for p in bad:
print("::error::Renovate problem: " + str(p.get("msg", "")))
sys.exit(1 if bad else 0)
' "$report"
+9 -5
View File
@@ -103,14 +103,18 @@ protection, or create tags: those are the operator's.
unauthenticated (no `RENOVATE_GITHUB_COM_TOKEN` exists) and may hit rate limits: best effort.
- **Dry run:** Actions > Renovate > Run workflow with `dry_run=true` (the default for a manual run;
sets `RENOVATE_DRY_RUN=full`, `LOG_LEVEL=debug`). Read the debug log: no branch or PR is created. The
schedule runs live.
schedule runs live. The job fails (it used to stay green) when Renovate exits non-zero
(`RENOVATE_EXIT_CODE_FOR_ERRORS`, 7 for a failed clone) or when the JSON report
(`RENOVATE_REPORT_TYPE=file`) is missing or holds an ERROR or FATAL problem; warnings do not fail it.
A first good dry run shows a clone (no `external-host-error`, no `could not read Username`).
- **Open item: the first live run (do not enable automerge for bot PRs until one has shown it gets Lint and
Build).** The dry run proves the READS (lookups, config, branch plan) and, from the Renovate 44.161.0
source (confirm by the log line for the post-upgrade task), also runs `postUpgradeTasks`. Only the first
LIVE run proves the writes: (1) that the job token can push a branch and open a PR. Renovate puts the
token in the clone URL, while `lint.yml` uses an http extraheader, so basic auth with the job token is
unproven; a fallback is to set `GIT_CONFIG_COUNT`/`GIT_CONFIG_KEY_0`/`GIT_CONFIG_VALUE_0` for the same
extraheader. (2) That PRs opened with the job token trigger the PR workflows: Gitea, like GitHub, may not
LIVE run proves the writes: (1) that the job token can push a branch and open a PR. Git auth: Renovate
puts the token in the clone URL, which git drops on a redirect (dry run 2439 failed so: `could not read
Username`). `renovate.yml` therefore writes a global git config `http.<server>/.extraheader`
(`AUTHORIZATION: bearer <job token>`, like `lint.yml`); Renovate does not pass `GIT_CONFIG_*` from its
environment to git but does pass `HOME`. Unproven until a run clones. (2) That PRs opened with the job token trigger the PR workflows: Gitea, like GitHub, may not
start workflows for events created by the job token, in which case the required `Lint` and `Build`
checks never run and automerge cannot work. If so, the decision is the operator's: either push the PR
with a user token held as a repo secret from a Kamino-only user, or have `renovate.yml` dispatch lint
+1 -1
View File
@@ -36,7 +36,7 @@
- `renovate.json` configures dependency bumps (minor and patch automerge, majors by hand). Renovate
runs for this repository in `.gitea/workflows/renovate.yml` (daily cron on the Collection's own
runner, with the workflow's job token; no cluster code involved). To dry-run after changing the
config: Actions > Renovate > Run workflow with `dry_run=true`, then read the debug log. The dry run
config: Actions > Renovate > Run workflow with `dry_run=true`, then read the debug log (the job fails on a failed clone or an ERROR problem). The dry run
proves reads (and runs the post-upgrade task); whether the job token can push and open a pull
request, and whether such pull requests start the PR workflows, only the first live run shows
(open item, see CLAUDE.md); until then they may need a manual lint run. Pull requests from `renovate/` branches must pass