Skip to content

Commit

Permalink
feat: GH Action - Publish Python Package (#30)
Browse files Browse the repository at this point in the history
* feat: set up Python package publishing GH Action

* docs: describe the new release process

* fix: aligns spacing and order of Workflow job configs

* chore: specify Python version to 3.10
  • Loading branch information
sakce authored Feb 5, 2024
1 parent b70a7e8 commit 053b1ff
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 50 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Triggered on push events to the main branch.
# Publishes the package to PyPI only on tag pushes.

name: 🐍 📦 Publish Python distribution to PyPI and TestPyPI

on:
push:
branches:
- main
tags:
- v*

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 🐍
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Setup Poetry 📚
uses: Gr1N/setup-poetry@v8

- name: Build distribution 📦
run: poetry build

- name: Store the distribution artifact 🥶
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish distro to PyPI 🐍 📦
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes

runs-on: ubuntu-latest
needs:
- build

environment:
name: prod
url: https://pypi.org/p/dbt-datadict

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}

publish-to-testpypi:
name: Publish distro to TestPyPI 🐍 📦

runs-on: ubuntu-latest
needs:
- build

environment:
name: test
url: https://test.pypi.org/p/dbt-datadict

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.PYPI_TOKEN }}
skip-existing: true
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/developer_guide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Developing Locally

1. Install package dependencies
1. Install package dependencies, as well as the `dbt-datadict` package itself:

```bash
$ poetry install
Expand Down Expand Up @@ -38,7 +38,7 @@
6. To pull the package from Test PyPI, run the following command:
```bash
$ python -m pip install --extra-index-url https://test.pypi.org/simple/ dbt-datadict==<version> # Replace <version>
$ python -m pip install --extra-index-url https://test.pypi.org/simple/ dbt-datadict==<version>
```
> **Hint**
Expand Down
14 changes: 14 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Package Release Process

1. Once you have made all the necessary changes to the package, update the version in the `pyproject.toml` file by running the following command, where the version specified is in line with the [PyPA Version Specifiers specification](https://packaging.python.org/en/latest/specifications/version-specifiers/#version-specifiers).

```bash
poetry version <version>
```

> **Hint**
> Run `poetry version --help` to see Poetry's options for automatic SemVer version bumping.
2. Commit the changes to the `pyproject.toml` file.
3. Once the `main` branch is in a release-ready state, create a new GitHub Release with a new tag `v<version>`. The release notes should include a summary of the changes made in the release.
4. Creating the release will trigger a [GitHub Action](../.github/workflows/publish.yml) that will publish the package to PyPI. Validate that the package has been published by checking the GH Action and the [PyPI project page](https://pypi.org/p/dbt-datadict).
93 changes: 45 additions & 48 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 053b1ff

Please sign in to comment.