From 6c623f2aa2c90c3456506a517ae56cff97177085 Mon Sep 17 00:00:00 2001 From: Daniel Marin Date: Fri, 2 Aug 2024 09:55:20 +0200 Subject: [PATCH] fix(workflows): add specific order in updates subdir --- .github/workflows/database_ud.yml | 6 +- .github/workflows/database_ws.yml | 124 +++++++++++++++--------------- test/execute_sql_files.py | 4 +- test/replace_vars.py | 4 +- 4 files changed, 70 insertions(+), 68 deletions(-) diff --git a/.github/workflows/database_ud.yml b/.github/workflows/database_ud.yml index ea1d7b1023..e2dce411c1 100644 --- a/.github/workflows/database_ud.yml +++ b/.github/workflows/database_ud.yml @@ -1,4 +1,4 @@ -name: Create Giswater Schema (WS) +name: Create Giswater Schema SAMPLE (UD) on: push: @@ -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: @@ -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 diff --git a/.github/workflows/database_ws.yml b/.github/workflows/database_ws.yml index a60c9c0f87..1bcc9de374 100644 --- a/.github/workflows/database_ws.yml +++ b/.github/workflows/database_ws.yml @@ -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/action-setup-postgis@v2.1 - 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/action-setup-postgis@v2.1 + 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 diff --git a/test/execute_sql_files.py b/test/execute_sql_files.py index 89dfe3ade7..0b88f1390b 100644 --- a/test/execute_sql_files.py +++ b/test/execute_sql_files.py @@ -69,6 +69,8 @@ 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)): @@ -76,7 +78,7 @@ def main(project_type): # 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) diff --git a/test/replace_vars.py b/test/replace_vars.py index d88d92480c..2d6e946c0c 100644 --- a/test/replace_vars.py +++ b/test/replace_vars.py @@ -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 }