#!/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:.*\(.*\).*:\1:p' Directory.Build.props) if [[ "$(printf '%s\n' "$versione" | grep -c .)" != "1" ]]; then errore "Directory.Build.props deve avere una sola ." 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:.* 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."