La regola del progetto è «codice e commenti in inglese; interfaccia, documenti e messaggi in italiano», e gli script di .gitea/ (script e flussi), di installer/ e docker/entrypoint.sh avevano ancora i commenti in italiano (decisione di Alberto del 29 novembre 2026). Cambiano solo i commenti: i messaggi che una persona legge (echo, ::warning::, ::error::, nomi dei passi, note della release) restano in italiano e nessun comando cambia. I programmi awk e gli script finti delle prove erano già in inglese. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
4.8 KiB
Bash
Executable File
121 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Quick checks before building (the «controlli» job of the CI): a few seconds, and they stop at once the errors that
|
|
# would otherwise be found after half an hour of tests. They can also be run by hand, from the repository root:
|
|
#
|
|
# bash .gitea/scripts/controlli.sh
|
|
#
|
|
# 1. every shell script of the repository is valid syntax (bash -n; sh -n for the sh ones) and has Unix line
|
|
# endings, like the awk programs of the CI;
|
|
# 2. the CI workflows read as block YAML: no tabs nor Windows line endings, two-space indentation outside text
|
|
# blocks, «on:» and «jobs:» present; and they are made of commands only: no «uses:», that is no action
|
|
# (JavaScript actions need Node, and the Febe CI is written in house: decision of 18 November 2026);
|
|
# 3. no file contains conflict markers left over from a merge;
|
|
# 4. the version in Directory.Build.props has the form x.y.z[-something], the one installer/costruisci.sh accepts;
|
|
# 5. every project listed in Febe.slnx exists;
|
|
# 6. every JSON file of the repository parses (configurations, cleaned samples, Chromium policies), with json.awk.
|
|
set -uo pipefail
|
|
|
|
radice="$(git rev-parse --show-toplevel)" || exit 2
|
|
cd "$radice" || exit 2
|
|
errori=0
|
|
export LC_ALL=C
|
|
|
|
errore() {
|
|
echo "ERRORE: $*" >&2
|
|
errori=$((errori + 1))
|
|
}
|
|
|
|
echo "== Script di shell"
|
|
quanti=0
|
|
while IFS= read -r -d '' script; do
|
|
quanti=$((quanti + 1))
|
|
bash -n "$script" || errore "$script: sintassi bash non valida."
|
|
if head -n 1 "$script" | grep -Eq '^#!(/usr/bin/env )?/?(bin/)?sh( |$)'; then
|
|
sh -n "$script" || errore "$script: sintassi sh non valida."
|
|
fi
|
|
if grep -q $'\r' "$script"; then
|
|
errore "$script ha righe Windows (CR): bash non le regge (.gitattributes chiede eol=lf)."
|
|
fi
|
|
done < <(git ls-files -z -- '*.sh')
|
|
echo " $quanti script controllati"
|
|
while IFS= read -r -d '' programma; do
|
|
if grep -q $'\r' "$programma"; then
|
|
errore "$programma ha righe Windows (CR) (.gitattributes chiede eol=lf)."
|
|
fi
|
|
done < <(git ls-files -z -- '*.awk')
|
|
|
|
echo "== Flussi della CI"
|
|
quanti=0
|
|
while IFS= read -r -d '' flusso; do
|
|
quanti=$((quanti + 1))
|
|
if grep -n $'\t' "$flusso" > /dev/null; then
|
|
errore "$flusso contiene tabulazioni: in YAML il rientro si fa con gli spazi."
|
|
fi
|
|
# A text block («run: |», «>-») holds all the lines indented more than its key; outside, indentation goes two
|
|
# spaces at a time and no line calls an action.
|
|
if rilievi=$(awk '
|
|
FNR == 1 { blocco = -1; on = 0; jobs = 0 }
|
|
{
|
|
riga = $0
|
|
if (riga ~ /\r$/) { print FNR ": riga Windows (CR)"; next }
|
|
match(riga, /^ */)
|
|
rientro = RLENGTH
|
|
vuota = riga ~ /^ *$/
|
|
if (blocco >= 0) {
|
|
if (vuota || rientro > blocco) next
|
|
blocco = -1
|
|
}
|
|
if (vuota || riga ~ /^ *#/) next
|
|
if (rientro % 2 == 1) print FNR ": rientro dispari"
|
|
if (riga ~ /^ *(- +)?uses *:/) print FNR ": «uses:» (nessuna azione: solo comandi)"
|
|
if (riga ~ /^on:/) on = 1
|
|
if (riga ~ /^jobs:/) jobs = 1
|
|
if (riga ~ /: *[|>][-+]?[0-9]? *(#.*)?$/) blocco = rientro
|
|
}
|
|
END {
|
|
if (!on) print "manca «on:»"
|
|
if (!jobs) print "manca «jobs:»"
|
|
}' "$flusso") && [[ -n "$rilievi" ]]; then
|
|
errore "$flusso:"$'\n'"$(sed 's/^/ riga /; s/^ riga manca/ manca/' <<< "$rilievi")"
|
|
fi
|
|
done < <(git ls-files -z -- '.gitea/workflows/*.yml' '.gitea/workflows/*.yaml')
|
|
echo " $quanti flussi controllati"
|
|
|
|
echo "== Segni di conflitto"
|
|
if conflitti=$(git grep -n -I -E '^(<{7}|>{7})( |$)' -- . ':!*.png' ':!*.jpg'); then
|
|
errore "segni di conflitto rimasti:"
|
|
echo "$conflitti" >&2
|
|
fi
|
|
|
|
echo "== Versione"
|
|
versione=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' Directory.Build.props)
|
|
if [[ "$(printf '%s\n' "$versione" | grep -c .)" != "1" ]]; then
|
|
errore "Directory.Build.props deve avere una sola <Version>."
|
|
elif [[ ! "$versione" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then
|
|
errore "versione «$versione» non valida: serve x.y.z, eventualmente con -qualcosa."
|
|
else
|
|
echo " $versione"
|
|
fi
|
|
|
|
echo "== Progetti della soluzione"
|
|
while IFS= read -r progetto; do
|
|
[[ -f "$progetto" ]] || errore "Febe.slnx elenca $progetto, che non esiste."
|
|
done < <(sed -n 's:.*<Project Path="\([^"]*\)".*:\1:p' Febe.slnx)
|
|
echo " $(grep -c '<Project Path=' Febe.slnx) progetti"
|
|
|
|
echo "== File JSON"
|
|
# A single process for all files; prints the files that do not parse, one per line, with the reason and the line.
|
|
mapfile -d '' json < <(git ls-files -z -- '*.json')
|
|
if ((${#json[@]} > 0)); then
|
|
if ! guasti=$(awk -f .gitea/scripts/json.awk -f .gitea/scripts/json-valido.awk "${json[@]}"); then
|
|
errore "JSON non valido:"
|
|
echo "${guasti:-(nessun dettaglio)}" >&2
|
|
fi
|
|
fi
|
|
|
|
if ((errori > 0)); then
|
|
echo "Controlli falliti: $errori." >&2
|
|
exit 1
|
|
fi
|
|
echo "Controlli superati."
|