Skip to content

Commit

Permalink
fix(workflows): add specific order in updates subdir
Browse files Browse the repository at this point in the history
  • Loading branch information
danimarinBG committed Aug 2, 2024
1 parent dda6211 commit 6c623f2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 68 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/database_ud.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create Giswater Schema (WS)
name: Create Giswater Schema SAMPLE (UD)

on:
push:
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
psql -h localhost -U postgres -d giswater_test_db -c 'CREATE EXTENSION postgis_raster;'
- name: Replace variables in SQL files
run: python test/replace_vars.py
run: python test/replace_vars.py ud

- name: Create sample schema
env:
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
fi
# Check features
arcs=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT count(*) FROM ws_36.v_edit_arc;")
arcs=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT count(*) FROM ud_36.v_edit_arc;")
if [ -z "$arcs" ]; then
echo "No arcs found in the v_edit_arc table."
exit 1
Expand Down
124 changes: 62 additions & 62 deletions .github/workflows/database_ws.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
name: Create Giswater Schema (WS)
name: Create Giswater Schema SAMPLE (WS)

on:
push:
branches: [ dev-3.6-manage-views ]
branches: [dev-3.6-manage-views]
pull_request:
branches: [ dev-3.6-manage-views ]
branches: [dev-3.6-manage-views]

jobs:
setup-and-test-db:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- 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: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r test/requirements.txt
- name: Setup PostgreSQL and PostGIS for Linux/macOS/Windows
uses: nyurik/[email protected]
with:
database: giswater_test_db

- name: Install pgrouting & postgis_raster
env:
PGPASSWORD: postgres
run: |
sudo apt-get install postgresql-14-pgrouting
psql -h localhost -U postgres -d giswater_test_db -c 'CREATE EXTENSION pgrouting;'
psql -h localhost -U postgres -d giswater_test_db -c 'CREATE EXTENSION postgis_raster;'
- name: Setup PostgreSQL and PostGIS for Linux/macOS/Windows
uses: nyurik/[email protected]
with:
database: giswater_test_db

- name: Replace variables in SQL files
run: python test/replace_vars.py
- name: Install pgrouting & postgis_raster
env:
PGPASSWORD: postgres
run: |
sudo apt-get install postgresql-14-pgrouting
psql -h localhost -U postgres -d giswater_test_db -c 'CREATE EXTENSION pgrouting;'
psql -h localhost -U postgres -d giswater_test_db -c 'CREATE EXTENSION postgis_raster;'
- name: Create sample schema
env:
PGPASSWORD: postgres
run: python test/execute_sql_files.py ws
- name: Replace variables in SQL files
run: python test/replace_vars.py ws

- name: Verify Database
env:
PGPASSWORD: postgres
run: |
# Check PostGIS version
postgis_version=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT postgis_full_version();")
if [ -z "$postgis_version" ]; then
echo "PostGIS extension not found or not installed correctly."
exit 1
else
echo "PostGIS version:"
echo "$postgis_version"
fi
- name: Create sample schema
env:
PGPASSWORD: postgres
run: python test/execute_sql_files.py ws

# Check pgRouting version
pgrouting_version=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT * FROM pgr_version();")
if [ -z "$pgrouting_version" ]; then
echo "pgRouting extension not found or not installed correctly."
exit 1
else
echo "pgRouting version:"
echo "$pgrouting_version"
fi
- name: Verify Database
env:
PGPASSWORD: postgres
run: |
# Check PostGIS version
postgis_version=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT postgis_full_version();")
if [ -z "$postgis_version" ]; then
echo "PostGIS extension not found or not installed correctly."
exit 1
else
echo "PostGIS version:"
echo "$postgis_version"
fi
# Check features
arcs=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT count(*) FROM ws_36.v_edit_arc;")
if [ -z "$arcs" ]; then
echo "No arcs found in the v_edit_arc table."
exit 1
else
echo "Arcs found:"
echo "$tables"
fi
# Check pgRouting version
pgrouting_version=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT * FROM pgr_version();")
if [ -z "$pgrouting_version" ]; then
echo "pgRouting extension not found or not installed correctly."
exit 1
else
echo "pgRouting version:"
echo "$pgrouting_version"
fi
# Check features
arcs=$(psql -h localhost -U postgres -d giswater_test_db -t -c "SELECT count(*) FROM ws_36.v_edit_arc;")
if [ -z "$arcs" ]; then
echo "No arcs found in the v_edit_arc table."
exit 1
else
echo "Arcs found:"
echo "$tables"
fi
4 changes: 3 additions & 1 deletion test/execute_sql_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ def main(project_type):
# Define the base updates directory
updates_dir = "updates/36"

order = ['utils', f"{project_type}"]

# Check if the updates directory exists and process it
if os.path.isdir(updates_dir):
for subdir in sorted(os.listdir(updates_dir)):
subdir_path = os.path.join(updates_dir, subdir)
# Check if the updates subdirectory exists and process it
if os.path.isdir(subdir_path):
for root, dirs, files in os.walk(subdir_path):
dirs[:] = sorted([d for d in dirs if d in ['utils', f"{project_type}"]])
dirs[:] = sorted([d for d in dirs if d in order], key=lambda x: order.index(x))
for file in sorted(files):
if file.endswith(".sql"):
file_path = os.path.join(root, file)
Expand Down
4 changes: 2 additions & 2 deletions test/replace_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def replace_vars_in_file(file_path, replacements):
with open(file_path, 'w') as file:
file.write(content)

def main():
def main(project_type):
sql_dir = './'
replacements = {
'SCHEMA_NAME': 'ws_36',
'SCHEMA_NAME': f'{project_type}_36',
'SRID_VALUE': '25831',
# Add more replacements as needed
}
Expand Down

0 comments on commit 6c623f2

Please sign in to comment.