Skip to content

Commit 9111202

Browse files
committed
test(hack): let one selector opt out of the release-prefix guard
A repo-wide name check will eventually meet a selector that is correct and still fails it, such as an object named on the operator's terms. The only escape so far was an empty prefix, which exempts a whole definition, and a guard with no narrower way out is one people learn to route around. A trailing "cozy-lint:ignore rd-release-prefix -- <reason>" comment now exempts that one entry, and a directive without a reason does not count, so a bare suppression is never the easy path. Assisted-by: LLM Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 13549b5 commit 9111202

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

‎hack/check-rd-release-prefix.bats‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,26 @@ REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
1818
prefix="$(yq -r '.spec.release.prefix // ""' "$f")"
1919
[ -n "$prefix" ] || continue
2020

21-
# One "<section>.<include|exclude>: <name>" row per selector entry.
22-
names="$(yq -r '
21+
# One "<section>.<include|exclude> TAB <name> TAB <line comment>" row per
22+
# selector entry. yq sees the comment only on a block-style entry: on a
23+
# flow sequence ("[a, b] # ...") it belongs to the list, not to an entry.
24+
rows="$(yq -r '
2325
.spec | (.secrets, .services, .ingresses) | select(. != null)
2426
| (.include, .exclude) | select(. != null) | .[]
2527
| .resourceNames | select(. != null) | .[]
26-
| (path | .[1] + "." + .[2]) + ": " + .
28+
| [(path | .[1] + "." + .[2]), ., (line_comment // "")] | @tsv
2729
' "$f")"
28-
[ -n "$names" ] || continue
29-
total=$(( total + $(printf '%s\n' "$names" | grep -c .) ))
30+
[ -n "$rows" ] || continue
31+
total=$(( total + $(printf '%s\n' "$rows" | grep -c .) ))
3032

31-
bad="$(printf '%s\n' "$names" | grep -vF "${prefix}{{ .name }}" || true)"
32-
[ -z "$bad" ] || violations="$violations$(printf '%s\n' "$bad" | sed "s|^|${f#"$REPO_ROOT"/}: |")
33+
bad="$(printf '%s\n' "$rows" | awk -F '\t' -v needle="${prefix}{{ .name }}" -v file="${f#"$REPO_ROOT"/}" '
34+
$3 ~ /cozy-lint:ignore rd-release-prefix/ {
35+
if ($3 !~ /cozy-lint:ignore rd-release-prefix -- [^ ]/) print file ": " $1 ": " $2 " (exempted without a reason)"
36+
next
37+
}
38+
index($2, needle) == 0 { print file ": " $1 ": " $2 }
39+
')"
40+
[ -z "$bad" ] || violations="$violations$bad
3341
"
3442
done
3543

@@ -41,6 +49,8 @@ REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
4149
echo "resourceNames selectors that can never match the object their chart creates:" >&2
4250
printf '%s' "$violations" >&2
4351
echo "Fix: spell the release prefix out, e.g. \"harbor-{{ .name }}-credentials\"." >&2
52+
echo "A name deliberately not derived from the release takes a trailing comment on its entry:" >&2
53+
echo " # cozy-lint:ignore rd-release-prefix -- <reason>" >&2
4454
exit 1
4555
fi
4656
}

0 commit comments

Comments
 (0)