diff options
| author | Yuriy Andamasov <yuriy@vyos.io> | 2026-05-14 00:49:50 +0300 |
|---|---|---|
| committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2026-05-14 05:08:38 +0000 |
| commit | 628eb360bd84f45cdf4247cd3d1e102fe30bfc45 (patch) | |
| tree | 6bc2a67b8d77d3bdf672274a9d2ad0d9be5083c2 /scripts/doc-linter.py | |
| parent | 41341ac4d4cb89328b456ea8f7b0fdeef45e9d39 (diff) | |
| download | vyos-documentation-628eb360bd84f45cdf4247cd3d1e102fe30bfc45.tar.gz vyos-documentation-628eb360bd84f45cdf4247cd3d1e102fe30bfc45.zip | |
ci(doc-linter): lint added + renamed files, not only modified
Previous workflow:
env:
FILES_MODIFIED: ${{ steps.file_changes.outputs.files_modified }}
run: python scripts/doc-linter.py "$FILES_MODIFIED"
`trilom/file-changes-action`'s `files_modified` output is
modifications-only. A PR adding a new `.md`/`.rst` doc page passed
`files_added`, never `files_modified`, so a brand-new page with long
lines or real public IPs slipped past the linter entirely.
Workflow: also pass `files_added` and `files_renamed` as separate
positional args. Each output is a JSON array (action v1.2.4) and is
passed via env to avoid shell-quoting issues.
Linter: `main()` now accepts one OR multiple positional argv entries,
each a JSON array of paths. Arrays are merged and deduplicated before
linting. Single-arg invocations remain backward-compatible. Switched
from `ast.literal_eval` to `json.loads` — the action's outputs are
JSON, and `json.loads` is the right tool (and dodges
literal_eval-via-`eval`-substring linter warnings).
Test coverage:
- Two JSON arrays merge -> single linter run on union.
- Empty-string argv entry skipped (no `files_renamed` in many PRs).
- Malformed JSON -> falls back to walking DOCS_ROOT.
- No argv -> walks DOCS_ROOT.
- Single-arg invocation -> backward-compat preserved.
Tracked as item 7 of the rolling-side cleanup backlog from PR #2014 /
#2019 / #2020 reviews.
🤖 Generated by [robots](https://vyos.io)
(cherry picked from commit 1ef5684729646ca3a24aff83ab8edd0aa57914c7)
Diffstat (limited to 'scripts/doc-linter.py')
| -rw-r--r-- | scripts/doc-linter.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/scripts/doc-linter.py b/scripts/doc-linter.py index e352615c..509b1400 100644 --- a/scripts/doc-linter.py +++ b/scripts/doc-linter.py @@ -2,7 +2,7 @@ import os import re import ipaddress import sys -import ast +import json IPV4SEG = r'(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])' IPV4ADDR = r'\b(?:(?:' + IPV4SEG + r'\.){3,3}' + IPV4SEG + r')\b' @@ -302,11 +302,23 @@ def main(): # Only the argv-parsing step is wrapped in try/except. Errors raised by # handle_file_action() must propagate so CI failures stay visible instead # of silently triggering a full docs/ walk. - try: - files = ast.literal_eval(sys.argv[1]) - except (IndexError, SyntaxError, ValueError): - # No argv or malformed list -> fall back to walking DOCS_ROOT. + # + # Accepts one or more positional argv entries, each a JSON array of + # paths (e.g., `'["foo.md", "bar.rst"]'`). Arrays are merged and + # deduplicated before linting. CI passes `files_modified`, + # `files_added`, etc. as separate args — see lint-doc.yml. + if len(sys.argv) <= 1: files = None + else: + try: + files = [] + for arg in sys.argv[1:]: + if arg.strip(): + files.extend(json.loads(arg)) + files = sorted(set(files)) + except (json.JSONDecodeError, TypeError): + # Malformed input -> fall back to walking DOCS_ROOT. + files = None if files is not None: for file in files: |
