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