Skip to content

Commit

Permalink
Config hatch for release workflow in GHA (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare authored Jan 18, 2024
1 parent e4c2f95 commit 055c07a
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .github/actions/publish-pypi/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish PyPI

inputs:
python-version:
description: Create an environment with the appropriate version of python and hatch installed
default: "3.11"

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 check-all
shell: bash

- name: Publish artifacts to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion .github/actions/publish-results/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inputs:
required: true

runs:
using: "composite"
using: composite
steps:
- name: Get timestamp
id: timestamp
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inputs:
required: true

runs:
using: "composite"
using: composite
steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Release

on:
workflow_dispatch:
inputs:
deploy-to:
type: choice
description: Choose where to publish (test/prod)
options:
- prod
- test
default: prod

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 }}
cancel-in-progress: true

jobs:

release:
name: PyPI - ${{ inputs.deploy-to }}
runs-on: ubuntu-latest
environment:
name: ${{ inputs.deploy-to }}
url: ${{ vars.PYPI_URL }}
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing

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

- name: Publish to PyPI
uses: ./.github/actions/publish-pypi
with:
python-version: "3.11"
File renamed without changes.
28 changes: 27 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ lint = [
"black",
"flake8",
"Flake8-pyproject",
]
typecheck = [
"mypy",
"types-protobuf",
"types-pytz",
Expand All @@ -45,6 +47,11 @@ test = [
"pytest-dotenv",
"pytest-xdist",
]
build = [
"wheel",
"twine",
"check-wheel-contents",
]

[project.urls]
Homepage = "https://github.com/dbt-labs/dbt-adapters"
Expand All @@ -67,7 +74,12 @@ packages = ["dbt"]
path = "dbt/adapters/__about__.py"

[tool.hatch.envs.default]
features = ["lint", "test"]
features = [
"lint",
"typecheck",
"test",
"build",
]
[tool.hatch.envs.default.scripts]
unit-tests = "- python -m pytest {args:tests/unit}"
lint-all = [
Expand All @@ -78,6 +90,20 @@ lint-all = [
lint-black = "python -m black ."
lint-flake8 = "python -m flake8 ."
lint-mypy = "python -m mypy ."
check-all = [
"- check-wheel",
"- check-sdist",
]
check-wheel = [
"twine check dist/*",
"find ./dist/dbt_adapters-*.whl -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/",
"pip freeze | grep dbt-adapters",
]
check-sdist = [
"check-wheel-contents dist/*.whl --ignore W007,W008",
"find ./dist/dbt_adapters-*.gz -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/",
"pip freeze | grep dbt-adapters",
]

[tool.black]
extend-exclude = "dbt/adapters/events/adapter_types_pb2.py"
Expand Down

0 comments on commit 055c07a

Please sign in to comment.