diff --git a/.github/actions/build-hatch/action.yml b/.github/actions/build-hatch/action.yml new file mode 100644 index 000000000..9c6359514 --- /dev/null +++ b/.github/actions/build-hatch/action.yml @@ -0,0 +1,36 @@ +name: Build - `hatch` +description: Build artifacts using the `hatch` build backend + +inputs: + build-command: + description: The command to build distributable artifacts + default: "hatch build" + check-command: + description: The command to check built artifacts + default: "hatch run build:check-all" + working-dir: + description: Where to run commands from, supports namespace packaging + default: "./" + artifacts-dir: + description: Where to upload the artifacts + default: "dist" + +runs: + using: composite + steps: + + - name: Build artifacts + run: ${{ inputs.build-command }} + shell: bash + working-directory: ${{ inputs.working-dir }} + + - name: Check artifacts + run: ${{ inputs.check-command }} + shell: bash + working-directory: ${{ inputs.working-dir }} + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifacts-dir}} + path: ${{ inputs.working-dir }}dist/ diff --git a/.github/actions/publish-pypi/action.yml b/.github/actions/publish-pypi/action.yml index 01cbc1cb3..f28775a47 100644 --- a/.github/actions/publish-pypi/action.yml +++ b/.github/actions/publish-pypi/action.yml @@ -1,25 +1,25 @@ -name: Publish PyPI +name: Publish - PyPI +description: Publish artifacts saved during build step to PyPI inputs: - python-version: - description: Create an environment with the appropriate version of python and hatch installed - default: "3.11" + artifacts-dir: + description: Where to download the artifacts + default: "dist" + repository-url: + description: The PyPI index to publish to, test or prod + required: true runs: using: composite steps: - - name: Setup environment - uses: ./.github/actions/setup-environment - with: - python-version: ${{ inputs.python-version }} - - - name: Build artifacts - run: hatch build - shell: bash - - name: Check artifacts - run: hatch run build:check-all - shell: bash + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifacts-dir }} + path: dist/ - name: Publish artifacts to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: ${{ inputs.repository-url }} diff --git a/.github/actions/publish-results/action.yml b/.github/actions/publish-results/action.yml index 5bd6e3416..d863d6598 100644 --- a/.github/actions/publish-results/action.yml +++ b/.github/actions/publish-results/action.yml @@ -5,7 +5,7 @@ inputs: description: File type for file name stub (e.g. "unit-tests") required: true python-version: - description: Create an environment with the appropriate version of python and hatch installed + description: Python version for the file name stub (e.g. "3.8") required: true source-file: description: File to be uploaded @@ -16,10 +16,10 @@ runs: steps: - name: Get timestamp id: timestamp - run: echo "ts=$(date +'%Y-%m-%dT%H_%M_%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts + run: echo "ts=$(date +'%Y-%m-%dT%H-%M-%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts shell: bash - uses: actions/upload-artifact@v3 with: - name: ${{ inputs.file-name }}_${{ inputs.python-version }}-${{ steps.timestamp.outputs.ts }}.csv + name: ${{ inputs.file-name }}_python-${{ inputs.python-version }}_${{ steps.timestamp.outputs.ts }}.csv path: ${{ inputs.source-file }} diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml deleted file mode 100644 index 6227c6985..000000000 --- a/.github/actions/setup-environment/action.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Setup `hatch` - -inputs: - python-version: - description: Create an environment with the appropriate version of python and hatch installed - required: true - -runs: - using: composite - steps: - - name: Set up Python ${{ inputs.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ inputs.python-version }} - - - name: Install hatch - run: python -m pip install hatch - shell: bash diff --git a/.github/actions/setup-hatch/action.yml b/.github/actions/setup-hatch/action.yml new file mode 100644 index 000000000..7b7780ef7 --- /dev/null +++ b/.github/actions/setup-hatch/action.yml @@ -0,0 +1,22 @@ +name: Setup - `hatch` +description: Setup a python environment with `hatch` installed + +inputs: + setup-command: + description: The command to setup development dependencies + default: "python -m pip install hatch" + python-version: + description: The version of python to install + default: "3.11" + +runs: + using: composite + steps: + - name: Set up Python ${{ inputs.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.python-version }} + + - name: Install dev dependencies + run: ${{ inputs.setup-command }} + shell: bash diff --git a/.github/workflows/lint.yml b/.github/workflows/code-quality.yml similarity index 80% rename from .github/workflows/lint.yml rename to .github/workflows/code-quality.yml index 2b336a430..98f1aa124 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/code-quality.yml @@ -1,4 +1,4 @@ -name: Lint +name: Code Quality on: push: @@ -10,6 +10,10 @@ on: permissions: read-all +defaults: + run: + shell: bash + # will cancel previous workflows triggered by the same event and for the same ref for PRs or same SHA otherwise concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.ref || github.sha }} @@ -26,15 +30,11 @@ jobs: with: persist-credentials: false - - name: Setup environment - uses: ./.github/actions/setup-environment - with: - python-version: "3.8" + - name: Setup `hatch` + uses: ./.github/actions/setup-hatch - name: Run linters run: hatch run lint:all - shell: bash - name: Run typechecks run: hatch run typecheck:all - shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b92ee915..6d8c1f7b1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,9 +3,16 @@ name: Release on: workflow_dispatch: inputs: + package: + type: choice + description: Choose what to publish + options: + - dbt-adapters + - dbt-tests-adapter + default: dbt-adapters deploy-to: type: choice - description: Choose where to publish (test/prod) + description: Choose where to publish options: - prod - test @@ -19,7 +26,7 @@ defaults: # will cancel previous workflows triggered by the same event and for the same ref for PRs or same SHA otherwise concurrency: - group: ${{ github.workflow }}-${{ github.event_name }}-${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.ref || github.sha }} + group: ${{ github.workflow }}-${{ github.event_name }}-${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.ref || github.sha }}-${{ inputs.package }}-${{ inputs.deploy-to }} cancel-in-progress: true jobs: @@ -29,7 +36,7 @@ jobs: runs-on: ubuntu-latest environment: name: ${{ inputs.deploy-to }} - url: ${{ vars.PYPI_URL }} + url: ${{ vars.PYPI_PROJECT_URL }} permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing @@ -39,7 +46,20 @@ jobs: with: persist-credentials: false + - name: Setup `hatch` + uses: ./.github/actions/setup-hatch + + - name: Build `dbt-adapters` + if: ${{ inputs.package == 'dbt-adapters' }} + uses: ./.github/actions/build-hatch + + - name: Build `dbt-tests-adapter` + if: ${{ inputs.package == 'dbt-tests-adapter' }} + uses: ./.github/actions/build-hatch + with: + working-dir: "./dbt-tests-adapter/" + - name: Publish to PyPI uses: ./.github/actions/publish-pypi with: - python-version: "3.11" + repository-url: ${{ vars.PYPI_REPOSITORY_URL }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f8a39ea8d..31c0304a6 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -31,8 +31,8 @@ jobs: with: persist-credentials: false - - name: Setup environment - uses: ./.github/actions/setup-environment + - name: Setup `hatch` + uses: ./.github/actions/setup-hatch with: python-version: ${{ matrix.python-version }} diff --git a/dbt-tests-adapter/pyproject.toml b/dbt-tests-adapter/pyproject.toml index a7966705c..f69b0e12e 100644 --- a/dbt-tests-adapter/pyproject.toml +++ b/dbt-tests-adapter/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", ] dependencies = [ - "dbt-core @ git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core", + "dbt-core", # `dbt-tests-adapter` will ultimately depend on the packages below # `dbt-tests-adapter` temporarily uses `dbt-core` for a dbt runner # `dbt-core` takes the packages below as dependencies, so they are unpinned to avoid conflicts @@ -50,14 +50,13 @@ Changelog = "https://github.com/dbt-labs/dbt-adapters/blob/main/CHANGELOG.md" requires = ["hatchling"] build-backend = "hatchling.build" -[tool.hatch.metadata] -allow-direct-references = true - [tool.hatch.build.targets.sdist.force-include] "../dbt/tests" = "dbt/tests" +"../dbt/__init__.py" = "dbt/__init__.py" [tool.hatch.build.targets.wheel.force-include] "../dbt/tests" = "dbt/tests" +"../dbt/__init__.py" = "dbt/__init__.py" [tool.hatch.version] path = "../dbt/tests/__about__.py"