|
65 | 65 | run: |
66 | 66 | working-directory: elementary |
67 | 67 | concurrency: |
68 | | - # This is what eventually defines the schema name in the data platform. |
| 68 | + # Serialises runs for the same warehouse × dbt-version × branch. |
| 69 | + # The schema name is derived from a hash of this group (see "Write dbt profiles"). |
69 | 70 | group: tests_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}_${{ github.head_ref || github.ref_name }} |
70 | 71 | cancel-in-progress: true |
71 | 72 | steps: |
@@ -114,12 +115,28 @@ jobs: |
114 | 115 |
|
115 | 116 | - name: Write dbt profiles |
116 | 117 | env: |
117 | | - PROFILES_YML: ${{ secrets.CI_PROFILES_YML }} |
| 118 | + CI_WAREHOUSE_SECRETS: ${{ secrets.CI_WAREHOUSE_SECRETS || '' }} |
118 | 119 | run: | |
119 | | - mkdir -p ~/.dbt |
120 | | - DBT_VERSION=$(pip show dbt-core | grep -i version | awk '{print $2}' | sed 's/\.//g') |
121 | | - UNDERSCORED_REF_NAME=$(echo "${{ inputs.warehouse-type }}_dbt_${DBT_VERSION}_${BRANCH_NAME}" | awk '{print tolower($0)}' | head -c 40 | sed "s/[-\/]/_/g") |
122 | | - echo "$PROFILES_YML" | base64 -d | sed "s/<SCHEMA_NAME>/py_$UNDERSCORED_REF_NAME/g" > ~/.dbt/profiles.yml |
| 120 | + # Schema name = py_<YYMMDD_HHMMSS>_<branch≤19>_<8-char hash> |
| 121 | + # The hash prevents collisions across concurrent jobs; the branch |
| 122 | + # keeps it human-readable; the timestamp helps with stale schema |
| 123 | + # cleanup and ensures each CI run gets a unique schema. |
| 124 | + # |
| 125 | + # Budget (PostgreSQL 63-char limit): |
| 126 | + # py_(3) + timestamp(13) + _(1) + branch(≤19) + _(1) + hash(8) = 45 |
| 127 | + # + _elementary(11) + _gw7(4) = 60 |
| 128 | + CONCURRENCY_GROUP="tests_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}_${BRANCH_NAME}" |
| 129 | + SHORT_HASH=$(echo -n "$CONCURRENCY_GROUP" | sha256sum | head -c 8) |
| 130 | + SAFE_BRANCH=$(echo "${BRANCH_NAME}" | awk '{print tolower($0)}' | sed "s/[^a-z0-9]/_/g; s/__*/_/g" | head -c 19) |
| 131 | + DATE_STAMP=$(date -u +%y%m%d_%H%M%S) |
| 132 | + SCHEMA_NAME="py_${DATE_STAMP}_${SAFE_BRANCH}_${SHORT_HASH}" |
| 133 | +
|
| 134 | + echo "Schema name: $SCHEMA_NAME (branch='${BRANCH_NAME}', timestamp=${DATE_STAMP}, hash of concurrency group)" |
| 135 | +
|
| 136 | + python "${{ github.workspace }}/elementary/tests/profiles/generate_profiles.py" \ |
| 137 | + --template "${{ github.workspace }}/elementary/tests/profiles/profiles.yml.j2" \ |
| 138 | + --output ~/.dbt/profiles.yml \ |
| 139 | + --schema-name "$SCHEMA_NAME" |
123 | 140 |
|
124 | 141 | - name: Run Python package unit tests |
125 | 142 | run: pytest -vv tests/unit --warehouse-type ${{ inputs.warehouse-type }} |
@@ -260,3 +277,10 @@ jobs: |
260 | 277 |
|
261 | 278 | - name: Run Python package e2e tests |
262 | 279 | run: pytest -vv tests/e2e --warehouse-type ${{ inputs.warehouse-type }} |
| 280 | + |
| 281 | + - name: Drop test schemas |
| 282 | + if: always() |
| 283 | + working-directory: ${{ env.E2E_DBT_PROJECT_DIR }} |
| 284 | + continue-on-error: true |
| 285 | + run: | |
| 286 | + dbt run-operation elementary_integration_tests.drop_test_schemas --target "${{ inputs.warehouse-type }}" |
0 commit comments