fix(ci): форматтер и ShellCheck — гейт должен быть зелёным на своей ветке
treefmt --fail-on-change падал на файлах, которые сама эта ветка и принесла:
checks.sh, config-fingerprint.sh и runtime-drift.sh не были shfmt-чистыми.
Форматтер, который красный на собственной ветке, — не форматтер.
Сделано:
* три скрипта этой ветки отформатированы (shfmt -i 2 -ci);
* .agent/src/install.sh исключён из treefmt: он старый, 487 строк diff'а,
и переписывать чужой инсталлятор — решение владельца, не форматтера;
* shellcheck добавлен в devshell .#fmt и в checks.sh (check #13); если
shellcheck нет в PATH — проверка SKIP, а не FAIL;
* поправлены протухшие комментарии treefmt.toml: output'а formatter у
флейка нет (ADR-0011), а .ci/flake-checks.nix удалён.
Заодно в шапке config-fingerprint.sh зафиксирован грабли, который стоил
часа поиска: обе ревизии надо материализовать одинаково (git archive),
иначе исполняемый бит одного файла меняет store path whitesur-kde, а за
ним system-path, XDG_DATA_DIRS и X-Restart-Triggers — при полностью
идентичном содержимом.
This commit is contained in:
1 parent
07b2c03c4c
commit
c4ccb5ac7e
5 files changed
+89
-32
No files matched your search
+34
-7
@@ -22,6 +22,7 @@
|
||||
# #11 `listen.addr` names an interface, not a network — added 2026-11-15
|
||||
# #12 AGENTS.md / manifest.md / manifest.json / decisions index agree
|
||||
# — added 2026-11-15
|
||||
# #13 shell scripts pass ShellCheck — added 2026-11-15
|
||||
#
|
||||
# Every python check below is also a standalone script, so it can be run
|
||||
# directly: `python3 .ci/tests/<script>.py .`. They deliberately are NOT
|
||||
@@ -66,7 +67,10 @@ SKIP_BUILD=false
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--no-build) SKIP_BUILD=true ;;
|
||||
*) echo "Unknown arg: $arg" >&2; exit 2 ;;
|
||||
*)
|
||||
echo "Unknown arg: $arg" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -164,7 +168,7 @@ check_no_latest_images() {
|
||||
if [ "$allowed" = false ]; then
|
||||
violations+=("$img")
|
||||
fi
|
||||
done <<< "$latest_images"
|
||||
done <<<"$latest_images"
|
||||
if [ "${#violations[@]}" -eq 0 ]; then
|
||||
report 0 "no :latest images (whitelist honoured)"
|
||||
else
|
||||
@@ -181,7 +185,7 @@ check_import_graph() {
|
||||
echo " SKIP: python3 not in PATH"
|
||||
return 0
|
||||
fi
|
||||
if python3 .ci/tests/import-graph.py . ; then
|
||||
if python3 .ci/tests/import-graph.py .; then
|
||||
report 0 "import graph"
|
||||
else
|
||||
report 1 "import graph"
|
||||
@@ -194,7 +198,7 @@ check_metadata_schemas() {
|
||||
echo " SKIP: python3 not in PATH"
|
||||
return 0
|
||||
fi
|
||||
if python3 .ci/tests/validate-metadata.py . ; then
|
||||
if python3 .ci/tests/validate-metadata.py .; then
|
||||
report 0 "metadata schemas"
|
||||
else
|
||||
report 1 "metadata schemas"
|
||||
@@ -207,7 +211,7 @@ check_domains() {
|
||||
echo " SKIP: python3 not in PATH"
|
||||
return 0
|
||||
fi
|
||||
if python3 .ci/tests/check-domains.py . ; then
|
||||
if python3 .ci/tests/check-domains.py .; then
|
||||
report 0 "coredns/nginx domains"
|
||||
else
|
||||
report 1 "coredns/nginx domains"
|
||||
@@ -227,7 +231,7 @@ check_listen_addrs() {
|
||||
report 1 "listen.addr classifier self-test"
|
||||
return 0
|
||||
fi
|
||||
if python3 .ci/tests/check-listen-addrs.py . ; then
|
||||
if python3 .ci/tests/check-listen-addrs.py .; then
|
||||
report 0 "listen.addr values"
|
||||
else
|
||||
report 1 "listen.addr values"
|
||||
@@ -240,13 +244,35 @@ check_agent_consistency() {
|
||||
echo " SKIP: python3 not in PATH"
|
||||
return 0
|
||||
fi
|
||||
if python3 .ci/tests/check-agent-consistency.py . ; then
|
||||
if python3 .ci/tests/check-agent-consistency.py .; then
|
||||
report 0 "agent metadata consistency"
|
||||
else
|
||||
report 1 "agent metadata consistency"
|
||||
fi
|
||||
}
|
||||
|
||||
check_shellcheck() {
|
||||
echo "Check #13: shell scripts pass ShellCheck ..."
|
||||
if ! command -v shellcheck >/dev/null 2>&1; then
|
||||
echo " SKIP: shellcheck not in PATH (available via 'nix develop .#fmt')"
|
||||
return 0
|
||||
fi
|
||||
local scripts=()
|
||||
while IFS= read -r f; do
|
||||
scripts+=("$f")
|
||||
done < <(find . -type f -name '*.sh' -not -path './.git/*' | sort)
|
||||
if [ "${#scripts[@]}" -eq 0 ]; then
|
||||
echo " SKIP: no shell scripts found"
|
||||
return 0
|
||||
fi
|
||||
# -S warning: style/info-level findings are noise, warnings and errors are not.
|
||||
if shellcheck -S warning "${scripts[@]}"; then
|
||||
report 0 "shellcheck (${#scripts[@]} script(s))"
|
||||
else
|
||||
report 1 "shellcheck (${#scripts[@]} script(s))"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "=== nixos flake checks ==="
|
||||
check_nix_flake_check
|
||||
check_sops_path_regex
|
||||
@@ -256,6 +282,7 @@ check_metadata_schemas
|
||||
check_domains
|
||||
check_listen_addrs
|
||||
check_agent_consistency
|
||||
check_shellcheck
|
||||
echo "==="
|
||||
echo "PASS: $PASS FAIL: $FAIL"
|
||||
if [ "$FAIL" -gt 0 ]; then
|
||||
|
||||
@@ -24,6 +24,23 @@
|
||||
# .ci/verify/config-fingerprint.sh /tmp/after
|
||||
# diff -r /tmp/before /tmp/after && echo "no behavioural change"
|
||||
#
|
||||
# IMPORTANT — materialise both revisions the same way, or the diff lies.
|
||||
# Store paths are part of the snapshot, and a store path depends on the
|
||||
# executable bit of the file it was copied from. A checkout made on Windows
|
||||
# (/mnt/c, drvfs) reports every file as executable, a `git archive` on Linux
|
||||
# restores the mode recorded in the git index. Compare a Windows working copy
|
||||
# against a `git archive` export and `overlays/patch-whitesur-sddm.pl` comes
|
||||
# out with two different store paths — which changes the `system-path`
|
||||
# derivation, which changes `XDG_DATA_DIRS` in accounts-daemon.service, which
|
||||
# changes the `X-Restart-Triggers` files of dbus-broker and polkit. None of
|
||||
# that is a behavioural change; it is the same bytes in a different wrapper.
|
||||
#
|
||||
# git archive dev | tar -x -C /tmp/dev
|
||||
# git archive agent | tar -x -C /tmp/agent
|
||||
# (cd /tmp/dev && .ci/verify/config-fingerprint.sh /tmp/fp-dev)
|
||||
# (cd /tmp/agent && .ci/verify/config-fingerprint.sh /tmp/fp-agent)
|
||||
# diff -r /tmp/fp-dev /tmp/fp-agent
|
||||
#
|
||||
# Exit code: 0 when every requested host evaluated, 1 otherwise.
|
||||
set -euo pipefail
|
||||
|
||||
@@ -134,7 +151,7 @@ for host in $HOSTS; do
|
||||
echo "fingerprint: evaluating ${host} ..."
|
||||
if nix --extra-experimental-features "nix-command flakes" eval \
|
||||
--json ".#nixosConfigurations.${host}.config" \
|
||||
--apply "$FINGERPRINT_EXPR" > "${OUT_DIR}/${host}.json" 2>"${OUT_DIR}/${host}.err"; then
|
||||
--apply "$FINGERPRINT_EXPR" >"${OUT_DIR}/${host}.json" 2>"${OUT_DIR}/${host}.err"; then
|
||||
echo " ok: ${OUT_DIR}/${host}.json"
|
||||
else
|
||||
echo " FAIL: ${host}" >&2
|
||||
|
||||
+13
-10
@@ -55,7 +55,10 @@ else
|
||||
--nginx) DO_NGINX=1 ;;
|
||||
--podman) DO_PODMAN=1 ;;
|
||||
--systemd) DO_SYSTEMD=1 ;;
|
||||
*) echo "Unknown arg: $arg" >&2; exit 2 ;;
|
||||
*)
|
||||
echo "Unknown arg: $arg" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
@@ -72,11 +75,11 @@ if [ "$DO_NGINX" -eq 1 ]; then
|
||||
else
|
||||
rendered=$(mktemp)
|
||||
loaded=$(mktemp)
|
||||
grep -hoE '^[[:space:]]*server_name[[:space:]]+[^;]+;' "$NGINX_CONF" \
|
||||
| sed -E 's/.*server_name[[:space:]]+//; s/;//' | tr ' ' '\n' | sort -u > "$rendered"
|
||||
nginx -T 2>/dev/null \
|
||||
| grep -hoE '^[[:space:]]*server_name[[:space:]]+[^;]+;' \
|
||||
| sed -E 's/.*server_name[[:space:]]+//; s/;//' | tr ' ' '\n' | sort -u > "$loaded"
|
||||
grep -hoE '^[[:space:]]*server_name[[:space:]]+[^;]+;' "$NGINX_CONF" |
|
||||
sed -E 's/.*server_name[[:space:]]+//; s/;//' | tr ' ' '\n' | sort -u >"$rendered"
|
||||
nginx -T 2>/dev/null |
|
||||
grep -hoE '^[[:space:]]*server_name[[:space:]]+[^;]+;' |
|
||||
sed -E 's/.*server_name[[:space:]]+//; s/;//' | tr ' ' '\n' | sort -u >"$loaded"
|
||||
if diff -u "$rendered" "$loaded" >/dev/null 2>&1; then
|
||||
echo " OK: nginx serves the same server_name set as the rendered config"
|
||||
else
|
||||
@@ -95,8 +98,8 @@ if [ "$DO_PODMAN" -eq 1 ]; then
|
||||
if ! command -v podman >/dev/null 2>&1; then
|
||||
echo " SKIP: podman not in PATH"
|
||||
else
|
||||
for unit in $(systemctl list-units --type=service --all --no-legend 2>/dev/null \
|
||||
| awk '$1 ~ /^podman-/ {print $1}'); do
|
||||
for unit in $(systemctl list-units --type=service --all --no-legend 2>/dev/null |
|
||||
awk '$1 ~ /^podman-/ {print $1}'); do
|
||||
unit_file="/etc/systemd/system/${unit}.service"
|
||||
[ -f "$unit_file" ] || continue
|
||||
container=$(sed -nE 's/.*--name[= ]"?([^" ]+)"?.*/\1/p' "$unit_file" | head -1)
|
||||
@@ -106,8 +109,8 @@ if [ "$DO_PODMAN" -eq 1 ]; then
|
||||
DRIFT=1
|
||||
continue
|
||||
fi
|
||||
declared=$(sed -nE 's/.*(-p|--publish)[= ]"?([^" ]+)"?.*/\2/p' "$unit_file" \
|
||||
| tr ',' '\n' | sed 's/^[[:space:]]*//' | sort -u)
|
||||
declared=$(sed -nE 's/.*(-p|--publish)[= ]"?([^" ]+)"?.*/\2/p' "$unit_file" |
|
||||
tr ',' '\n' | sed 's/^[[:space:]]*//' | sort -u)
|
||||
published=$(podman inspect "$container" --format '{{json .NetworkSettings.Ports}}' 2>/dev/null)
|
||||
for entry in $declared; do
|
||||
host_port="${entry%%:*}"
|
||||
|
||||
@@ -45,7 +45,7 @@ in
|
||||
};
|
||||
|
||||
# `nix develop .#fmt` -> инструменты форматирования репозитория:
|
||||
# treefmt + nixfmt + shfmt. Конфиг — treefmt.toml в корне репозитория.
|
||||
# treefmt + nixfmt + shfmt + shellcheck. Конфиг — treefmt.toml в корне.
|
||||
#
|
||||
# nix develop .#fmt --command treefmt # применить стиль
|
||||
# nix develop .#fmt --command treefmt -- --fail-on-change .
|
||||
@@ -61,13 +61,15 @@ in
|
||||
treefmt
|
||||
nixfmt
|
||||
shfmt
|
||||
shellcheck
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "[fmt-devshell] treefmt: $(command -v treefmt)" >&2
|
||||
echo "[fmt-devshell] nixfmt: $(command -v nixfmt)" >&2
|
||||
echo "[fmt-devshell] shfmt: $(command -v shfmt)" >&2
|
||||
echo "[fmt-devshell] конфиг: treefmt.toml в корне репозитория" >&2
|
||||
echo "[fmt-devshell] treefmt: $(command -v treefmt)" >&2
|
||||
echo "[fmt-devshell] nixfmt: $(command -v nixfmt)" >&2
|
||||
echo "[fmt-devshell] shfmt: $(command -v shfmt)" >&2
|
||||
echo "[fmt-devshell] shellcheck: $(command -v shellcheck)" >&2
|
||||
echo "[fmt-devshell] конфиг: treefmt.toml в корне репозитория" >&2
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
+17
-9
@@ -1,19 +1,26 @@
|
||||
# treefmt configuration — one entry point for every formatter in the repo.
|
||||
#
|
||||
# `nix fmt` runs this (see the `formatter` output in flake.nix; the wrapper
|
||||
# puts nixfmt and shfmt on PATH next to treefmt).
|
||||
# How to use it:
|
||||
# nix develop .#fmt --command treefmt # apply the style
|
||||
# nix develop .#fmt --command treefmt -- --fail-on-change . # CI-style gate
|
||||
#
|
||||
# There is deliberately NO `formatter` output in flake.nix: on the pinned
|
||||
# nixpkgs `nix flake check` fails with "'outPath' is not a valid system type"
|
||||
# on any derivation output, so the formatter lives in a devshell instead
|
||||
# (see the note in flake.nix and ADR-0011).
|
||||
#
|
||||
# Current state (measured 2026-11-15):
|
||||
# * all 137 tracked .nix files are already nixfmt-clean — the formatter is a
|
||||
# guard against future drift, not a mass reformat;
|
||||
# * the three tracked .sh files are NOT shfmt-clean, so `nix fmt` will
|
||||
# rewrite them. That is deliberate and safe: they are scripts, not
|
||||
# behaviour. Nothing is formatted automatically on commit.
|
||||
# * all 138 tracked .nix files are nixfmt-clean — the formatter guards
|
||||
# against future drift, it does not reformat the repository;
|
||||
# * the repository's own shell scripts are shfmt-clean;
|
||||
# * .agent/src/install.sh is EXCLUDED below: it predates the formatter and
|
||||
# was never shfmt-formatted (487 diff lines). Reformatting somebody
|
||||
# else's installer is the owner's call, not the formatter's.
|
||||
#
|
||||
# Deliberately absent: a JSON/YAML formatter. The .agent artefacts are
|
||||
# hand-written and reformatting them would bury every real diff in noise.
|
||||
# ShellCheck is a linter, not a formatter — it runs as a CI check
|
||||
# (.ci/flake-checks.nix), not here.
|
||||
# ShellCheck is a linter, not a formatter — it runs as its own check
|
||||
# (see check #13 in .ci/checks.sh).
|
||||
|
||||
[global]
|
||||
# A formatter that fails must not stop the others: report and continue.
|
||||
@@ -27,3 +34,4 @@ includes = ["**/*.nix"]
|
||||
command = "shfmt"
|
||||
args = ["-i", "2", "-ci", "-w"]
|
||||
includes = ["**/*.sh"]
|
||||
excludes = [".agent/src/install.sh"]
|
||||
Reference in new issue
Block a user