Skip to content

Commit

Permalink
Generalize actions for reuse across adapters (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare authored Jan 29, 2024
1 parent 60005a0 commit f896eff
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 53 deletions.
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

0 comments on commit f896eff

Please sign in to comment.