-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add version drift-check for cluster_setup scripts and docs #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #!/usr/bin/env bash | ||
| # Fails if a version hardcoded in scripts/docs disagrees with versions.env. | ||
| # | ||
| # Every pinned version must be tagged inline with `ver:<KEY>` immediately | ||
| # after the version string, e.g.: | ||
| # YQ_VERSION="v4.44.1" # ver:YQ_VERSION | ||
| # pinned to `v4.44.1` <!-- ver:YQ_VERSION --> | ||
| # | ||
| # This script finds every `ver:<KEY>` marker in the repo, and checks that the | ||
| # version string named by KEY in versions.env also appears on that line. | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" | ||
| VERSIONS_FILE="${SCRIPT_DIR}/versions.env" | ||
|
|
||
| [[ -f "${VERSIONS_FILE}" ]] || { echo "missing ${VERSIONS_FILE}" >&2; exit 1; } | ||
|
|
||
| declare -A EXPECTED | ||
| while IFS='=' read -r key value; do | ||
| [[ -z "${key}" || "${key}" == \#* ]] && continue | ||
| EXPECTED["${key}"]="${value}" | ||
| done < "${VERSIONS_FILE}" | ||
|
|
||
| mismatches=0 | ||
| checked=0 | ||
|
|
||
| # grep -rn output is "path:line_no:content" — content may itself contain ':', | ||
| # so split only on the first two colons. | ||
| while IFS= read -r hit; do | ||
| file="${hit%%:*}" | ||
| rest="${hit#*:}" | ||
| line_no="${rest%%:*}" | ||
| content="${rest#*:}" | ||
|
|
||
| # Require a non-identifier char (or start of line) before "ver:" so this | ||
| # doesn't false-match inside words like "nvidia-driver:latest-dkms". | ||
| [[ "${content}" =~ (^|[^A-Za-z0-9_-])ver:([A-Za-z0-9_]+) ]] || continue | ||
| key="${BASH_REMATCH[2]}" | ||
|
|
||
| if [[ -z "${EXPECTED[${key}]+x}" ]]; then | ||
| echo "UNKNOWN KEY: ${file}:${line_no} references ver:${key}, not present in versions.env" >&2 | ||
| mismatches=$(( mismatches + 1 )) | ||
| continue | ||
| fi | ||
|
|
||
| expected="${EXPECTED[${key}]}" | ||
| if ! grep -qF -- "${expected}" <<<"${content}"; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The fixed-string containment test accepts a different version whenever it starts with the expected value. For example, with Useful? React with 👍 / 👎. |
||
| echo "MISMATCH: ${file}:${line_no} expected '${expected}' (versions.env:${key}) — got: ${content}" >&2 | ||
| mismatches=$(( mismatches + 1 )) | ||
| fi | ||
| checked=$(( checked + 1 )) | ||
| done < <(grep -rn 'ver:[A-Za-z0-9_]\+' \ | ||
| --include='*.sh' --include='*.md' \ | ||
| "${REPO_ROOT}/tools/cluster_setup" "${REPO_ROOT}/docs/deployment" 2>/dev/null) | ||
|
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because this scan only discovers existing Useful? React with 👍 / 👎.
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The grep runs in a process substitution, so its nonzero status is not propagated, and stderr is discarded. If either configured scan root is missing, renamed, or unreadable while the other still contains markers, the script reports success without checking that entire scope; for example, removing Useful? React with 👍 / 👎. |
||
|
|
||
| if (( checked == 0 )); then | ||
| echo "No ver:<KEY> markers found — nothing checked. Is the marker convention still in use?" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Checked ${checked} marker(s)." | ||
| if (( mismatches > 0 )); then | ||
| echo "${mismatches} version drift issue(s) found." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "No version drift." | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex extracts only the first
ver:<KEY>occurrence from each grep result. Several newly tagged documentation lines contain multiple markers, such as the binaries row inK0S_README.md:1394; changing its secondYQ_VERSIONvalue tov9.99.9still produces “No version drift” because only the precedingK0S_VERSIONmarker is checked. Iterate through all marker matches in each line rather than using a singleBASH_REMATCH.Useful? React with 👍 / 👎.