Skip to content

Commit ab11877

Browse files
cursoragentNikolayS
andcommitted
Update CI to test multiple PostgreSQL versions with improved configuration
Co-authored-by: nik <[email protected]>
1 parent d189092 commit ab11877

File tree

1 file changed

+171
-48
lines changed

1 file changed

+171
-48
lines changed

.github/workflows/test.yml

Lines changed: 171 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,97 +12,220 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
test-name: ['postgres-dba-tests']
15+
postgres-version: ['13', '14', '15', '16', '17']
1616
fail-fast: false
1717

18+
services:
19+
postgres:
20+
image: postgres:${{ matrix.postgres-version }}
21+
env:
22+
POSTGRES_PASSWORD: postgres
23+
POSTGRES_DB: test
24+
options: >-
25+
--health-cmd pg_isready
26+
--health-interval 10s
27+
--health-timeout 5s
28+
--health-retries 5
29+
ports:
30+
- 5432:5432
31+
1832
steps:
1933
- name: Checkout code
2034
uses: actions/checkout@v4
2135

22-
- name: Start PostgreSQL and configure
36+
- name: Install PostgreSQL client
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y postgresql-client
40+
41+
- name: Configure PostgreSQL for pg_stat_statements
2342
run: |
24-
# Stop default PostgreSQL if running
25-
sudo systemctl stop postgresql.service || true
43+
# Wait for PostgreSQL to be ready
44+
until pg_isready -h localhost -p 5432 -U postgres; do
45+
echo "Waiting for postgres..."
46+
sleep 2
47+
done
2648
27-
# Find PostgreSQL config files
28-
echo "PostgreSQL config files:"
29-
find /etc/postgresql -name "postgresql.conf" -type f
30-
find /etc/postgresql -name "pg_hba.conf" -type f
49+
# Get container ID and configure shared_preload_libraries
50+
CONTAINER_ID=$(docker ps --filter "expose=5432" --format "{{.ID}}")
51+
echo "PostgreSQL container: $CONTAINER_ID"
3152
32-
# Configure PostgreSQL for pg_stat_statements (multiple approaches to ensure it works)
33-
sudo sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = 'pg_stat_statements'/" /etc/postgresql/*/main/postgresql.conf || true
34-
sudo sed -i "s/^#shared_preload_libraries = ''/shared_preload_libraries = 'pg_stat_statements'/" /etc/postgresql/*/main/postgresql.conf || true
35-
sudo bash -c "echo \"shared_preload_libraries = 'pg_stat_statements'\" >> /etc/postgresql/*/main/postgresql.conf"
53+
# Configure shared_preload_libraries in postgresql.conf
54+
docker exec $CONTAINER_ID bash -c "echo \"shared_preload_libraries = 'pg_stat_statements'\" >> /var/lib/postgresql/data/postgresql.conf"
3655
37-
# Show the final configuration
38-
echo "Final postgresql.conf shared_preload_libraries setting:"
39-
grep -n "shared_preload_libraries" /etc/postgresql/*/main/postgresql.conf || echo "Not found"
56+
# Configure pg_hba.conf for trust authentication
57+
docker exec $CONTAINER_ID bash -c "echo 'local all all trust' > /var/lib/postgresql/data/pg_hba.conf"
4058
41-
# Set trust authentication for local connections
42-
sudo bash -c "echo 'local all all trust' > /etc/postgresql/*/main/pg_hba.conf"
59+
# Restart PostgreSQL to load the configuration
60+
docker restart $CONTAINER_ID
4361
44-
# Start PostgreSQL
45-
sudo systemctl start postgresql.service
46-
pg_isready
62+
# Wait for PostgreSQL to be ready after restart
63+
until pg_isready -h localhost -p 5432 -U postgres; do
64+
echo "Waiting for postgres to restart..."
65+
sleep 2
66+
done
4767
48-
# Create runner user and test database
49-
sudo -u postgres createuser -s runner
50-
sudo -u postgres createdb test
68+
echo "PostgreSQL ${{ matrix.postgres-version }} configured successfully"
5169
5270
- name: Prepare test database
5371
run: |
54-
# Check PostgreSQL version and available extensions
55-
sudo -u postgres psql -d test -c 'SELECT version();'
56-
sudo -u postgres psql -d test -c 'SELECT * FROM pg_available_extensions WHERE name IN ('"'"'pg_stat_statements'"'"', '"'"'pgstattuple'"'"');'
72+
# Check PostgreSQL version
73+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c 'SELECT version();'
5774
58-
# Create extensions (they need to be created by superuser)
59-
sudo -u postgres psql -d test -c 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements;'
60-
sudo -u postgres psql -d test -c 'CREATE EXTENSION IF NOT EXISTS pgstattuple;'
75+
# Create extensions
76+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements;'
77+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pgstattuple;'
6178
62-
# Verify extensions are created
63-
sudo -u postgres psql -d test -c 'SELECT * FROM pg_extension;'
79+
# Verify extensions
80+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c 'SELECT extname FROM pg_extension;'
6481
65-
# Create test tables
66-
psql -d test -c "CREATE TABLE align1 AS SELECT 1::int4, 2::int8, 3::int4 AS more FROM generate_series(1, 100000) _(i);"
67-
psql -d test -c "CREATE TABLE align2 AS SELECT 1::int4, 3::int4 AS more, 2::int8 FROM generate_series(1, 100000) _(i);"
82+
# Create test tables (exactly as in CircleCI)
83+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c "CREATE TABLE align1 AS SELECT 1::int4, 2::int8, 3::int4 AS more FROM generate_series(1, 100000) _(i);"
84+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c "CREATE TABLE align2 AS SELECT 1::int4, 3::int4 AS more, 2::int8 FROM generate_series(1, 100000) _(i);"
6885
6986
- name: Test wide mode
7087
run: |
7188
echo "\set postgres_dba_wide true" > ~/.psqlrc
7289
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
90+
echo "Testing all SQL files in wide mode..."
7391
for f in sql/*; do
74-
echo "Testing $f in wide mode..."
75-
if ! psql -d test -f warmup.psql -f "$f" > /dev/null 2>&1; then
76-
echo "FAILED: $f in wide mode"
77-
psql -d test -f warmup.psql -f "$f"
92+
echo " Testing $f..."
93+
if ! PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f "$f" > /dev/null 2>&1; then
94+
echo "❌ FAILED: $f in wide mode"
95+
echo "Error output:"
96+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f "$f"
7897
exit 1
7998
fi
8099
done
100+
echo "✅ All tests passed in wide mode"
81101
82102
- name: Test normal mode
83103
run: |
84104
echo "\set postgres_dba_wide false" > ~/.psqlrc
85105
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
106+
echo "Testing all SQL files in normal mode..."
86107
for f in sql/*; do
87-
echo "Testing $f in normal mode..."
88-
if ! psql -d test -f warmup.psql -f "$f" > /dev/null 2>&1; then
89-
echo "FAILED: $f in normal mode"
90-
psql -d test -f warmup.psql -f "$f"
108+
echo " Testing $f..."
109+
if ! PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f "$f" > /dev/null 2>&1; then
110+
echo "❌ FAILED: $f in normal mode"
111+
echo "Error output:"
112+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f "$f"
91113
exit 1
92114
fi
93115
done
116+
echo "✅ All tests passed in normal mode"
94117
95118
- name: Run regression tests
96119
run: |
97120
echo "\set postgres_dba_wide false" > ~/.psqlrc
98121
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
99122
100-
echo "Running regression test for 0_node.sql..."
101-
diff -b test/regression/0_node.out <(psql -d test -f warmup.psql -f sql/0_node.sql | grep Role)
123+
echo "Running regression tests..."
124+
125+
echo " Testing 0_node.sql..."
126+
diff -b test/regression/0_node.out <(PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f sql/0_node.sql | grep Role)
102127
103-
echo "Running regression test for p1_alignment_padding.sql..."
104-
diff -b test/regression/p1_alignment_padding.out <(psql -d test -f warmup.psql -f sql/p1_alignment_padding.sql | grep align)
128+
echo " Testing p1_alignment_padding.sql..."
129+
diff -b test/regression/p1_alignment_padding.out <(PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f sql/p1_alignment_padding.sql | grep align)
130+
131+
echo " Testing a1_activity.sql..."
132+
diff -b test/regression/a1_activity.out <(PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f sql/a1_activity.sql | grep User)
133+
134+
echo "✅ All regression tests passed"
135+
136+
test-beta:
137+
runs-on: ubuntu-latest
138+
continue-on-error: true # Allow beta tests to fail without breaking CI
139+
140+
strategy:
141+
matrix:
142+
postgres-version: ['18-beta']
143+
fail-fast: false
144+
145+
services:
146+
postgres:
147+
image: postgres:${{ matrix.postgres-version }}
148+
env:
149+
POSTGRES_PASSWORD: postgres
150+
POSTGRES_DB: test
151+
options: >-
152+
--health-cmd pg_isready
153+
--health-interval 10s
154+
--health-timeout 5s
155+
--health-retries 5
156+
ports:
157+
- 5432:5432
158+
159+
steps:
160+
- name: Checkout code
161+
uses: actions/checkout@v4
162+
163+
- name: Install PostgreSQL client
164+
run: |
165+
sudo apt-get update
166+
sudo apt-get install -y postgresql-client
167+
168+
- name: Configure PostgreSQL for pg_stat_statements
169+
run: |
170+
# Wait for PostgreSQL to be ready
171+
until pg_isready -h localhost -p 5432 -U postgres; do
172+
echo "Waiting for postgres..."
173+
sleep 2
174+
done
105175
106-
echo "Running regression test for a1_activity.sql..."
107-
diff -b test/regression/a1_activity.out <(psql -d test -f warmup.psql -f sql/a1_activity.sql | grep User)
176+
# Get container ID and configure shared_preload_libraries
177+
CONTAINER_ID=$(docker ps --filter "expose=5432" --format "{{.ID}}")
178+
echo "PostgreSQL container: $CONTAINER_ID"
179+
180+
# Configure shared_preload_libraries in postgresql.conf
181+
docker exec $CONTAINER_ID bash -c "echo \"shared_preload_libraries = 'pg_stat_statements'\" >> /var/lib/postgresql/data/postgresql.conf"
182+
183+
# Configure pg_hba.conf for trust authentication
184+
docker exec $CONTAINER_ID bash -c "echo 'local all all trust' > /var/lib/postgresql/data/pg_hba.conf"
185+
186+
# Restart PostgreSQL to load the configuration
187+
docker restart $CONTAINER_ID
188+
189+
# Wait for PostgreSQL to be ready after restart
190+
until pg_isready -h localhost -p 5432 -U postgres; do
191+
echo "Waiting for postgres to restart..."
192+
sleep 2
193+
done
194+
195+
echo "PostgreSQL ${{ matrix.postgres-version }} configured successfully"
196+
197+
- name: Prepare test database
198+
run: |
199+
# Check PostgreSQL version
200+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c 'SELECT version();'
201+
202+
# Create extensions
203+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements;'
204+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pgstattuple;'
205+
206+
# Create test tables
207+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c "CREATE TABLE align1 AS SELECT 1::int4, 2::int8, 3::int4 AS more FROM generate_series(1, 100000) _(i);"
208+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -c "CREATE TABLE align2 AS SELECT 1::int4, 3::int4 AS more, 2::int8 FROM generate_series(1, 100000) _(i);"
209+
210+
- name: Test wide mode (beta)
211+
run: |
212+
echo "\set postgres_dba_wide true" > ~/.psqlrc
213+
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
214+
echo "Testing all SQL files in wide mode (PostgreSQL 18 beta)..."
215+
for f in sql/*; do
216+
echo " Testing $f..."
217+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f "$f" > /dev/null 2>&1 || echo " ⚠️ Warning: $f failed in wide mode (beta)"
218+
done
219+
echo "✅ Wide mode tests completed (beta)"
220+
221+
- name: Test normal mode (beta)
222+
run: |
223+
echo "\set postgres_dba_wide false" > ~/.psqlrc
224+
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
225+
echo "Testing all SQL files in normal mode (PostgreSQL 18 beta)..."
226+
for f in sql/*; do
227+
echo " Testing $f..."
228+
PGPASSWORD=postgres psql -h localhost -U postgres -d test -f warmup.psql -f "$f" > /dev/null 2>&1 || echo " ⚠️ Warning: $f failed in normal mode (beta)"
229+
done
230+
echo "✅ Normal mode tests completed (beta)"
108231

0 commit comments

Comments
 (0)