mirror of
https://github.com/dsx-ai-factory/nvke.git
synced 2026-12-07 04:35:58 +08:00
* build: give every tool pin a single owner in make/tool-versions.mk make/tool-versions.mk already owned most of the repository's pins, but nine tools still declared their own where they were used, and two of those were declared twice: controller-tools v0.20.1 in both cluster-api-provider-provisioned/ and management-engine/, and the TPM plugin 1.9.0 in both the spire-agent package and the CAPD bundle script. The second pair was held in step by a comment reading 'move them together'. Moved in: addlicense, buf, controller-tools, ginkgo, gofail, gofumpt, goimports, setup-envtest, the envtest Kubernetes version, and the SPIRE and TPM-plugin releases the node .deb wraps. golangci-lint stays in make/golangci.mk, beside the bootstrap logic that consumes it, and is the one recorded exception. prepare-capd-bundles.sh cannot include a makefile, so it now reads the two pins out of make/tool-versions.mk instead of restating them. hack/tool-version-check.sh makes this hold: for every name the owner declares, a literal re-declaration anywhere else in the tree fails with the tool, both values, and both locations. A derivation -- any right-hand side that reads the value from somewhere -- is the wanted shape and passes. Wired into 'make gate' and go-build.yml. The envtest cache key in gofail-e2e.yml now hashes make/tool-versions.mk too, since that is where ENVTEST_K8S_VERSION moved. Signed-off-by: Terry Howe <thowe@nvidia.com> * build: close the tool-pin gaps review found build-image.sh still defaulted SPIRE_AGENT_VERSION and TPM_ATTESTOR_VERSION to literal 1.14.1 / 1.9.0 -- the same two pins this branch centralised, in the sibling of the script it fixed. The checker could not see them: the names differ from the owned ones, and `: "${X:=v}"` is not the `X=` shape it greps. Both readers now share hack/read-tool-version.sh rather than each carrying a copy of the sed. Env overrides still win; the pin is only the default, and an unknown name is a hard error so a rename fails loudly instead of downloading an empty version. The comment this branch deleted from the spire-agent Makefile was the only in-tree pointer to the places nothing can check -- controller/Tiltfile, hack/mirror-bootstrap-images.sh and create-forge-nico-cluster.sh embed the version inside an image tag or an apt package spec. That list now sits above the pin it constrains, split into what the check enforces and what a human still has to move. Also from review: - The checker now reads YAML `NAME: value`, which is how a workflow or a composite action declares a pin. Every current occurrence is a `${{ }}` derivation and still passes; a literal one now fails. - EXEMPT_FILES described golangci.mk as "the one recorded exception", but GOLANGCI_LINT_VERSION is not declared in the owner file, so the check never looks for it. Reworded to what it is: room for the pin to move here later. - Quote the pin count instead of relying on word splitting (SC2086). - Drop the double blank lines the moved declarations left behind. Signed-off-by: Terry Howe <thowe@nvidia.com> * build: route every addlicense pin through ADDLICENSE_VERSION, catch `+=` Review found `controller/Makefile` still invoking `addlicense@v1.1.1` while `agent/Makefile` used the variable. It was five sites, not one: the root `Makefile`, `cli/`, `controller/`, `controller/nico-sim/` and `os-image/` all restated the literal, so moving ADDLICENSE_VERSION into the owner file had converted exactly one of six consumers. `controller/nico-sim/` and `os-image/` did not include the owner file at all, so the variable was empty there -- substituting it without the include would have produced `addlicense@` and a broken target rather than a wrong version. Both now include it. It is assignments only, so neither module's default goal moves. The check could not have caught any of these: a version inside a `go run` module path is not an assignment, the same reason the Tiltfile image tags are listed as unreachable in make/tool-versions.mk. Separately, the check now reads `+=`. Appending to a pin the owner already set yields a two-word value no consumer can use, and it is a second declaration by any reading. Kept `[[:space:]]*` rather than the suggested `[[:space:]]`: the latter requires a space before the operator and would have stopped matching `GINKGO_VERSION?=v1.0.0`, which is the form the check most needs to catch. Signed-off-by: Terry Howe <thowe@nvidia.com> --------- Signed-off-by: Terry Howe <thowe@nvidia.com>
104 lines
4.1 KiB
Bash
Executable File
104 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# make/tool-versions.mk owns every tool pin. This fails when something else in
|
|
# the tree declares one of the same names, which is the only way the two can
|
|
# disagree.
|
|
#
|
|
# Two copies of controller-tools v0.20.1 (cluster-api-provider-provisioned and
|
|
# management-engine) and two of the TPM plugin 1.9.0 (the spire-agent package
|
|
# and the CAPD bundle script) sat in the tree agreeing with each other, held
|
|
# there by a comment reading "move them together". Agreement maintained by
|
|
# whoever remembers is agreement until someone does not: the failure is a green
|
|
# local run and a red CI run, or the reverse, with the version nobody looked at
|
|
# as the cause.
|
|
#
|
|
# Mirroring a pin into a shell script or a workflow is fine -- read it from
|
|
# here, the way controller/hack/ci/prepare-capd-bundles.sh does. Assigning it a
|
|
# second time is what this rejects.
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
OWNER="make/tool-versions.mk"
|
|
[[ -f "${OWNER}" ]] || { echo "ERROR: ${OWNER} is missing" >&2; exit 2; }
|
|
|
|
# golangci-lint has a different owner: make/golangci.mk carries the pin beside
|
|
# the bootstrap logic that consumes it, and is included by every module for
|
|
# exactly that. It is not a hole in this check -- GOLANGCI_LINT_VERSION is not
|
|
# declared in ${OWNER}, so the check never looks for it at all. This exemption
|
|
# exists so that moving the pin here later does not immediately fail on the
|
|
# file that legitimately still defines it.
|
|
EXEMPT_FILES="^make/golangci\.mk$"
|
|
|
|
fail=0
|
|
|
|
names=""
|
|
while IFS= read -r name; do
|
|
names="${names} ${name}"
|
|
done < <(sed -nE 's/^([A-Z][A-Z0-9_]*(_VERSION|_SHA256[A-Z0-9_]*))[[:space:]]*\??=.*/\1/p' "${OWNER}" | sort -u)
|
|
|
|
[[ -n "${names}" ]] || { echo "ERROR: no pins found in ${OWNER}" >&2; exit 2; }
|
|
|
|
owned_value() {
|
|
sed -nE "s/^$1[[:space:]]*\??=[[:space:]]*([^[:space:]#]*).*/\1/p" "${OWNER}" | tail -1
|
|
}
|
|
|
|
for name in ${names}; do
|
|
want="$(owned_value "${name}")"
|
|
while IFS= read -r hit; do
|
|
file="${hit%%:*}"
|
|
rest="${hit#*:}"
|
|
line="${rest%%:*}"
|
|
text="${rest#*:}"
|
|
[[ "${file}" == "${OWNER}" ]] && continue
|
|
[[ "${file}" =~ ${EXEMPT_FILES} ]] && continue
|
|
got="$(printf '%s' "${text}" \
|
|
| sed -E "s/^[[:space:]]*(export[[:space:]]+)?${name}[[:space:]]*([:+?]?=|:)[[:space:]]*//" \
|
|
| tr -d "\"'" | awk '{print $1}')"
|
|
# A derivation is the wanted shape, not a second declaration: a `$`
|
|
# on the right-hand side means the value is being read from somewhere
|
|
# (make, another variable, this file) rather than restated. Only a
|
|
# literal can disagree with the owner, so only a literal is an error.
|
|
# A bare `#` is the rest of a comment, not a value.
|
|
case "${got}" in
|
|
'' | '#'* | *'$'*) continue ;;
|
|
esac
|
|
echo "ERROR: ${file}:${line} declares ${name}=${got}; ${OWNER} declares ${want}" >&2
|
|
fail=1
|
|
done < <({
|
|
# `+=` is in here with the rest: appending to a pin the owner already
|
|
# set produces a two-word value that no consumer can use, and it is a
|
|
# second declaration by any reading.
|
|
git grep -nE "^[[:space:]]*(export[[:space:]]+)?${name}[[:space:]]*[:+?]?=" \
|
|
-- ':(exclude)vendor' ':(exclude)*.md' || true
|
|
# A workflow or composite action declares its pins as `NAME: value`,
|
|
# which is the same second declaration in another syntax. Restricted to
|
|
# YAML, so a makefile target sharing a pin's name is not read as one.
|
|
# Only catches a value on the same line as the key; a pin folded onto
|
|
# the next line is out of reach and is why the comment in ${OWNER}
|
|
# names the places nothing can check.
|
|
git grep -nE "^[[:space:]]*${name}:[[:space:]]*[^[:space:]]" \
|
|
-- '*.yml' '*.yaml' ':(exclude)vendor' || true
|
|
})
|
|
done
|
|
|
|
if (( fail )); then
|
|
cat >&2 <<-MSG
|
|
|
|
${OWNER} is the single owner of these pins. Delete the second declaration
|
|
and include the file:
|
|
|
|
include ../make/tool-versions.mk
|
|
|
|
A shell script or workflow that cannot include a makefile should read the
|
|
value out of ${OWNER}; see controller/hack/ci/prepare-capd-bundles.sh.
|
|
MSG
|
|
exit 1
|
|
fi
|
|
|
|
n="$(printf '%s' "${names}" | wc -w | tr -d ' ')"
|
|
echo "Tool versions: ${n} pins, each declared once in ${OWNER}."
|