Commit 1dea9202 authored by xuwang's avatar xuwang
Browse files

feat(renovate): renovate-admin-update — build admin repo list from repos.txt



Add `make renovate-admin-update` (renovate-admin-update.sh) to regenerate the
RENOVATE_ADMIN_CONFIG `repositories` list from SUB_REPOS_FILE (repos.txt),
including only repos that contain Terraform (*.tf) or Docker (Dockerfile*) files.
Other admin-config keys are preserved. An explicit, diffable, hand-editable list
in place of Renovate autodiscover.

Changelog: added
Co-Authored-By: default avatarClaude Opus 4.8 <noreply@anthropic.com>
parent c362da58
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -170,11 +170,12 @@ repos you own, with **no instance-wide scan**. Pair with `onboarding: false` +
}
```

A natural source for that list is the project's `repos.txt`:

```bash
grep -vE '^\s*#|^\s*$' repos.txt | awk '{print $2}' | sed -E 's#^git@[^:]+:##; s#\.git$##'
```
For projects that track sub-repos in `repos.txt`, **`make renovate-admin-update`**
regenerates the `repositories` list automatically — including only repos that
actually contain Terraform (`*.tf`) or Docker (`Dockerfile*`) files (kube/puppet/
docs are skipped) — while preserving the other keys. Edit `repos.txt` (or the
generated file) and re-run to change the set. It's the reviewable alternative to
autodiscover: the scanned set is an explicit, diffable list.

**Autodiscover** — set `"autodiscover": true` (+ optional `autodiscoverFilter`) in
the admin config, or omit the file and use `RENOVATE_AUTODISCOVER_FILTER`. Note
+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@ RENOVATE_AUTODISCOVER_FILTER ?=
RENOVATE_ADMIN_CONFIG        ?= renovate-admin.json
export RENOVATE_AUTODISCOVER_FILTER RENOVATE_ADMIN_CONFIG

.PHONY: renovate-admin-update
renovate-admin-update: ## regenerate ${RENOVATE_ADMIN_CONFIG} repos from ${SUB_REPOS_FILE} (tf/docker only)
	@renovate-admin-update.sh

.PHONY: renovate-admin-dryrun
renovate-admin-dryrun: renovate-check ## autodiscover dry-run across accessible repos (read_api)
	@renovate-run.sh autodiscover-dryrun
+69 −0
Original line number Diff line number Diff line
#!/bin/bash -eu
#
# Regenerate the `repositories` list in a Renovate admin config from a sub-repos
# file (repos.txt), including only repos that contain Renovate-relevant manager
# files — Terraform (*.tf) or Docker (Dockerfile*). Other repos (kube manifests,
# puppet, docs, …) are left out. All OTHER keys in the admin config (onboarding,
# requireConfig, …) are preserved; if the file doesn't exist it's created with
# safe defaults (onboarding=false, requireConfig=required).
#
# This is the deliberate, reviewable alternative to Renovate autodiscover: the
# scanned set is an explicit list you can see, diff, and hand-edit. Edit
# repos.txt (or the generated file) and re-run to change it.
#
# Env:
#   SUB_REPOS_FILE         repos list (default: repos.txt)   [name  git-url ...]
#   SUB_REPOS_DIR          clone dir for the repos (default: sub-projects)
#   RENOVATE_ADMIN_CONFIG  admin config to update (default: renovate-admin.json)

THIS_DIR=$(cd "$(dirname "$0")" && pwd)
source "${THIS_DIR}/functions.sh"

REPOS_FILE="${SUB_REPOS_FILE:-repos.txt}"
REPOS_DIR="${SUB_REPOS_DIR:-sub-projects}"
ADMIN="${RENOVATE_ADMIN_CONFIG:-renovate-admin.json}"

[ -f "${REPOS_FILE}" ] || err "Sub-repos file not found: ${REPOS_FILE}"
command -v jq >/dev/null 2>&1 || err "jq is required."

repos=()
skipped=()
while read -r name url _rest; do
    case "${name}" in ''|\#*) continue ;; esac      # skip blank / comment lines
    [ -n "${url:-}" ] || continue
    proj="$(echo "${url}" | sed -E 's#^[a-z]+://##; s#^[^@/]*@##; s#^[^/:]+[:/]##; s#\.git$##')"
    dir="${REPOS_DIR}/${name}"
    if [ ! -d "${dir}" ]; then
        skipped+=("${name} (not cloned)"); continue
    fi
    # Terraform (*.tf, ignoring rendered build/cache dirs) or Docker (Dockerfile*).
    if find "${dir}" \
            \( -path '*/.git/*' -o -path '*/.tf_build/*' -o -path '*/.terraform/*' \) -prune -o \
            \( -name '*.tf' -o -iname 'Dockerfile*' \) -print 2>/dev/null | grep -q .; then
        repos+=("${proj}")
    else
        skipped+=("${name} (no tf/docker files)")
    fi
done < "${REPOS_FILE}"

if [ "${#repos[@]}" -eq 0 ]; then
    arr="[]"
else
    arr="$(printf '%s\n' "${repos[@]}" | sort -u | jq -R . | jq -s .)"
fi

tmp="$(mktemp)"
if [ -f "${ADMIN}" ]; then
    jq --argjson r "${arr}" '.repositories = $r' "${ADMIN}" > "${tmp}"
else
    jq -n --argjson r "${arr}" '{
      "$schema": "https://docs.renovatebot.com/renovate-schema.json",
      repositories: $r,
      onboarding: false,
      requireConfig: "required"
    }' > "${tmp}"
fi
mv "${tmp}" "${ADMIN}"

echo "Updated ${ADMIN}: $(echo "${arr}" | jq 'length') repo(s) (terraform/docker)."
for s in "${skipped[@]+"${skipped[@]}"}"; do echo "  skip: ${s}"; done