fix(renovate): authenticate git with a bearer header and fail the job on repository errors #21
No files matched your search
@@ -50,16 +50,55 @@ jobs:
|
|||||||
RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1/
|
RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1/
|
||||||
RENOVATE_REPOSITORIES: ${{ github.repository }}
|
RENOVATE_REPOSITORIES: ${{ github.repository }}
|
||||||
RENOVATE_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
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]>"
|
RENOVATE_GIT_AUTHOR: "Renovate Bot <[email protected]>"
|
||||||
# postUpgradeTasks may run exactly this one command (anchored, no wildcard); the JSON
|
# postUpgradeTasks may run exactly this one command (anchored, no wildcard); the JSON
|
||||||
# string holds a regex, hence the doubled backslash.
|
# string holds a regex, hence the doubled backslash.
|
||||||
RENOVATE_ALLOWED_COMMANDS: '["^python3 scripts/bump_image_versions\\.py origin/main$"]'
|
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' }}
|
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
|
# 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).
|
# 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' }}
|
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run != 'false' && 'true' || 'false' }}
|
||||||
run: |
|
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
|
if [ "$DRY_RUN" = "true" ]; then
|
||||||
export RENOVATE_DRY_RUN=full
|
export RENOVATE_DRY_RUN=full
|
||||||
fi
|
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"
|
||||||
@@ -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.
|
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;
|
- **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
|
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
|
- **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
|
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
|
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
|
LIVE run proves the writes: (1) that the job token can push a branch and open a PR. Git auth: Renovate
|
||||||
token in the clone URL, while `lint.yml` uses an http extraheader, so basic auth with the job token is
|
puts the token in the clone URL, which git drops on a redirect (dry run 2439 failed so: `could not read
|
||||||
unproven; a fallback is to set `GIT_CONFIG_COUNT`/`GIT_CONFIG_KEY_0`/`GIT_CONFIG_VALUE_0` for the same
|
Username`). `renovate.yml` therefore writes a global git config `http.<server>/.extraheader`
|
||||||
extraheader. (2) That PRs opened with the job token trigger the PR workflows: Gitea, like GitHub, may not
|
(`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`
|
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
|
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
|
with a user token held as a repo secret from a Kamino-only user, or have `renovate.yml` dispatch lint
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@
|
|||||||
- `renovate.json` configures dependency bumps (minor and patch automerge, majors by hand). Renovate
|
- `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
|
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
|
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
|
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
|
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
|
(open item, see CLAUDE.md); until then they may need a manual lint run. Pull requests from `renovate/` branches must pass
|
||||||
|
|||||||
Reference in new issue
Block a user