Skip to content

Commit

Permalink
test.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Feb 5, 2025
1 parent b0a330a commit 621e2a2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/rst_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Specific checks for rst files

on:
pull_request:
paths:
- "**/*.rst" # trigger only for .rst files

jobs:
one_sentence_per_line:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Get changed lines in .rst files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --unified=0 origin/${{ github.base_ref }} HEAD -- '*.rst' | grep '^[+-]' | grep -Ev '^(---|\+\+\+)' > /tmp/changed_lines.txt || true
- name: Run one-sentence-per-line checker on changed lines
run: |
python3 ./scripts/check_sentences.py /tmp/changed_lines.txt
51 changes: 51 additions & 0 deletions scripts/sentence_line_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse
import re
import sys

def is_one_sentence_per_line(line) -> bool:
"""
Check if a line contains only one complete sentence.
:param line: The line of file to check.
"""
# this assumes a sentence ends with a period, question mark, or exclamation mark.
sentence_endings = re.findall(r'[.!?]', line)
# allow empty lines or lines with only one sentence
return len(sentence_endings) <= 1

def check_changed_lines(filename) -> None:
"""
Check only changed lines for violations.
.. warning:: It checks only added / modified lines for the viaolation in the file,
and ignores everything else including removed lines.
:param filename: The name of the file to check.
"""
with open(filename, 'r', encoding='utf-8') as file:
lines = file.readlines()

violations = []
for lineno, line in enumerate(lines, start=1):
line = line.strip()
# check only added lines, ignore everything else
if line.startswith("+") and not is_one_sentence_per_line(line[1:]):
violations.append((lineno, line[1:]))

if violations:
print(f"\n⚠️ Found {len(violations)} violations:")
for lineno, line in violations:
print(f" ❌ Line {lineno}: {line}")
# exit with non-zero status code to fail github actions
sys.exit(1)
else:
print("✅ No violations found.")

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Check if modified contents contain only one complete sentence per line.")
parser.add_argument(
'filename', type=str, help='The name of the file to check.')
args = parser.parse_args()

check_changed_lines(args.filename)
7 changes: 7 additions & 0 deletions source/Citations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Citations
=========

This is a test.
This is a test. This should fail.
Is this a test?
Is this a test? Shoud this fail?
This is a test!
This is a test! This should fail!

If you use ROS 2 in your work please cite the 2022 Science Robotics paper `Robot Operating System 2: Design, architecture, and uses in the wild <https://www.science.org/doi/10.1126/scirobotics.abm6074>`_.

| S. Macenski, T. Foote, B. Gerkey, C. Lalancette, W. Woodall, "Robot Operating System 2: Design, architecture, and uses in the wild," Science Robotics vol. 7, May 2022.
Expand Down

0 comments on commit 621e2a2

Please sign in to comment.