Skip to content

Commit 7d6d12f

Browse files
Merge pull request #1 from gabriele-ciccotelli/rtl-ltr-linter
Add RTL/LTR Markdown linter for mixed-direction text consistency and PR annotation
2 parents 1be7c48 + fba7e29 commit 7d6d12f

File tree

3 files changed

+779
-0
lines changed

3 files changed

+779
-0
lines changed

.github/workflows/rtl-ltr-linter.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: RTL/LTR Markdown Linter
2+
3+
on: [pull_request]
4+
5+
permissions:
6+
contents: read # Required to checkout the repository content
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# Checkout the repository code
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
# Fetch the full history of 'main' for accurate git diff in PRs
18+
- name: Fetch all history for main
19+
run: git fetch --no-tags --prune --depth=50 origin main
20+
21+
# Set up the required Python version for the linter
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.11' # Use a recent Python version for compatibility
26+
27+
# Install only the Python dependencies needed for the linter script
28+
- name: Install Python dependencies
29+
run: |
30+
pip install python-bidi PyYAML
31+
32+
# (Optional) List files for debugging purposes
33+
- name: List files in scripts directory and current path
34+
run: |
35+
echo "Current working directory:"
36+
pwd
37+
echo "Listing contents of scripts directory (if it exists at root):"
38+
ls -la scripts/ || echo "scripts/ directory not found at root or ls failed"
39+
40+
# Identify all changed Markdown files in the PR using tj-actions/changed-files
41+
- name: Get changed Markdown files
42+
id: changed_md_files
43+
uses: tj-actions/changed-files@v44
44+
with:
45+
files: |
46+
**/*.md
47+
48+
# Run the RTL/LTR Markdown linter:
49+
# - Scans all Markdown files for issues and writes a full log
50+
# - Prints GitHub Actions annotations only for issues on changed lines in changed files
51+
# - Fails the job if any error or warning is found on changed lines
52+
- name: Run RTL/LTR Markdown linter
53+
id: run_linter
54+
run: |
55+
echo "Scanning all specified paths for full log..."
56+
echo "Changed Markdown files for PR annotations: ${{ steps.changed_md_files.outputs.all_changed_files }}"
57+
58+
CHANGED_FILES_ARGS=""
59+
if [ "${{ steps.changed_md_files.outputs.all_changed_files_count }}" -gt 0 ]; then
60+
# Pass changed files to the script for PR annotation generation
61+
# The paths from tj-actions/changed-files are space-separated
62+
CHANGED_FILES_ARGS="--changed-files ${{ steps.changed_md_files.outputs.all_changed_files }}"
63+
fi
64+
65+
# Execute the linter.
66+
# Annotations for changed files will be printed to stdout by the script.
67+
# The script will also write a full log to 'rtl-linter-output.log'.
68+
# If the script exits with a non-zero code (issues found), this step will fail.
69+
python3 scripts/rtl_ltr_linter.py books casts courses more ${CHANGED_FILES_ARGS} --log-file rtl-linter-output.log
70+
71+
# Upload the linter output log as a workflow artifact for further inspection
72+
- name: Upload linter output artifact
73+
uses: actions/upload-artifact@v4
74+
if: always() # Upload artifact even if the linter step failed
75+
with:
76+
name: rtl-linter-output # Name of the artifact
77+
path: rtl-linter-output.log # Path to the output file
78+
retention-days: 7 # How long to keep the artifact

0 commit comments

Comments
 (0)