Skip to content

Commit 72851bf

Browse files
Issue (#1): Initial Commit.
1 parent 6272806 commit 72851bf

1 file changed

Lines changed: 175 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: C/C++ CI
2+
3+
on:
4+
push:
5+
branches: [ "main", "develop" ]
6+
pull_request:
7+
branches: [ "main", "develop" ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
postgresql-version: [12, 13, 14, 15, 16, 17]
16+
17+
services:
18+
postgres:
19+
image: postgres:${{ matrix.postgresql-version }}
20+
env:
21+
POSTGRES_PASSWORD: postgres
22+
POSTGRES_DB: testdb
23+
options: >-
24+
--health-cmd pg_isready
25+
--health-interval 10s
26+
--health-timeout 5s
27+
--health-retries 5
28+
ports:
29+
- 5432:5432
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
- name: Install system dependencies
36+
run: |
37+
sudo apt-get update
38+
sudo apt-get install -y \
39+
postgresql-${{ matrix.postgresql-version }} \
40+
postgresql-server-dev-${{ matrix.postgresql-version }} \
41+
postgresql-client-${{ matrix.postgresql-version }} \
42+
build-essential \
43+
make \
44+
gcc \
45+
libc6-dev \
46+
pkg-config \
47+
libpq-dev \
48+
git \
49+
curl \
50+
valgrind
51+
52+
- name: Set up PostgreSQL environment
53+
run: |
54+
sudo systemctl start postgresql
55+
sudo systemctl enable postgresql
56+
sudo -u postgres psql -c "CREATE DATABASE testdb;"
57+
sudo -u postgres psql -c "CREATE USER testuser WITH PASSWORD 'testpass';"
58+
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;"
59+
sudo -u postgres psql -c "ALTER USER testuser CREATEDB;"
60+
61+
- name: Build pgraft extension
62+
run: |
63+
cd pgraft
64+
make clean
65+
make
66+
echo "pgraft extension built successfully"
67+
68+
- name: Build ramd daemon
69+
run: |
70+
cd ramd
71+
make clean
72+
make
73+
echo "ramd daemon built successfully"
74+
75+
- name: Build ramctrl utility
76+
run: |
77+
cd ramctrl
78+
make clean
79+
make
80+
echo "ramctrl utility built successfully"
81+
82+
- name: Install pgraft extension
83+
run: |
84+
cd pgraft
85+
sudo make install
86+
87+
- name: Test pgraft extension loading
88+
run: |
89+
sudo -u postgres psql -d testdb -c "CREATE EXTENSION IF NOT EXISTS pgraft;"
90+
echo "pgraft extension loaded successfully"
91+
92+
- name: Test pgraft core functions
93+
run: |
94+
sudo -u postgres psql -d testdb -c "SELECT pgraft_version();"
95+
sudo -u postgres psql -d testdb -c "SELECT pgraft_init(1, 'localhost', 5432);"
96+
sudo -u postgres psql -d testdb -c "SELECT pgraft_start();"
97+
sudo -u postgres psql -d testdb -c "SELECT pgraft_get_state();"
98+
sudo -u postgres psql -d testdb -c "SELECT pgraft_is_leader();"
99+
echo "Core functions test passed"
100+
101+
- name: Test pgraft monitoring functions
102+
run: |
103+
sudo -u postgres psql -d testdb -c "SELECT pgraft_get_cluster_health();"
104+
sudo -u postgres psql -d testdb -c "SELECT pgraft_get_performance_metrics();"
105+
sudo -u postgres psql -d testdb -c "SELECT pgraft_is_cluster_healthy();"
106+
sudo -u postgres psql -d testdb -c "SELECT pgraft_get_system_stats();"
107+
sudo -u postgres psql -d testdb -c "SELECT pgraft_get_quorum_status();"
108+
echo "Monitoring functions test passed"
109+
110+
- name: Test pgraft log operations
111+
run: |
112+
sudo -u postgres psql -d testdb -c "SELECT pgraft_append_log('test data 1');"
113+
sudo -u postgres psql -d testdb -c "SELECT pgraft_append_log('test data 2');"
114+
sudo -u postgres psql -d testdb -c "SELECT pgraft_read_log(1);"
115+
sudo -u postgres psql -d testdb -c "SELECT pgraft_commit_log(2);"
116+
echo "Log operations test passed"
117+
118+
- name: Test pgraft cluster operations
119+
run: |
120+
sudo -u postgres psql -d testdb -c "SELECT pgraft_add_node(2, 'localhost', 5433);"
121+
sudo -u postgres psql -d testdb -c "SELECT pgraft_add_node(3, 'localhost', 5434);"
122+
sudo -u postgres psql -d testdb -c "SELECT pgraft_get_leader();"
123+
sudo -u postgres psql -d testdb -c "SELECT pgraft_get_term();"
124+
echo "Cluster operations test passed"
125+
126+
- name: Run memory check on pgraft
127+
run: |
128+
cd pgraft
129+
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt make test 2>&1 || true
130+
cat valgrind-out.txt || echo "Valgrind completed"
131+
132+
- name: Check for memory leaks
133+
run: |
134+
if [ -f pgraft/valgrind-out.txt ]; then
135+
if grep -q "definitely lost" pgraft/valgrind-out.txt; then
136+
echo "Memory leaks detected:"
137+
grep "definitely lost" pgraft/valgrind-out.txt
138+
exit 1
139+
else
140+
echo "No memory leaks detected"
141+
fi
142+
fi
143+
144+
- name: Test ramd daemon
145+
run: |
146+
cd ramd
147+
timeout 5s ./ramd --help || echo "ramd help test completed"
148+
echo "ramd daemon test passed"
149+
150+
- name: Test ramctrl utility
151+
run: |
152+
cd ramctrl
153+
timeout 5s ./ramctrl --help || echo "ramctrl help test completed"
154+
echo "ramctrl utility test passed"
155+
156+
- name: Run static analysis
157+
run: |
158+
find . -name "*.c" -o -name "*.h" | xargs cppcheck --enable=all --inconclusive --std=c99 --suppress=missingIncludeSystem 2>&1 || true
159+
echo "Static analysis completed"
160+
161+
- name: Check code formatting
162+
run: |
163+
find . -name "*.c" -o -name "*.h" | xargs grep -n "if(" || true
164+
find . -name "*.c" -o -name "*.h" | xargs grep -n "for(" || true
165+
find . -name "*.c" -o -name "*.h" | xargs grep -n "while(" || true
166+
echo "Code formatting check completed"
167+
168+
- name: Upload test results
169+
uses: actions/upload-artifact@v4
170+
if: always()
171+
with:
172+
name: test-results-postgresql-${{ matrix.postgresql-version }}
173+
path: |
174+
pgraft/valgrind-out.txt
175+
*/test-results.txt

0 commit comments

Comments
 (0)