Skip to content

Commit

Permalink
fix(workflow): exit if sql fails
Browse files Browse the repository at this point in the history
  • Loading branch information
smaspons authored Jul 29, 2024
1 parent 7b1fb43 commit df1c23a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/database_ws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,39 @@ jobs:
env:
PGPASSWORD: postgres
run: |
set -e # Exit immediately if a command exits with a non-zero status
# Define the root directories to process
root_directories=("utils" "ws" "i18n")
root_directories=("utils" "ws" "i18n/en_US")
# Function to execute SQL files and handle errors
execute_sql() {
local file=$1
echo "Executing $file..."
if ! psql -h localhost -U postgres -d giswater_test_db -f "$file" 2>&1; then
echo "Error executing $file"
exit 1
fi
}
# Process each root directory and its subdirectories
for root_dir in "${root_directories[@]}"; do
echo "Processing root directory: $root_dir"
find "$root_dir" -type f -name "*.sql" | sort | while read -r file; do
echo "Executing $file..."
psql -h localhost -U postgres -d giswater_test_db -f "$file"
execute_sql "$file"
done
done
# Define the base updates directory
updates_dir="updates/36"
# Check if the updates directory exists
if [ -d "$updates_dir" ]; then
# Process "utils" and "ws" subdirectories within updates_dir
find "$updates_dir" -type d -name "utils" -o -name "ws" | sort | while read -r subdir; do
echo "Processing directory: $subdir"
find "$subdir" -type f -name "*.sql" | sort | while read -r file; do
echo "Executing $file..."
psql -h localhost -U postgres -d giswater_test_db -f "$file"
execute_sql "$file"
done
done
else
Expand Down

0 comments on commit df1c23a

Please sign in to comment.