-
Notifications
You must be signed in to change notification settings - Fork 12
277 lines (228 loc) · 10.1 KB
/
snowflake_regression_tests.yml
File metadata and controls
277 lines (228 loc) · 10.1 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: Docker tests
run-name: ${{ github.actor }} is running regression tests.
on:
push:
branches:
- '**'
pull_request:
types: [opened, synchronize, reopened]
jobs:
run-scripts:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
pgver: [15, 16, 17, 18]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up Docker
uses: docker/setup-buildx-action@v2
- name: Build Docker Image
run: |
docker build -t snowflake docker/
- name: Create Docker Network
run: |
docker network create pg_network || true
- name: Run Docker Container with Unique Port
run: |
PGPORT=$((5400 + ${{ matrix.pgver }})) # Assign unique ports (5415, 5416, 5417)
CONTAINER_NAME=snowflake-${{ matrix.pgver }} # Unique container name
echo "Starting PostgreSQL container: $CONTAINER_NAME on port $PGPORT"
docker run -d --name $CONTAINER_NAME --network pg_network \
-e PGPORT=$PGPORT \
-e POSTGRES_USER=postgres \
-e POSTGRES_DB=postgres \
-p $PGPORT:5432 snowflake || { echo "Failed to start container: $CONTAINER_NAME"; exit 1; }
- name: Wait for SSH to Start
run: |
CONTAINER_NAME=snowflake-${{ matrix.pgver }} # Match dynamic container name
echo "Waiting for SSH to start in container: $CONTAINER_NAME..."
for i in {1..10}; do
if docker exec $CONTAINER_NAME pgrep sshd > /dev/null 2>&1; then
echo "SSHD is running!"
exit 0
fi
echo "SSHD not ready, retrying..."
sleep 2
done
echo "SSHD failed to start in $CONTAINER_NAME!"
docker logs $CONTAINER_NAME # Print logs for debugging
exit 1
- name: Install System Dependencies Inside the Container
run: |
docker exec -u root snowflake-${{ matrix.pgver }} bash -c "
apt-get update && \
apt-get install -y \
build-essential \
libreadline-dev \
zlib1g-dev \
bison \
flex \
curl \
ca-certificates \
gcc \
git \
wget \
libicu-dev && \
rm -rf /var/lib/apt/lists/*
"
- name: Ensure Passwordless sudo for postgres user
run: |
echo "postgres ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/postgres
sudo chmod 0440 /etc/sudoers.d/postgres
sudo usermod -aG sudo postgres # Add postgres user to sudo group
- name: Clone the Postgres repo and list the files
run: |
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
sudo apt-get update && sudo apt-get install -y git && \
git clone https://github.com/postgres/postgres.git /home/postgres/postgres-source && \
cd /home/postgres/postgres-source
"
- name: Verify Cloned Postgres Repository
run: |
docker exec -u postgres snowflake-${{ matrix.pgver }} ls -la /home/postgres/postgres-source
- name: List all available tags in the cloned Postgres repository
run: |
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
cd /home/postgres/postgres-source && \
git fetch --tags && \
git tag -l
"
- name: Checkout the latest PostgreSQL tag that matches matrix.pgver
run: |
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
cd /home/postgres/postgres-source && \
git fetch --tags && \
MATRIX_PGVER=${{ matrix.pgver }} && \
LATEST_TAG=\$(git tag -l \"REL_\${MATRIX_PGVER}*\" | grep -Eo 'REL_[0-9]+_[0-9]+(_[0-9]+)?' | sort -V | tail -n 1) && \
git checkout \$LATEST_TAG && \
echo \"Checked out tag: \$LATEST_TAG\"
"
- name: Configure, build, and install PostgreSQL
run: |
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
cd /home/postgres/postgres-source && \
./configure --prefix=/usr/local/pgsql --without-icu && \
make -j\$(nproc) && \
sudo make install
"
- name: Create the PostgreSQL data directory
run: |
docker exec -u root snowflake-${{ matrix.pgver }} bash -c "
mkdir -p /var/lib/postgresql/data && \
chown -R postgres:postgres /var/lib/postgresql && \
chmod 700 /var/lib/postgresql/data
"
- name: Initialize PostgreSQL Cluster for matrix.pgver
run: |
PGPORT=$((5400 + ${{ matrix.pgver }})) # Assign a unique port
PGDATA_DIR="/var/lib/postgresql/data-${{ matrix.pgver }}" # Unique data directory
echo "Initializing PostgreSQL ${{ matrix.pgver }} Cluster..."
echo "Using PGDATA: $PGDATA_DIR"
echo "Using PGPORT: $PGPORT"
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
export PGDATA=$PGDATA_DIR && export PGPORT=$PGPORT
mkdir -p \$PGDATA
if [ ! -f \$PGDATA/PG_VERSION ]; then
echo 'Running initdb for PostgreSQL ${{ matrix.pgver }}...'
/usr/local/pgsql/bin/initdb -D \$PGDATA
fi
"
echo "PGPORT=$PGPORT" >> $GITHUB_ENV
echo "PGDATA=$PGDATA_DIR" >> $GITHUB_ENV
- name: Locate pg_config and Update PATH
run: |
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
PG_CONFIG_PATH=\$(find /usr/local/pgsql -type f -name pg_config | head -n 1) && \
if [ -z \"\$PG_CONFIG_PATH\" ]; then
echo 'Error: pg_config not found' && exit 1
fi && \
PG_BIN_DIR=\$(dirname \"\$PG_CONFIG_PATH\") && \
echo \"Found pg_config in: \$PG_BIN_DIR\" && \
echo \"export PATH=\$PG_BIN_DIR:\$PATH\" >> /home/postgres/.bashrc && \
echo \"export PATH=\$PG_BIN_DIR:\$PATH\" >> /home/postgres/.profile && \
echo \"pg_config location successfully added to PATH\" && \
export PATH=\$PG_BIN_DIR:\$PATH && \
pg_config
"
- name: Clone & Build Snowflake Extension
run: |
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
PG_CONFIG_PATH=\$(find /usr/local/pgsql -type f -name pg_config | head -n 1) && \
if [ -z \"\$PG_CONFIG_PATH\" ]; then \
echo 'Error: pg_config not found!' && exit 1; \
fi && \
export PATH=\$(dirname \"\$PG_CONFIG_PATH\"):\$PATH && \
echo \"pg_config location successfully added to PATH: \$(dirname \"\$PG_CONFIG_PATH\")\" && \
# Ensure contrib directory exists in Postgres source
cd /home/postgres/postgres-source/contrib && \
# Clone Snowflake extension if it doesn't exist
if [ ! -d \"snowflake\" ]; then \
echo 'Cloning Snowflake extension...' && \
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/pgEdge/snowflake.git snowflake; \
fi && \
# Move into the Snowflake extension directory
cd snowflake && \
# Build using PGXS
echo 'Building Snowflake extension...' && \
USE_PGXS=1 make
"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Make Install Snowflake as Root
run: |
docker exec -u root snowflake-${{ matrix.pgver }} bash -c "
PG_CONFIG_PATH=\$(find /usr/local/pgsql -type f -name pg_config | head -n 1) && \
if [ -z \"\$PG_CONFIG_PATH\" ]; then \
echo 'Error: pg_config not found!' && exit 1; \
fi && \
export PATH=\$(dirname \"\$PG_CONFIG_PATH\"):\$PATH && \
echo \"pg_config location successfully added to PATH: \$(dirname \"\$PG_CONFIG_PATH\")\" && \
# Verify Snowflake directory exists before installing
if [ ! -d \"/home/postgres/postgres-source/contrib/snowflake\" ]; then \
echo 'Error: Snowflake directory does not exist!'; \
exit 1; \
fi && \
cd /home/postgres/postgres-source/contrib/snowflake && \
# Install using PGXS
echo 'Installing Snowflake extension as root...' && \
USE_PGXS=1 make install
"
- name: Ensure PG is running, add Snowflake to shared_preload_libraries, and create extension
run: |
PGPORT=$((5400 + ${{ matrix.pgver }})) # Assign unique port per version
PGDATA_DIR="/var/lib/postgresql/data-${{ matrix.pgver }}" # Unique data dir per version
echo "Checking if PostgreSQL is running for PG ${{ matrix.pgver }} at port $PGPORT..."
docker exec -u postgres snowflake-${{ matrix.pgver }} bash -c "
export PGDATA=$PGDATA_DIR && export PGPORT=$PGPORT
PATH=/usr/local/pgsql/bin:$PATH # Ensure pg_isready is available
if ! /usr/local/pgsql/bin/pg_isready -p \$PGPORT; then
echo 'PostgreSQL is not ready. Starting it now...'
/usr/local/pgsql/bin/pg_ctl -D \$PGDATA -o \"-p \$PGPORT\" start && sleep 5
fi
echo 'Ensuring Snowflake parameter is set...'
/usr/local/pgsql/bin/psql -d postgres -p \$PGPORT -c \"ALTER SYSTEM SET shared_preload_libraries TO 'snowflake';\"
echo 'Restarting PostgreSQL to apply changes...'
/usr/local/pgsql/bin/pg_ctl -D \$PGDATA -o \"-p \$PGPORT\" restart && sleep 5
echo 'Verifying PostgreSQL is running...'
/usr/local/pgsql/bin/pg_isready -p \$PGPORT
echo 'PostgreSQL is running. Listing available extensions:'
/usr/local/pgsql/bin/psql -d postgres -p \$PGPORT -c 'SELECT * FROM pg_available_extensions;'
echo 'Creating Snowflake extension...'
/usr/local/pgsql/bin/psql -d postgres -p \$PGPORT -c 'CREATE EXTENSION snowflake;'
"
- name: Put your test cases here
run: |
echo "Current User: $(whoami)" > latest.log
echo "Current Path: $(pwd)" >> latest.log
cat latest.log
- name: Upload Log File as Artifact
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: latest-log-${{ matrix.pgver }}
path: latest.log