Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize actions for reuse across adapters #54

Merged
merged 21 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
809c139
generalize actions for reuse across adapters
mikealfare Jan 26, 2024
9fc50d5
use github environments to store config
mikealfare Jan 26, 2024
c69ded0
use github environments to store config
mikealfare Jan 26, 2024
63df7ca
parse env var with fromjson
mikealfare Jan 26, 2024
0c9eb78
remove github env dependency for unit tests and code quality
mikealfare Jan 26, 2024
96a2953
update workflow name to match file name
mikealfare Jan 26, 2024
ae81723
default to python 3.11 in one place, remove the need for an env variable
mikealfare Jan 26, 2024
58c203f
pass pypi url as an input to the shared action instead of using an en…
mikealfare Jan 26, 2024
cba6d6b
fix parameter name for pypi publish action
mikealfare Jan 26, 2024
3f09967
wrap expected value in quotes
mikealfare Jan 26, 2024
ca33412
show current directory for debugging
mikealfare Jan 26, 2024
223b69a
add working directory option for namespace packages
mikealfare Jan 26, 2024
63658ee
make the working directory relative
mikealfare Jan 26, 2024
0e36e34
add the inputs to the concurrency hash to allow for parallel deploys …
mikealfare Jan 26, 2024
585dc22
separate build and publish steps
mikealfare Jan 26, 2024
887be8e
fix action references
mikealfare Jan 26, 2024
2708803
fix name for artifact upload/download
mikealfare Jan 26, 2024
0d4bdc8
fix name for pypi repository arg
mikealfare Jan 26, 2024
42de99f
fix conditional check for build
mikealfare Jan 26, 2024
b1c08fc
remove direct dependency on `dbt-core`
mikealfare Jan 26, 2024
ba1a7c6
capture root init in package
mikealfare Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/actions/build-hatch/action.yml
Original file line number Diff line number Diff line change
@@ -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/
30 changes: 15 additions & 15 deletions .github/actions/publish-pypi/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 3 additions & 3 deletions .github/actions/publish-results/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
18 changes: 0 additions & 18 deletions .github/actions/setup-environment/action.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/actions/setup-hatch/action.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: Code Quality

on:
push:
Expand All @@ -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 }}
Expand All @@ -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
28 changes: 24 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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 }}
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
7 changes: 3 additions & 4 deletions dbt-tests-adapter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Loading