Skip to content

Commit 9ba59ef

Browse files
committed
ci: add GitHub Action to validate manpages with mandoc
Add a new workflow that builds and validates all manpages using mandoc -T lint. The workflow runs on PRs and pushes that modify manpage-related files and validates both English and French manpages in parallel.
1 parent bf9a10f commit 9ba59ef

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

.github/workflows/manpage-lint.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# spell-checker:ignore mandoc uudoc manpages dtolnay libsystemd libattr libcap
2+
3+
name: Manpage Validation
4+
5+
on:
6+
pull_request:
7+
paths:
8+
- 'src/bin/uudoc.rs'
9+
- 'src/uu/*/locales/*.ftl'
10+
- 'src/uu/*/src/*.rs'
11+
- 'Cargo.toml'
12+
- 'GNUmakefile'
13+
- '.github/workflows/manpage-lint.yml'
14+
push:
15+
branches:
16+
- main
17+
paths:
18+
- 'src/bin/uudoc.rs'
19+
- 'src/uu/*/locales/*.ftl'
20+
- 'src/uu/*/src/*.rs'
21+
- 'Cargo.toml'
22+
- 'GNUmakefile'
23+
- '.github/workflows/manpage-lint.yml'
24+
25+
jobs:
26+
manpage-lint:
27+
name: Validate manpages with mandoc
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
locale: [en, fr]
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v6
36+
37+
- name: Install prerequisites
38+
shell: bash
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install -y mandoc locales-all
42+
sudo apt-get install -y libselinux1-dev libsystemd-dev libacl1-dev libattr1-dev libcap-dev
43+
44+
- name: Install Rust toolchain
45+
uses: dtolnay/rust-toolchain@stable
46+
47+
- name: Build manpages (${{ matrix.locale }})
48+
run: |
49+
# Create temporary directory for manpages
50+
MANPAGE_DIR=$(mktemp -d)
51+
echo "MANPAGE_DIR=${MANPAGE_DIR}" >> $GITHUB_ENV
52+
53+
# Set locale for manpage generation
54+
if [ "${{ matrix.locale }}" = "fr" ]; then
55+
export LANGUAGE=fr_FR.UTF-8
56+
export LANG=fr_FR.UTF-8
57+
export LC_ALL=fr_FR.UTF-8
58+
fi
59+
60+
# Build and install manpages to temporary directory
61+
# codespell-ignore: DESTDIR
62+
make install-manpages DESTDIR="${MANPAGE_DIR}"
63+
64+
- name: Validate manpages with mandoc (${{ matrix.locale }})
65+
run: |
66+
# Find all generated manpages
67+
MANPAGE_PATH="${MANPAGE_DIR}/usr/local/share/man/man1"
68+
69+
# Check if manpages were generated
70+
if [ ! -d "${MANPAGE_PATH}" ]; then
71+
echo "Error: No manpages found at ${MANPAGE_PATH}"
72+
exit 1
73+
fi
74+
75+
# Initialize error tracking
76+
ERRORS_FOUND=0
77+
ERROR_LOG=$(mktemp)
78+
79+
echo "Validating ${{ matrix.locale }} manpages with mandoc..."
80+
echo "=========================================="
81+
82+
# Validate each manpage
83+
for manpage in "${MANPAGE_PATH}"/*.1; do
84+
if [ -f "$manpage" ]; then
85+
filename=$(basename "$manpage")
86+
echo "Checking: $filename"
87+
88+
# Run mandoc lint and capture output
89+
if ! mandoc -T lint "$manpage" 2>&1 | tee -a "$ERROR_LOG"; then
90+
echo " ✗ Errors found in $filename"
91+
ERRORS_FOUND=1
92+
else
93+
# Check if mandoc produced any output (warnings/errors)
94+
if mandoc -T lint "$manpage" 2>&1 | grep -q .; then
95+
echo " ⚠ Warnings found in $filename"
96+
ERRORS_FOUND=1
97+
else
98+
echo "$filename is valid"
99+
fi
100+
fi
101+
fi
102+
done
103+
104+
echo ""
105+
echo "=================================="
106+
107+
# Summary and exit
108+
if [ "$ERRORS_FOUND" -eq 1 ]; then
109+
echo "Manpage validation failed. Issues found:"
110+
echo ""
111+
cat "$ERROR_LOG"
112+
exit 1
113+
else
114+
echo "All manpages validated successfully!"
115+
fi
116+
117+
- name: Count manpages (${{ matrix.locale }})
118+
run: |
119+
MANPAGE_PATH="${MANPAGE_DIR}/usr/local/share/man/man1"
120+
COUNT=$(find "${MANPAGE_PATH}" -name "*.1" -type f | wc -l)
121+
echo "Total ${{ matrix.locale }} manpages generated: $COUNT"

0 commit comments

Comments
 (0)