diff --git a/.gitea/workflows/renovate.yml b/.gitea/workflows/renovate.yml index 7cab213..cee1964 100644 --- a/.gitea/workflows/renovate.yml +++ b/.gitea/workflows/renovate.yml @@ -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 " # 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://@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" diff --git a/CLAUDE.md b/CLAUDE.md index 6cdcbe4..903a04f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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./.extraheader` + (`AUTHORIZATION: bearer `, 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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c37362..feb1483 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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