Skip to content

Commit 7ece6ed

Browse files
committed
Testing: add GitHub action to make sure PRs are using multiline comments, not single line style. Helps us meet coding standards.
1 parent dc2b8e7 commit 7ece6ed

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Comment Style Check
2+
3+
on:
4+
pull_request:
5+
branches: [ '*' ]
6+
paths:
7+
- '**/*.java'
8+
- '**/*.c'
9+
- '**/*.h'
10+
11+
jobs:
12+
check-comment-style:
13+
runs-on: ubuntu-latest
14+
name: Check Multi-line Comment Style
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Get changed files
23+
id: changed-files
24+
run: |
25+
# Get list of changed .java and .c/.h files in this PR
26+
git diff --name-only --diff-filter=AM origin/${{ github.base_ref }}...HEAD | \
27+
grep -E '\.(java|c|h)$' > changed_files.txt || echo "No matching files found"
28+
29+
if [ -s changed_files.txt ]; then
30+
echo "Found changed files:"
31+
cat changed_files.txt
32+
echo "has_files=true" >> $GITHUB_OUTPUT
33+
else
34+
echo "No .java, .c, or .h files changed in this PR"
35+
echo "has_files=false" >> $GITHUB_OUTPUT
36+
fi
37+
38+
- name: Check for single-line comments in changed files
39+
if: steps.changed-files.outputs.has_files == 'true'
40+
run: |
41+
violations_found=false
42+
43+
while IFS= read -r file; do
44+
if [ -f "$file" ]; then
45+
echo "Checking $file for comment style violations..."
46+
47+
# Find potential single-line comments (//)
48+
# This is a simple check that may have some false positives
49+
# but catches the most common violations
50+
violations=$(grep -n '//' "$file" | \
51+
grep -v 'http://' | \
52+
grep -v 'https://' | \
53+
grep -v -E '/\*.*//.*\*/' | \
54+
grep -v -E '"[^"]*//[^"]*"' | \
55+
grep -E ':[[:space:]]*//' || true)
56+
57+
if [ -n "$violations" ]; then
58+
echo "❌ Single-line comments found in $file:"
59+
echo "$violations"
60+
echo ""
61+
violations_found=true
62+
else
63+
echo "✅ $file: No single-line comment violations found"
64+
fi
65+
fi
66+
done < changed_files.txt
67+
68+
if [ "$violations_found" = true ]; then
69+
echo ""
70+
echo "=================================="
71+
echo "❌ COMMENT STYLE CHECK FAILED"
72+
echo "=================================="
73+
echo ""
74+
echo "Single-line comments (//) were found in the changed files."
75+
echo "According to the coding standard in CLAUDE.md:"
76+
echo "- MUST only use multi-line comments, no \"//\" style ones"
77+
echo ""
78+
echo "Please replace all single-line comments (//) with multi-line comments (/* */)."
79+
echo ""
80+
echo "Examples:"
81+
echo " ❌ Bad: // This is a comment"
82+
echo " ✅ Good: /* This is a comment */"
83+
echo ""
84+
echo " ❌ Bad: // TODO: implement this"
85+
echo " ✅ Good: /* TODO: implement this */"
86+
echo ""
87+
exit 1
88+
else
89+
echo ""
90+
echo "=================================="
91+
echo "✅ COMMENT STYLE CHECK PASSED"
92+
echo "=================================="
93+
echo "All changed files follow the multi-line comment style standard."
94+
fi
95+
96+
- name: Comment style check skipped
97+
if: steps.changed-files.outputs.has_files == 'false'
98+
run: |
99+
echo "✅ Comment style check skipped - no .java, .c, or .h files were changed in this PR"

0 commit comments

Comments
 (0)