From 41524a3d2066cd990f175d27e9db54b7eb21da09 Mon Sep 17 00:00:00 2001 From: Jean Cochrane Date: Thu, 31 Aug 2023 10:21:35 -0500 Subject: [PATCH] Do not fail cleanup-dbt-resources workflow if databases do not exist (#105) --- .github/scripts/cleanup_dbt_resources.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/scripts/cleanup_dbt_resources.sh b/.github/scripts/cleanup_dbt_resources.sh index 1f7e80199..47a76620b 100755 --- a/.github/scripts/cleanup_dbt_resources.sh +++ b/.github/scripts/cleanup_dbt_resources.sh @@ -9,6 +9,24 @@ # Assumes that jq is installed and available on the caller's path. set -euo pipefail +delete_database() { + output=$(aws glue delete-database --name "$1" 2>&1) + status=$? + if [ "$status" != "0" ]; then + echo "$output" + if [[ $output =~ "EntityNotFoundException" ]]; then + # This case is expected, since it's likely that not all models + # will be built during CI runs. Exit with a non-255 status so + # that xargs continues executing. + echo "Continuing execution due to expected 404 response." + exit 254 + else + exit 255 # Unexpected error; signal to xargs to quit + fi + fi +} +export -f delete_database # Make delete_database useable by xargs + if [[ "$#" -eq 0 ]]; then echo "Missing first argument representing dbt target" exit 1 @@ -32,7 +50,7 @@ echo "Deleting the following schemas from Athena:" echo echo "$schemas" -echo "$schemas" | xargs -i bash -c 'aws glue delete-database --name {} || exit 255' +echo "$schemas" | xargs -i bash -c 'delete_database {}' echo echo "Done!"