diff --git a/.github/actions/configure_dbt_environment/action.yaml b/.github/actions/configure_dbt_environment/action.yaml index b9415701b..89bbf7eae 100644 --- a/.github/actions/configure_dbt_environment/action.yaml +++ b/.github/actions/configure_dbt_environment/action.yaml @@ -5,7 +5,17 @@ runs: steps: - name: Configure dbt environment run: | - if [[ $GITHUB_REF_NAME == 'master' ]]; then + # GITHUB_REF_NAME is only set on pull_request events, so if it's + # present, we must be in a PR context. Use the +x param expansion: + # https://stackoverflow.com/a/13864829 + if [-z ${GITHUB_REF_NAME+x} ]; then + echo "On pull request branch, setting dbt env to CI" + { + echo "TARGET=ci"; + echo "CACHE_KEY=$GITHUB_HEAD_REF"; + echo "HEAD_REF=$GITHUB_HEAD_REF" + } >> "$GITHUB_ENV" + elif [[ $GITHUB_REF_NAME == 'master' ]]; then echo "On master branch, setting dbt env to prod" { echo "TARGET=prod"; @@ -19,11 +29,7 @@ runs: echo "HEAD_REF=data-catalog"; } >> "$GITHUB_ENV" else - echo "On pull request branch, setting dbt env to CI" - { - echo "TARGET=ci"; - echo "CACHE_KEY=$GITHUB_HEAD_REF"; - echo "HEAD_REF=$GITHUB_HEAD_REF" - } >> "$GITHUB_ENV" + echo "CI context did not match any of the expected environments" + exit 1 fi shell: bash