Repository navigation
feat(validation): add lightweight AsciiDoc validation for agent and CI use #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- | ||
| name: Validate Docs | ||
|
|
||
| "on": | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| - "modules/**" | ||
| - "antora.yml" | ||
| - "bin/validate-docs.sh" | ||
| - "Makefile" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| validate: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 | ||
| with: | ||
| egress-policy: audit | ||
| disable-telemetry: true | ||
|
|
||
| - name: Checkout | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
|
||
| - name: Install asciidoctor | ||
| run: sudo gem install asciidoctor -v 2.0.26 --no-document | ||
|
|
||
| - name: Validate documentation | ||
| run: make validate-docs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
| MODULES_DIR="${REPO_ROOT}/modules" | ||
| PAGES_DIR="${MODULES_DIR}/ROOT/pages" | ||
| PARTIALS_DIR="${MODULES_DIR}/ROOT/partials" | ||
| NAV_FILE="${MODULES_DIR}/ROOT/nav.adoc" | ||
|
|
||
| ERROR_LOG=$(mktemp) | ||
| WORK_DIR=$(mktemp -d) | ||
| trap 'rm -f "${ERROR_LOG}"; rm -rf "${WORK_DIR}"' EXIT | ||
|
|
||
| error() { | ||
| echo "ERROR: $1" >&2 | ||
| echo "x" >> "${ERROR_LOG}" | ||
| } | ||
|
|
||
| warn() { | ||
| echo "WARN: $1" >&2 | ||
| } | ||
|
|
||
| # --- AsciiDoc syntax validation --- | ||
| validate_syntax() { | ||
| echo "==> Validating AsciiDoc syntax..." | ||
|
|
||
| if ! command -v asciidoctor &>/dev/null; then | ||
| warn "asciidoctor not found, skipping syntax validation." | ||
| warn "Install with: gem install asciidoctor" | ||
| return | ||
| fi | ||
|
|
||
| # Antora's partial$ prefix isn't understood by standalone asciidoctor. | ||
| # Resolve it to a relative path via a temp copy with a symlinked partials dir. | ||
| cp -a "${PAGES_DIR}" "${WORK_DIR}/pages" | ||
| ln -s "${PARTIALS_DIR}" "${WORK_DIR}/partials" | ||
| find "${WORK_DIR}/pages" -name '*.adoc' -exec \ | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| perl -pi -e 's|include::partial\$|include::../partials/|g' {} + | ||
|
|
||
| local syntax_errors=0 | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| while IFS= read -r -d '' file; do | ||
| local output | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| output=$(asciidoctor \ | ||
| --failure-level=WARN \ | ||
| --backend=html5 \ | ||
| --safe-mode=unsafe \ | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| --out-file=/dev/null \ | ||
| "$file" 2>&1) || true | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
|
|
||
| if [[ -n "$output" ]]; then | ||
| echo "$output" | while IFS= read -r line; do | ||
| echo " $line" | ||
| done | ||
| syntax_errors=$((syntax_errors + 1)) | ||
| fi | ||
| done < <(find "${WORK_DIR}/pages" -name '*.adoc' -print0) | ||
|
|
||
| if [[ ${syntax_errors} -gt 0 ]]; then | ||
| error "${syntax_errors} file(s) produced asciidoctor warnings or errors" | ||
| fi | ||
| } | ||
|
|
||
| # --- xref validation --- | ||
| validate_xrefs() { | ||
| echo "==> Validating xref targets..." | ||
|
|
||
| while IFS= read -r -d '' file; do | ||
| local relpath="${file#"${REPO_ROOT}/"}" | ||
| local matches | ||
| matches=$(grep -noE 'xref:[^[]+\[' "$file" 2>/dev/null) || continue | ||
|
|
||
| while IFS=: read -r lineno match; do | ||
| local target="${match#xref:}" | ||
| target="${target%\[}" | ||
| target="${target%%#*}" | ||
|
|
||
| # Skip cross-component xrefs, attribute-substituted targets, and same-page anchors | ||
| if [[ "$target" == *:* || "$target" == "{"* || -z "$target" ]]; then | ||
| continue | ||
| fi | ||
|
|
||
| if [[ ! -f "${PAGES_DIR}/${target}" ]]; then | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| error "${relpath}:${lineno}: broken xref to '${target}' (file not found in pages/)" | ||
| fi | ||
| done <<< "$matches" | ||
| done < <(find "${MODULES_DIR}" -name '*.adoc' -print0) | ||
|
cuipinghuo marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| # --- include validation --- | ||
| validate_includes() { | ||
| echo "==> Validating include targets..." | ||
|
|
||
| while IFS= read -r -d '' file; do | ||
| local relpath="${file#"${REPO_ROOT}/"}" | ||
| local matches | ||
| matches=$(grep -noE 'include::[^[]+\[' "$file" 2>/dev/null) || continue | ||
|
|
||
| while IFS=: read -r lineno match; do | ||
| local target="${match#include::}" | ||
| target="${target%\[}" | ||
|
|
||
| if [[ "$target" == partial\$* ]]; then | ||
| local partial_name="${target#partial\$}" | ||
| if [[ ! -f "${PARTIALS_DIR}/${partial_name}" ]]; then | ||
| error "${relpath}:${lineno}: broken include, partial '${partial_name}' not found in partials/" | ||
| fi | ||
| fi | ||
| done <<< "$matches" | ||
| done < <(find "${MODULES_DIR}" -name '*.adoc' -print0) | ||
| } | ||
|
|
||
| # --- nav validation --- | ||
| validate_nav() { | ||
| echo "==> Validating navigation references..." | ||
|
|
||
| if [[ ! -f "${NAV_FILE}" ]]; then | ||
| error "Navigation file not found: ${NAV_FILE}" | ||
| return | ||
| fi | ||
|
|
||
| for navfile in "${NAV_FILE}" "${PARTIALS_DIR}/contents.adoc"; do | ||
| [[ -f "$navfile" ]] || continue | ||
| local relpath="${navfile#"${REPO_ROOT}/"}" | ||
| local matches | ||
| matches=$(grep -noE 'xref:[^[]+\[' "$navfile" 2>/dev/null) || continue | ||
|
|
||
| while IFS=: read -r lineno match; do | ||
| local target="${match#xref:}" | ||
| target="${target%\[}" | ||
| target="${target%%#*}" | ||
|
|
||
| if [[ "$target" == *:* || "$target" == "{"* || -z "$target" ]]; then | ||
| continue | ||
| fi | ||
|
|
||
| if [[ ! -f "${PAGES_DIR}/${target}" ]]; then | ||
| error "${relpath}:${lineno}: nav references non-existent page '${target}'" | ||
| fi | ||
| done <<< "$matches" | ||
| done | ||
| } | ||
|
|
||
| echo "Validating documentation in ${REPO_ROOT}..." | ||
| echo | ||
|
|
||
| validate_syntax | ||
| validate_xrefs | ||
| validate_includes | ||
| validate_nav | ||
|
|
||
| echo | ||
| error_count=$(wc -l < "${ERROR_LOG}" | tr -d ' ') | ||
| if [[ ${error_count} -gt 0 ]]; then | ||
| echo "FAILED: ${error_count} error(s) found." | ||
| exit 1 | ||
| else | ||
| echo "PASSED: All validation checks passed." | ||
| exit 0 | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.