-
Notifications
You must be signed in to change notification settings - Fork 30
211 lines (177 loc) · 5.55 KB
/
Copy pathci.yml
File metadata and controls
211 lines (177 loc) · 5.55 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: CI
on:
push:
branches: [ master, main, develop ]
pull_request:
branches: [ master, main ]
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up environment
run: |
if [ "${{ matrix.compiler }}" = "gcc" ]; then
echo "CC=gcc" >> $GITHUB_ENV
else
echo "CC=clang" >> $GITHUB_ENV
fi
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y valgrind python3 python3-pip
pip3 install requests
- name: Build server
run: |
make clean
make
- name: Check for compilation warnings
run: |
make clean
make CFLAGS="-Wall -Wextra -Werror"
- name: Run unit tests
run: |
gcc -o tests/test_main tests/test_main.c main.c httpd.c -I. -DTESTING
./tests/test_main
- name: Run integration tests
run: |
python3 tests/integration_test.py
- name: Memory leak check
run: |
# Start server with valgrind
valgrind --leak-check=full --error-exitcode=1 --log-file=valgrind.log \
./server 9999 &
SERVER_PID=$!
# Wait for server
sleep 2
# Send test request
curl -s http://localhost:9999/ || true
# Stop server
kill -INT $SERVER_PID
wait $SERVER_PID || true
# Check results
echo "=== Valgrind Report ==="
cat valgrind.log
echo ""
# Check for memory leaks (multiple possible formats)
if grep -q "All heap blocks were freed -- no leaks are possible" valgrind.log || \
(grep -q "definitely lost: 0 bytes" valgrind.log && \
grep -q "indirectly lost: 0 bytes" valgrind.log); then
echo "✅ No memory leaks detected"
else
echo "❌ Memory leaks detected"
exit 1
fi
- name: Static analysis with compiler
run: |
$CC -Wall -Wextra -pedantic -fsyntax-only main.c httpd.c 2>&1 | tee static-analysis.log
if [ -s static-analysis.log ]; then
echo "⚠ Static analysis warnings found"
cat static-analysis.log
else
echo "✓ No static analysis warnings"
fi
- name: Upload artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-artifacts-${{ matrix.compiler }}
path: |
valgrind.log
static-analysis.log
tests/*.log
security-scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run cppcheck
run: |
sudo apt-get update
sudo apt-get install -y cppcheck
cppcheck --enable=all --error-exitcode=1 --suppress=missingIncludeSystem \
main.c httpd.c httpd.h 2>&1 | tee cppcheck.log || true
# Show results but don't fail build on warnings
if [ -s cppcheck.log ]; then
echo "⚠ Cppcheck found issues:"
cat cppcheck.log
else
echo "✓ No cppcheck issues found"
fi
- name: Check for common vulnerabilities
run: |
echo "Checking for common security issues..."
# Check for unsafe functions
if grep -r "gets\|sprintf\|strcpy\|strcat\|scanf" *.c *.h; then
echo "❌ Found usage of unsafe functions"
exit 1
else
echo "✓ No unsafe function usage found"
fi
# Check for TODO/FIXME related to security
if grep -ri "TODO.*security\|FIXME.*security\|XXX.*security" *.c *.h; then
echo "⚠ Found security-related TODOs"
else
echo "✓ No security TODOs found"
fi
documentation:
name: Documentation Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for required documentation
run: |
echo "Checking documentation..."
files="README.md CONTRIBUTING.md SECURITY.md CHANGELOG.md"
missing=""
for file in $files; do
if [ ! -f "$file" ]; then
missing="$missing $file"
fi
done
if [ -n "$missing" ]; then
echo "❌ Missing documentation files:$missing"
exit 1
else
echo "✓ All required documentation files present"
fi
- name: Validate markdown
run: |
echo "Checking markdown files..."
for file in *.md; do
if [ -f "$file" ]; then
# Basic check: file is not empty
if [ ! -s "$file" ]; then
echo "❌ $file is empty"
exit 1
fi
echo "✓ $file is valid"
fi
done
build-status:
name: Build Status
runs-on: ubuntu-latest
needs: [build-and-test, security-scan, documentation]
if: always()
steps:
- name: Check build status
run: |
if [ "${{ needs.build-and-test.result }}" = "success" ] && \
[ "${{ needs.security-scan.result }}" = "success" ] && \
[ "${{ needs.documentation.result }}" = "success" ]; then
echo "✅ All checks passed!"
exit 0
else
echo "❌ Some checks failed"
echo "Build and Test: ${{ needs.build-and-test.result }}"
echo "Security Scan: ${{ needs.security-scan.result }}"
echo "Documentation: ${{ needs.documentation.result }}"
exit 1
fi