diff --git a/scripts/lib/gate-filters.sh b/scripts/lib/gate-filters.sh index b40ee807..10339b24 100644 --- a/scripts/lib/gate-filters.sh +++ b/scripts/lib/gate-filters.sh @@ -1,13 +1,32 @@ #!/usr/bin/env bash # Shared post-filters for this repo's grep-based CI gates (#597). # -# Sourced, not executed: +# Sourced, not executed. This example is the shape the two converted gates +# actually use, and it passes `scripts/check-shell-lint.sh` phase 1 as written -- +# both of which matter, because the next gate will be a copy of one of those two +# and of this block: # -# source "$(git rev-parse --show-toplevel)/scripts/lib/gate-filters.sh" +# gate_lib_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# # shellcheck source=scripts/lib/gate-filters.sh +# source "$gate_lib_dir/lib/gate-filters.sh" +# +# set +e # hits=$(git grep -nE "$pattern" -- "${paths[@]}" \ # | skip_comment_continuations \ -# | exempt_path AuditDetailScreen.kt \ -# || true) +# | exempt_path AuditDetailScreen.kt) +# set -e +# +# Two details are deliberate rather than incidental. +# +# The library is resolved from the GATE's own location, not from the working +# directory: `$(git rev-parse --show-toplevel)` reads the enclosing repo, which +# is the wrong repo when the gate is invoked from the throwaway tree its +# self-test builds, and shellcheck flags the discarded status besides (SC2312). +# +# The pipeline sits inside a `set +e` bracket rather than ending in `|| true`. +# Both discard the status, and the status must be discarded -- see below -- but +# a FUNCTION in an `||` condition turns `set -e` off inside it, which +# `check-shell-lint.sh` reports as SC2310 and fails the build over. # # ============================================================================= # READ THIS FIRST IF YOU ARE ADDING A GATE @@ -55,9 +74,12 @@ # `check-apk-distribution.sh` have none and deliberately do not source this file. # # Both functions read stdin and write stdout, so they compose as pipeline -# stages. Neither swallows `grep`'s exit status: `grep -v` exits 1 when it emits -# nothing, which for a gate is the GOOD case, so the caller keeps the `|| true` -# on the pipeline as a whole exactly as before. +# stages. Neither swallows `grep`'s exit status, so the CALLER must discard it: +# `grep -v` exits 1 when it emits nothing, which for a gate is the GOOD case, +# and under `set -euo pipefail` that would otherwise kill the gate on a clean +# tree. Both converted gates do that with the `set +e` bracket shown above -- +# which is a change from the `|| true` they carried before this library existed, +# and the reason is SC2310, not taste. # Drop lines whose CONTENT field is a block-comment continuation (` * ...`), so # prose about the banned construct -- a KDoc paragraph, a pattern list written