diff --git a/.github/workflows/test-warehouse.yml b/.github/workflows/test-warehouse.yml index fe52d9c7f..73e1a2331 100644 --- a/.github/workflows/test-warehouse.yml +++ b/.github/workflows/test-warehouse.yml @@ -65,7 +65,8 @@ jobs: run: working-directory: elementary concurrency: - # This is what eventually defines the schema name in the data platform. + # Serialises runs for the same warehouse × dbt-version × branch. + # The schema name is derived from a hash of this group (see "Write dbt profiles"). group: tests_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}_${{ github.head_ref || github.ref_name }} cancel-in-progress: true steps: @@ -116,13 +117,26 @@ jobs: env: CI_WAREHOUSE_SECRETS: ${{ secrets.CI_WAREHOUSE_SECRETS || '' }} run: | - DBT_VERSION=$(pip show dbt-core | grep -i version | awk '{print $2}' | sed 's/\.//g') - UNDERSCORED_REF_NAME=$(echo "${{ inputs.warehouse-type }}_dbt_${DBT_VERSION}_${BRANCH_NAME}" | awk '{print tolower($0)}' | head -c 40 | sed "s/[-\/]/_/g") + # Schema name = py___<8-char hash> + # The hash prevents collisions across concurrent jobs; the branch + # keeps it human-readable; the timestamp helps with stale schema + # cleanup and ensures each CI run gets a unique schema. + # + # Budget (PostgreSQL 63-char limit): + # py_(3) + timestamp(13) + _(1) + branch(≤19) + _(1) + hash(8) = 45 + # + _elementary(11) + _gw7(4) = 60 + CONCURRENCY_GROUP="tests_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}_${BRANCH_NAME}" + SHORT_HASH=$(echo -n "$CONCURRENCY_GROUP" | sha256sum | head -c 8) + SAFE_BRANCH=$(echo "${BRANCH_NAME}" | awk '{print tolower($0)}' | sed "s/[^a-z0-9]/_/g; s/__*/_/g" | head -c 19) + DATE_STAMP=$(date -u +%y%m%d_%H%M%S) + SCHEMA_NAME="py_${DATE_STAMP}_${SAFE_BRANCH}_${SHORT_HASH}" + + echo "Schema name: $SCHEMA_NAME (branch='${BRANCH_NAME}', timestamp=${DATE_STAMP}, hash of concurrency group)" python "${{ github.workspace }}/elementary/tests/profiles/generate_profiles.py" \ --template "${{ github.workspace }}/elementary/tests/profiles/profiles.yml.j2" \ --output ~/.dbt/profiles.yml \ - --schema-name "py_$UNDERSCORED_REF_NAME" + --schema-name "$SCHEMA_NAME" - name: Run Python package unit tests run: pytest -vv tests/unit --warehouse-type ${{ inputs.warehouse-type }}