This repository was archived by the owner on May 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
182 lines (152 loc) · 6.61 KB
/
Copy pathci_test_ws_db.yml
File metadata and controls
182 lines (152 loc) · 6.61 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
name: CI Test WS database
on:
push:
branches: [main, release/**, feature/**]
tags: [v*]
pull_request:
branches: [main, release/**, feature/**]
workflow_dispatch:
inputs:
tests:
description: "Tests to run"
required: false
default: "all"
build_image:
description: "Build/push DB image"
required: false
default: "false"
permissions:
contents: read
packages: write
jobs:
ci_test_ws_db:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pg_version: [16, 17]
env:
# PGPASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
PGPASSWORD: postgres
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Show which PG version we're testing
run: echo "Testing on PostgreSQL version ${{ matrix.pg_version }}"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r test/requirements.txt
- name: Add PostgreSQL repository
run: |
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- name: Update apt-get & install PostgreSQL
run: |
sudo apt-get update
sudo apt-get install -y \
postgresql-${{ matrix.pg_version }} \
postgresql-${{ matrix.pg_version }}-postgis-3 \
postgresql-${{ matrix.pg_version }}-pgrouting \
postgresql-${{ matrix.pg_version }}-pgtap \
postgis
- name: Remove default Postgres clusters
run: |
for cluster in $(pg_lsclusters --no-header | awk '{print $1 ":" $2}'); do
ver=$(echo $cluster | cut -d':' -f1)
name=$(echo $cluster | cut -d':' -f2)
sudo pg_dropcluster --stop $ver $name || true
done
- name: Create & start PG cluster
run: |
# Choose a port based on matrix.pg_version and workflow type (WS)
if [ "${{ matrix.pg_version }}" = "16" ]; then
PORT=55432
else
PORT=55433
fi
# Ensure any existing cluster is stopped before creating new one
sudo pg_dropcluster --stop ${{ matrix.pg_version }} main || true
sudo pg_createcluster ${{ matrix.pg_version }} main --port=$PORT
sudo pg_ctlcluster ${{ matrix.pg_version }} main start
# Make the port visible to subsequent steps
echo "PORT=$PORT" >> $GITHUB_ENV
- name: Show running clusters
run: sudo pg_lsclusters
# Use the secret password here
- name: Set postgres password
run: |
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
- name: Create PostgreSQL Database
run: |
psql -h localhost -p ${{ env.PORT }} -U postgres -c "CREATE DATABASE gw_db;"
- name: Setup PostgreSQL extensions
run: |
psql -h localhost -p ${{ env.PORT }} -U postgres -d gw_db -c 'CREATE EXTENSION postgis;'
psql -h localhost -p ${{ env.PORT }} -U postgres -d gw_db -c 'CREATE EXTENSION pgrouting;'
psql -h localhost -p ${{ env.PORT }} -U postgres -d gw_db -c 'CREATE EXTENSION postgis_raster;'
psql -h localhost -p ${{ env.PORT }} -U postgres -d gw_db -c 'CREATE EXTENSION postgis_topology;'
psql -h localhost -p ${{ env.PORT }} -U postgres -d gw_db -c 'CREATE EXTENSION pgtap;'
- name: Replace variables in SQL files
run: python test/replace_vars.py ws
- name: Create Sample Schema
run: python test/execute_sql_files.py ws
- name: Run all SQL tests in sequence
run: |
TEST_GROUPS="${{ github.event.inputs.tests || 'all' }}"
EXIT_CODE=0
if [[ "$TEST_GROUPS" == "all" || "$TEST_GROUPS" == *"schema"* ]]; then
echo "Running SCHEMA tests..."
pg_prove -h localhost -p ${{ env.PORT }} -U postgres -d gw_db test/ws/schema/{tables,views}/*.sql || EXIT_CODE=1
fi
if [[ "$TEST_GROUPS" == "all" || "$TEST_GROUPS" == *"security"* ]]; then
echo "Running SECURITY tests..."
pg_prove -h localhost -p ${{ env.PORT }} -U postgres -d gw_db test/ws/security/*.sql || EXIT_CODE=1
fi
if [[ "$TEST_GROUPS" == "all" || "$TEST_GROUPS" == *"function"* ]]; then
echo "Running FUNCTION tests..."
pg_prove -h localhost -p ${{ env.PORT }} -U postgres -d gw_db test/ws/function/*.sql || EXIT_CODE=1
fi
if [[ "$TEST_GROUPS" == "all" || "$TEST_GROUPS" == *"data"* ]]; then
echo "Running DATA tests..."
pg_prove -h localhost -p ${{ env.PORT }} -U postgres -d gw_db test/ws/data/*.sql || EXIT_CODE=1
fi
if [[ "$TEST_GROUPS" == "all" || "$TEST_GROUPS" == *"performance"* ]]; then
echo "Running PERFORMANCE tests..."
pg_prove -h localhost -p ${{ env.PORT }} -U postgres -d gw_db test/ws/performance/*.sql || EXIT_CODE=1
fi
exit $EXIT_CODE
- name: Set image tag
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "IMAGE_TAG=main" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${GITHUB_REF_NAME//\//-}" >> $GITHUB_ENV
fi
- name: Dump DB for image
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_image == 'true'
run: |
/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_dump \
-h localhost -p ${{ env.PORT }} -U postgres -n ws_40 -Fc -f gw_ws.dump gw_db
- name: Log in to GHCR
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_image == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push DB image
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_image == 'true'
uses: docker/build-push-action@v6
with:
context: .
file: docker/gw-db/Dockerfile
push: true
tags: ghcr.io/giswater/gw-db:${{ env.IMAGE_TAG }}-pg${{ matrix.pg_version }}-ws
build-args: |
GW_DUMP=gw_ws.dump
PG_MAJOR=${{ matrix.pg_version }}