Skip to content

Commit

Permalink
update workflow files to use hatch.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Nov 17, 2024
1 parent 6df3421 commit 5869413
Show file tree
Hide file tree
Showing 7 changed files with 555 additions and 250 deletions.
6 changes: 3 additions & 3 deletions .github/scripts/update_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
set -e

git_branch=$1
target_req_file="dev-requirements.txt"
core_req_sed_pattern="s|dbt-core.git.*#egg=dbt-core|dbt-core.git@${git_branch}#egg=dbt-core|g"
tests_req_sed_pattern="s|dbt-core.git.*#egg=dbt-tests|dbt-core.git@${git_branch}#egg=dbt-tests|g"
target_req_file="hatch.toml"
core_req_sed_pattern="s|dbt-core.git#subdirectory=core|dbt-core.git@${git_branch}#subdirectory=core|g"
tests_req_sed_pattern="s|dbt-adapters.git#subdirectory=dbt-tests-adapter|dbt-adapters.git@${git_branch}#subdirectory=dbt-tests-adapter|g"
if [[ "$OSTYPE" == darwin* ]]; then
# mac ships with a different version of sed that requires a delimiter arg
sed -i "" "$core_req_sed_pattern" $target_req_file
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/update_dev_dependency_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set -e
dbt_adapters_branch=$1
dbt_core_branch=$2
dbt_common_branch=$3
target_req_file="dev-requirements.txt"
core_req_sed_pattern="s|dbt-core.git.*#egg=dbt-core|dbt-core.git@${dbt_core_branch}#egg=dbt-core|g"
target_req_file="hatch.toml"
core_req_sed_pattern="s|dbt-core.git#subdirectory=core|dbt-core.git@${dbt_core_branch}#subdirectory=core|g"
adapters_req_sed_pattern="s|dbt-adapters.git|dbt-adapters.git@${dbt_adapters_branch}|g"
common_req_sed_pattern="s|dbt-common.git|dbt-common.git@${dbt_common_branch}|g"
if [[ "$OSTYPE" == darwin* ]]; then
Expand Down
88 changes: 16 additions & 72 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,17 @@ jobs:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.result }}

steps:
- name: Check out the repository (non-PR)
if: github.event_name != 'pull_request_target'
- if: github.event_name != 'pull_request_target'
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Check out the repository (PR)
if: github.event_name == 'pull_request_target'
- if: github.event_name == 'pull_request_target'
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}

- name: Check if relevant files changed
if: github.event_name == 'pull_request_target'
- if: github.event_name == 'pull_request_target'
# https://github.com/marketplace/actions/paths-changes-filter
# For each filter, it sets output variable named by the filter to the text:
# 'true' - if any of changed files matches any of filter rules
Expand All @@ -119,10 +113,9 @@ jobs:
- '.github/**/*.sh'
- 'dbt/**'
- 'tests/**'
- 'dev-requirements.txt'
- 'pyproject.toml'
- '*.py'
- name: Generate integration test matrix
id: generate-matrix
- id: generate-matrix
uses: actions/github-script@v7
env:
CHANGES: ${{ steps.get-changes.outputs.changes }}
Expand All @@ -132,9 +125,9 @@ jobs:
const matrix = script({ context })
console.log(matrix)
return matrix
test:
name: ${{ matrix.adapter }} / python ${{ matrix.python-version }} / ${{ matrix.os }}

# run if not a PR from a forked repository or has a label to mark as safe to test
# also checks that the matrix generated is not empty
if: >-
Expand All @@ -147,67 +140,42 @@ jobs:
)
runs-on: ${{ matrix.os }}
needs: test-metadata

strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.test-metadata.outputs.matrix) }}

env:
TOXENV: integration-${{ matrix.adapter }}
PYTEST_ADDOPTS: "-v --color=yes -n4 --csv integration_results.csv"
DBT_INVOCATION_ENV: github-actions
DD_CIVISIBILITY_AGENTLESS_ENABLED: true
DD_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DD_SITE: datadoghq.com
DD_ENV: ci
DD_SERVICE: ${{ github.event.repository.name }}

steps:
- name: Check out the repository
if: github.event_name == 'push'
- if: github.event_name == 'push'
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Check out the repository (workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
- if: github.event_name == 'workflow_dispatch'
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ inputs.adapter_branch }}

# explicitly checkout the branch for the PR,
# this is necessary for the `pull_request_target` event
- name: Check out the repository (PR)
if: github.event_name == 'pull_request_target'
- if: github.event_name == 'pull_request_target'
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Update Adapters and Core branches (update dev_requirements.txt)
if: ${{ github.event_name == 'workflow_dispatch' }}
- if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
./.github/scripts/update_dev_dependency_branches.sh \
${{ inputs.dbt_adapters_branch }} \
${{ inputs.dbt_core_branch }} \
${{ inputs.dbt_common_branch }}
cat dev-requirements.txt
- name: Install python dependencies
run: |
python -m pip install --user --upgrade pip
python -m pip install tox
python -m pip --version
tox --version
- name: Run tox (snowflake)
if: matrix.adapter == 'snowflake'
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: pypa/hatch@install
- run: hatch run integration-tests
env:
SNOWFLAKE_TEST_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }}
SNOWFLAKE_TEST_PASSWORD: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }}
Expand All @@ -226,38 +194,14 @@ jobs:
DBT_TEST_USER_1: dbt_test_role_1
DBT_TEST_USER_2: dbt_test_role_2
DBT_TEST_USER_3: dbt_test_role_3
run: tox -- --ddtrace

- name: Get current date
if: always()
id: date
run: echo "date=$(date +'%Y-%m-%dT%H_%M_%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts

- uses: actions/upload-artifact@v4
if: always()
with:
name: logs_${{ matrix.python-version }}_${{ matrix.os }}_${{ matrix.adapter }}-${{ steps.date.outputs.date }}
path: ./logs
overwrite: true

- uses: actions/upload-artifact@v4
if: always()
with:
name: integration_results_${{ matrix.python-version }}_${{ matrix.os }}_${{ matrix.adapter }}-${{ steps.date.outputs.date }}.csv
path: integration_results.csv
overwrite: true

require-label-comment:
runs-on: ubuntu-latest

needs: test

permissions:
pull-requests: write

steps:
- name: Needs permission PR comment
if: >-
- if: >-
needs.test.result == 'skipped' &&
github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository
Expand Down
124 changes: 15 additions & 109 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,124 +38,52 @@ defaults:
jobs:
code-quality:
name: code-quality

runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Install python dependencies
run: |
python -m pip install --user --upgrade pip
python -m pip install -r dev-requirements.txt
python -m pip --version
pre-commit --version
dbt --version
- name: Run pre-commit hooks
run: pre-commit run --all-files --show-diff-on-failure
- uses: pre-commit/action@v3.0.1

unit:
name: unit test / python ${{ matrix.python-version }}

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

env:
TOXENV: "unit"
PYTEST_ADDOPTS: "-v --color=yes --csv unit_results.csv"

steps:
- name: Check out the repository
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install python dependencies
run: |
python -m pip install --user --upgrade pip
python -m pip install tox
python -m pip --version
tox --version
- name: Run tox
run: tox

- name: Get current date
if: always()
id: date
run: echo "date=$(date +'%Y-%m-%dT%H_%M_%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts

- uses: actions/upload-artifact@v4
if: always()
with:
name: unit_results_${{ matrix.python-version }}-${{ steps.date.outputs.date }}.csv
path: unit_results.csv
overwrite: true
- uses: pypa/hatch@install
- run: hatch run unit-tests

build:
name: build packages

runs-on: ubuntu-latest

outputs:
is_alpha: ${{ steps.check-is-alpha.outputs.is_alpha }}

steps:
- name: Check out the repository
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Install python dependencies
run: |
python -m pip install --user --upgrade pip
python -m pip install --upgrade setuptools wheel twine check-wheel-contents
python -m pip --version
- name: Build distributions
run: ./scripts/build-dist.sh

- name: Show distributions
run: ls -lh dist/

- name: Check distribution descriptions
run: |
twine check dist/*
- name: Check wheel contents
run: |
check-wheel-contents dist/*.whl --ignore W007,W008
- name: Check if this is an alpha version
id: check-is-alpha
- run: hatch build
- run: hatch run build:check-all
- id: check-is-alpha
run: |
export is_alpha=0
if [[ "$(ls -lh dist/)" == *"a1"* ]]; then export is_alpha=1; fi
echo "is_alpha=$is_alpha" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v4
with:
name: dist
Expand All @@ -164,44 +92,22 @@ jobs:

test-build:
name: verify packages / python ${{ matrix.python-version }} / ${{ matrix.os }} / ${{ matrix.dist-type }}

if: needs.build.outputs.is_alpha == 0

needs: build

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
dist-type: ['whl', 'gz']

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install python dependencies
run: |
python -m pip install --user --upgrade pip
python -m pip install --upgrade wheel
python -m pip --version
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/

- name: Show distributions
run: ls -lh dist/

- name: Install ${{ matrix.dist-type }} distributions
run: |
find ./dist/*.${{ matrix.dist-type }} -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/
- name: Check ${{ matrix.dist-type }} distributions
run: |
python -c "import dbt.adapters.snowflake"
- run: find ./dist/*.${{ matrix.dist-type }} -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/
- run: python -c "import dbt.adapters.snowflake"
Loading

0 comments on commit 5869413

Please sign in to comment.