Skip to content

Commit b2555d4

Browse files
authored
Merge pull request #285 from rlm2002/ghWolfCryptJNIActions
TEST: comment style check, line length check, and scan-build from wolfCrypt JNI
2 parents e23ff98 + cf81eb2 commit b2555d4

4 files changed

Lines changed: 309 additions & 1 deletion

File tree

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"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 native/ 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/|native/)' > "$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+
# Skip WolfSSLProvider.java...
42+
# that legitimately exceed 80 characters
43+
if [[ "$file" == "src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java" ]]; then
44+
echo "⚠️ Skipping $file (contains security service mappings)"
45+
continue
46+
fi
47+
48+
echo "Checking: $file"
49+
50+
# Get added lines with actual file line numbers and check their length
51+
new_line_num=0
52+
git diff "origin/$BASE_BRANCH"...HEAD "$file" | \
53+
while IFS= read -r line; do
54+
# Track line numbers from diff headers - format: @@ -old_start,old_count +new_start,new_count @@
55+
if [[ "$line" =~ ^@@.*\+([0-9]+) ]]; then
56+
# Extract starting line number for new file (after +)
57+
# Subtract 1 because we'll increment before processing first line
58+
new_line_num=$((${BASH_REMATCH[1]} - 1))
59+
elif [[ "$line" =~ ^(\+[^+].*) ]]; then
60+
# This is an added line (not a +++ header)
61+
# Increment line number BEFORE processing (since this line exists in new file)
62+
new_line_num=$((new_line_num + 1))
63+
added_line="${line:1}" # Remove leading +
64+
char_count=${#added_line}
65+
66+
# Skip JNI method signatures and calls to avoid false positives
67+
# These are auto-generated names that can't be shortened
68+
if [[ $char_count -gt 80 ]]; then
69+
# Check if this is a JNI method signature, call, or parameter line that should be ignored
70+
if [[ "$added_line" =~ JNIEXPORT.*JNICALL.*Java_com_wolfssl_ ]] || \
71+
[[ "$added_line" =~ Java_com_wolfssl_.*\( ]] || \
72+
[[ "$added_line" =~ ^[[:space:]]*return[[:space:]]+Java_com_wolfssl_.* ]] || \
73+
[[ "$added_line" =~ ^[[:space:]]*\(JNIEnv\*[[:space:]]+env.*\) ]] || \
74+
[[ "$added_line" =~ ^[[:space:]]*JNIEnv\*[[:space:]]+env.* ]]; then
75+
echo "⚠️ $file:$new_line_num - Skipping JNI method signature/call/parameters ($char_count characters)"
76+
echo " Line: $added_line"
77+
else
78+
echo "❌ $file:$new_line_num - Line too long ($char_count characters)"
79+
echo " Line: $added_line"
80+
echo "violation" >> "$violations_file"
81+
fi
82+
fi
83+
elif [[ "$line" =~ ^[[:space:]] ]]; then
84+
# Context line (unchanged) - increment new file line number
85+
new_line_num=$((new_line_num + 1))
86+
# Removed lines (starting with -) don't affect new file line numbers
87+
fi
88+
done
89+
fi
90+
done < "$changed_files"
91+
92+
# Count violations
93+
if [[ -f "$violations_file" ]]; then
94+
violation_count=$(grep -c "violation" "$violations_file" || echo 0)
95+
else
96+
violation_count=0
97+
fi
98+
99+
echo "================================================================"
100+
101+
if [[ $violation_count -gt 0 ]]; then
102+
echo "❌ Found $violation_count line(s) exceeding 80 " \
103+
"characters in PR changes"
104+
echo ""
105+
echo "Please ensure all lines are 80 characters or less " \
106+
"as per coding standards."
107+
echo "You can check line length in your editor or use this command:"
108+
echo " grep -n '.\{81,\}' <filename>"
109+
rm -f "$violations_file" "$changed_files"
110+
exit 1
111+
else
112+
echo "✅ All changed lines are within the 80 character limit"
113+
rm -f "$violations_file" "$changed_files"
114+
exit 0
115+
fi

.github/workflows/scan-build.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Clang Static Analyzer (scan-build)
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
scan-build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
# Install scan-build (part of clang-tools)
16+
- name: Install scan-build
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y clang-tools
20+
21+
# Cache Junit JARs
22+
- name: Cache Junit JARs
23+
uses: actions/cache@v3
24+
id: cache-junit
25+
with:
26+
path: ${{ github.workspace }}/junit
27+
key: junit-cache-${{ runner.os }}-junit-4.13.2-hamcrest-1.3
28+
restore-keys: |
29+
junit-cache-${{ runner.os }}-
30+
31+
# Download Junit JARs (needed for full build)
32+
- name: Download junit-4.13.2.jar
33+
if: steps.cache-junit.outputs.cache-hit != 'true'
34+
run: wget --directory-prefix=$GITHUB_WORKSPACE/junit https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
35+
- name: Download hamcrest-all-1.3.jar
36+
if: steps.cache-junit.outputs.cache-hit != 'true'
37+
run: wget --directory-prefix=$GITHUB_WORKSPACE/junit https://repo1.maven.org/maven2/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar
38+
39+
# Build native wolfSSL
40+
- name: Build native wolfSSL
41+
uses: wolfSSL/actions-build-autotools-project@v1
42+
with:
43+
repository: wolfSSL/wolfssl
44+
ref: master
45+
path: wolfssl
46+
configure: '--enable-jni --enable-all'
47+
check: false
48+
install: true
49+
50+
# Setup Java
51+
- name: Setup java
52+
uses: actions/setup-java@v4
53+
with:
54+
distribution: 'zulu'
55+
java-version: '11'
56+
57+
- name: Set JUNIT_HOME
58+
run: |
59+
echo "JUNIT_HOME=$GITHUB_WORKSPACE/junit" >> "$GITHUB_ENV"
60+
- name: Set LD_LIBRARY_PATH
61+
run: |
62+
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
63+
64+
# Run scan-build over the native JNI C files
65+
- name: Run scan-build
66+
env:
67+
PREFIX: ${{ github.workspace }}/build-dir
68+
run: |
69+
scan-build --status-bugs -o scan-build-reports make
70+
71+
# Upload scan-build results as artifacts
72+
- name: Upload scan-build results
73+
if: always()
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: scan-build-reports
77+
path: scan-build-reports/
78+
79+
# Show scan-build results in logs
80+
- name: Show scan-build results
81+
if: always()
82+
run: |
83+
if [ -d "scan-build-reports" ]; then
84+
echo "=== Scan-build analysis complete ==="
85+
find scan-build-reports -name "*.html" -exec echo "Report: {}" \;
86+
if find scan-build-reports -name "*.html" | head -1 | xargs grep -l "No bugs found" > /dev/null 2>&1; then
87+
echo "✅ No static analysis issues found"
88+
else
89+
echo "⚠️ Static analysis issues detected - check artifacts"
90+
find scan-build-reports -name "*.txt" -exec cat {} \; || true
91+
fi
92+
else
93+
echo "No scan-build reports generated"
94+
fi

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ endif
2121
all: build
2222

2323
build:
24-
./java.sh
24+
./java.sh $(INSTALL_DIR)
2525
ant
2626

2727
install:

0 commit comments

Comments
 (0)