|
| 1 | +#!/bin/bash |
| 2 | +# Report man pages whose rendered NAME does not match their filename. |
| 3 | +# asciidoctor takes the .TH name from the page's NAME section, the build pins the filename with -o, so a translated NAME just leaves the two disagreeing. |
| 4 | +# Never fails the build: under GitHub Actions it emits warning annotations and a job summary, otherwise plain lines. |
| 5 | +# The NAME lines are managed in Weblate, so fixes go there. |
| 6 | +# Argument: the built man tree to scan (default docs/build/man). |
| 7 | + |
| 8 | +set -u |
| 9 | + |
| 10 | +ROOT="${1:-docs/build/man}" |
| 11 | + |
| 12 | +if [ ! -d "$ROOT" ]; then |
| 13 | + echo "I: $ROOT not found, build the man pages first" |
| 14 | + exit 0 |
| 15 | +fi |
| 16 | + |
| 17 | +# Lowercase and drop the roff backslash .TH escapes into names. |
| 18 | +norm() { local s=${1//\\/}; printf '%s' "${s,,}"; } |
| 19 | + |
| 20 | +count=0 |
| 21 | +summary="" |
| 22 | +while IFS= read -r -d '' f; do |
| 23 | + # Skip .so alias stubs: redirects with no .TH of their own. |
| 24 | + case "$(head -n 1 "$f")" in |
| 25 | + ".so "*) continue ;; |
| 26 | + esac |
| 27 | + th=$(sed -ne 's/^\.TH "\([^"]*\)".*/\1/p' "$f" | head -n 1) |
| 28 | + [ -n "$th" ] || continue |
| 29 | + base=${f##*/} |
| 30 | + stem=${base%.*} |
| 31 | + [ "$(norm "$th")" = "$(norm "$stem")" ] && continue |
| 32 | + |
| 33 | + rel=${f#"$ROOT"/} |
| 34 | + lang=${rel%%/*} |
| 35 | + case "$lang" in man[0-9]*) lang=en ;; esac |
| 36 | + if [ -n "${GITHUB_ACTIONS:-}" ]; then |
| 37 | + printf '::warning title=manpage NAME mismatch::%s: %s has NAME %s\n' "$lang" "$stem" "$th" |
| 38 | + else |
| 39 | + printf 'W: %s: %s has NAME %s\n' "$lang" "$stem" "$th" |
| 40 | + fi |
| 41 | + summary="${summary}| ${lang} | ${stem} | ${th} |"$'\n' |
| 42 | + count=$((count + 1)) |
| 43 | +done < <(find "$ROOT" -type f -name '*.[0-9]' -print0 | sort -z) |
| 44 | + |
| 45 | +echo "I: $count manpage NAME/filename mismatch(es)" |
| 46 | + |
| 47 | +if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then |
| 48 | + { |
| 49 | + echo "## Manpage NAME mismatches: $count" |
| 50 | + if [ "$count" -gt 0 ]; then |
| 51 | + echo |
| 52 | + echo "Translated NAME lines that drifted from the command name." |
| 53 | + echo "The left side of a NAME line is a command identifier and must" |
| 54 | + echo "stay verbatim; fix these in Weblate." |
| 55 | + echo |
| 56 | + echo "| lang | page | rendered NAME |" |
| 57 | + echo "| ---- | ---- | ------------- |" |
| 58 | + printf '%s' "$summary" |
| 59 | + fi |
| 60 | + } >> "$GITHUB_STEP_SUMMARY" |
| 61 | +fi |
| 62 | + |
| 63 | +exit 0 |
0 commit comments