fix(renovate): authenticate git with a bearer header and fail the job on repository errors
Renovate puts the job token in the clone URL, which git drops when the server redirects (dry run 2439: could not read Username). Write a global git http.extraheader like lint.yml does. Renovate exits 0 on a repository failure: set exitCodeForErrors and check the JSON report for a missing file or ERROR/FATAL problems. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
a7ea0e0473
commit
7e32ad5ac6
3 files changed
+50
-7
No files matched your search
@@ -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"
|
||||
Reference in new issue
Block a user