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

Fix cleanup-dbt-resources workflow to run on data-catalog branch #58

Merged

Conversation

jeancochrane
Copy link
Contributor

@jeancochrane jeancochrane commented Aug 8, 2023

The cleanup-dbt-resources workflow is currently failing on the data-catalog branch because GITHUB_REF_NAME appears to be set to data-catalog even though the workflow is triggered from a pull_request event:

Deleting the following schemas from Athena:

"ci_data-catalog_default"
"ci_data-catalog_location"

An error occurred (EntityNotFoundException) when calling the DeleteDatabase operation: Database ci_data-catalog_default not found.

This PR adjusts the configure-dbt-environment action to give higher priority to environments that have GITHUB_HEAD_REF set when setting the HEAD_REF variable for a pull request, since this variable is guaranteed to only be set on pull_request events, whereas GITHUB_REF_NAME can be set on both pull_request and push (docs).

@jeancochrane jeancochrane force-pushed the jeancochrane/fix-cleanup-dbt-resources-workflow branch from a08431e to fb9a6c8 Compare August 8, 2023 20:34
Comment on lines +32 to +33
echo "CI context did not match any of the expected environments"
exit 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fully intentional, but the build ended up testing this path when I accidentally referenced GITHUB_REF_NAME instead of GITHUB_HEAD_REF for this run: https://github.com/ccao-data/data-architecture/actions/runs/5801770404/job/15726741689

@jeancochrane jeancochrane marked this pull request as ready for review August 8, 2023 20:55
@jeancochrane jeancochrane requested a review from a team as a code owner August 8, 2023 20:55
Copy link
Member

@dfsnow dfsnow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice quickfix!

# GITHUB_HEAD_REF is only set on pull_request events, so if it's
# present, we must be in a PR context. Use the +x param expansion
# to distinguish empty strings: https://stackoverflow.com/a/13864829
if [ ! -z ${GITHUB_HEAD_REF+x} ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (non-blocking): Probably simpler to do: if [ -n "$GITHUB_HEAD_REF" ]; then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, done in 310645e! Why does bash have so many options for such a simple operation 🙃

@jeancochrane jeancochrane merged commit f617f52 into data-catalog Aug 8, 2023
3 checks passed
@jeancochrane jeancochrane deleted the jeancochrane/fix-cleanup-dbt-resources-workflow branch August 8, 2023 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants