Skip to content

Commit 0f5de75

Browse files
Merge pull request #126 from cconlon/ghActionLineLength
Testing: add GitHub action to check all lines are <= 80 characters
2 parents dc2b8e7 + 1bb3016 commit 0f5de75

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Line Length Check
2+
3+
on:
4+
pull_request:
5+
branches: [ '*' ]
6+
7+
jobs:
8+
line-length-check:
9+
runs-on: ubuntu-latest
10+
name: Check 80 character line limit
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Check line length in PR changes
19+
run: |
20+
# Get the base branch (usually main/master)
21+
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
22+
23+
echo "Checking line length (max 80 characters) for changed files in " \
24+
"src/, examples/, and jni/ directories..."
25+
echo "================================================================"
26+
27+
# Create temporary files with unique names
28+
changed_files=$(mktemp)
29+
violations_file=$(mktemp)
30+
31+
# Get all changed files in this PR and filter for target directories
32+
git diff --name-only "origin/$BASE_BRANCH"...HEAD | \
33+
grep -E '^(src/|examples/|jni/)' > "$changed_files" || true
34+
35+
# Initialize violation count
36+
violation_count=0
37+
38+
# Check each changed file
39+
while IFS= read -r file; do
40+
if [[ -f "$file" ]]; then
41+
echo "Checking: $file"
42+
43+
# Get added lines with line numbers and check their length
44+
git diff "origin/$BASE_BRANCH"...HEAD "$file" | \
45+
grep -n -E '^\+[^+]' | \
46+
while IFS=':' read -r line_num added_line; do
47+
# Remove the leading +
48+
actual_line="${added_line:1}"
49+
char_count=${#actual_line}
50+
51+
if [[ $char_count -gt 80 ]]; then
52+
echo "❌ $file:$line_num - Line too long ($char_count characters)"
53+
echo " Line: $actual_line"
54+
echo "violation" >> "$violations_file"
55+
fi
56+
done
57+
fi
58+
done < "$changed_files"
59+
60+
# Count violations
61+
if [[ -f "$violations_file" ]]; then
62+
violation_count=$(grep -c "violation" "$violations_file" || echo 0)
63+
else
64+
violation_count=0
65+
fi
66+
67+
echo "================================================================"
68+
69+
if [[ $violation_count -gt 0 ]]; then
70+
echo "❌ Found $violation_count line(s) exceeding 80 " \
71+
"characters in PR changes"
72+
echo ""
73+
echo "Please ensure all lines are 80 characters or less " \
74+
"as per coding standards."
75+
echo "You can check line length in your editor or use this command:"
76+
echo " grep -n '.\{81,\}' <filename>"
77+
rm -f "$violations_file" "$changed_files"
78+
exit 1
79+
else
80+
echo "✅ All changed lines are within the 80 character limit"
81+
rm -f "$violations_file" "$changed_files"
82+
exit 0
83+
fi

0 commit comments

Comments
 (0)