Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fail cleanup-dbt-resources workflow if databases do not exist #105

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/scripts/cleanup_dbt_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"
Loading