function metrics #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Java CI with LOC Counting | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout code | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Cache Maven dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/*.java') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Build with Maven | |
run: mvn clean install | |
- name: Run Checkstyle | |
run: mvn checkstyle:check | |
- name: Count Lines of Code | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y cloc | |
cloc --exclude-dir=target --quiet . # Exclude 'target' directory to avoid counting compiled files | |
- name: Measure Java Application Metrics | |
run: | | |
# Install jq for parsing JSON results (ensure it's installed) | |
sudo apt-get install -y jq | |
# Run tests and capture the output | |
mvn test | tee result.log | |
# Extract total test execution time in seconds (use the proper regex) | |
test_duration=$(grep -oP 'Total time: \K[0-9.]+' result.log) | |
echo "Test Execution Time: $test_duration seconds" | |
# Extract error rate (failed tests) | |
failed_tests=$(grep -c 'FAILURE' result.log) | |
total_tests=$(grep -c 'Tests run' result.log) | |
if [[ $total_tests -gt 0 ]]; then | |
error_rate=$(echo "scale=2; $failed_tests / $total_tests * 100" | bc) | |
else | |
error_rate=0 | |
fi | |
echo "Error Rate: $error_rate%" | |
# Extract throughput (tests per second) | |
if [[ $test_duration > 0 ]]; then | |
throughput=$(echo "scale=2; $total_tests / $test_duration" | bc) | |
else | |
throughput=0 | |
fi | |
echo "Throughput: $throughput tests per second" | |
# Measure memory usage with JVM options during test run | |
echo "Memory Usage (heap size):" | |
jps -v | grep 'java' | |
# Check method call count (assuming logging is implemented for call count) | |
call_count=$(grep -o 'methodCallCount' result.log | wc -l) | |
echo "Call Count: $call_count" | |
- name: Upload test results to GitHub | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-results | |
path: result.log |