-
Notifications
You must be signed in to change notification settings - Fork 2
82 lines (67 loc) · 2.42 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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