Skip to content

Commit 33081a5

Browse files
authored
Merge pull request #40 from syntasso/chore/32/switch-to-uv
chore: automate package publishing process with uv
2 parents 198dc4e + f185c28 commit 33081a5

25 files changed

+939
-203
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ updates:
1111
groups: # group bumps to reduce number of PRs
1212
minor-and-patch:
1313
patterns: ["*"]
14-
update-types: ["minor", "patch"]
14+
update-types: ["minor", "patch"]

.github/workflows/docs.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/publish.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: "Publish package and documentation"
2+
3+
on:
4+
release:
5+
types: ["published"]
6+
7+
jobs:
8+
packages:
9+
name: "Build and publish release"
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.12"
19+
20+
- name: Install uv
21+
uses: astral-sh/setup-uv@v5
22+
with:
23+
enable-cache: true
24+
25+
- name: Build
26+
run: uv build
27+
28+
- name: Publish RC packages to PyPI Test
29+
if: contains(github.event.release.tag_name, '-rc')
30+
run: |
31+
uv publish --index testpypi --token ${{ secrets.TEST_PYPI_TOKEN }}
32+
33+
- name: Publish release packages to PyPI
34+
if: ${{ ! contains(github.event.release.tag_name, '-rc') }}
35+
run: uv publish --token ${{ secrets.PYPI_TOKEN }}
36+
37+
docs:
38+
needs: packages
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- uses: actions/setup-python@v5
44+
with:
45+
python-version: "3.12"
46+
47+
- name: Install uv
48+
uses: astral-sh/setup-uv@v5
49+
with:
50+
enable-cache: true
51+
52+
- name: Generate docs
53+
run: make install generate-docs
54+
55+
- name: Publish RC docs
56+
if: contains(github.event.release.tag_name, '-rc')
57+
uses: peaceiris/actions-gh-pages@v4
58+
with:
59+
github_token: ${{ secrets.GITHUB_TOKEN }}
60+
publish_dir: ./docs
61+
# this puts the docs for this tag under gh-pages:/rc/<tag>/
62+
destination_dir: rc/${{ github.event.release.tag_name }}
63+
64+
- name: Publish release docs
65+
if: ${{ ! contains(github.event.release.tag_name, '-rc') }}
66+
uses: peaceiris/actions-gh-pages@v4
67+
with:
68+
github_token: ${{ secrets.GITHUB_TOKEN }}
69+
publish_dir: ./docs

.github/workflows/release.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: create-new-release
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- test
7+
types:
8+
- completed
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: write
15+
issues: write
16+
pull-requests: write
17+
18+
jobs:
19+
release-please:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: googleapis/release-please-action@v4
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
release-type: python

.github/workflows/test.yaml

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,40 @@
1-
name: Test-and-release-kratix-sdk
1+
name: test
22

33
on:
44
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches-ignore: [ "release-please--**" ]
5+
workflow_dispatch:
86

97
jobs:
10-
test:
11-
name: Lint and test
8+
lint-and-test:
129
runs-on: ubuntu-latest
13-
10+
1411
strategy:
1512
matrix:
16-
python-version: ["3.12", "3.13"]
13+
python-version: ["3.10", "3.10", "3.12", "3.13", "3.14"]
1714

1815
steps:
1916
- uses: actions/checkout@v4
17+
2018
- name: Set up Python ${{ matrix.python-version }}
2119
uses: actions/setup-python@v5
2220
with:
2321
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
enable-cache: true
27+
2428
- name: Display Python version
2529
run: python -c "import sys; print(sys.version)"
30+
2631
- name: Install dependencies
27-
run: python -m pip install --upgrade pip setuptools wheel
28-
- name: Install Poetry
29-
uses: snok/install-poetry@v1
32+
run: make install
33+
3034
- name: lint
3135
run: make install lint
36+
3237
- name: Tests
3338
run: make test
34-
35-
release-please:
36-
name: Create Release PR
37-
runs-on: ubuntu-latest
38-
needs: [test]
39-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
40-
41-
steps:
42-
- name: Checkout code
43-
uses: actions/checkout@v4
44-
with:
45-
fetch-depth: 0
46-
token: ${{ secrets.GITHUB_TOKEN }}
47-
48-
- name: Setup Node.js
49-
uses: actions/setup-node@v4
50-
with:
51-
node-version: '18'
52-
53-
- name: Install Release Please
54-
run: npm install -g release-please
55-
56-
- name: Create pending releases
57-
if: github.ref == 'refs/heads/main'
58-
run: |
59-
release-please \
60-
--token="${{ secrets.GITHUB_TOKEN }}" \
61-
--repo-url="${{ github.repository }}" \
62-
github-release
63-
64-
- name: Create Release PR
65-
run: |
66-
release-please release-pr \
67-
--repo-url="${{ github.repository }}" \
68-
--token="${{ secrets.GITHUB_TOKEN }}" \
69-
--release-type="python"
39+
env:
40+
UV_PYTHON: ${{ matrix.python-version }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ __pycache__/
99
.vscode/
1010
tests/__pycache__/
1111
dist/
12+
docs/

Makefile

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
.PHONY: test lint fmt clean install
1+
UV_PYTHON ?= 3.12
2+
3+
.PHONY: help install test lint fmt generate-docs build-and-load-configure image build-and-load-system-test-image
4+
5+
help: # Show help for each of the Makefile recipes.
6+
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "\033[1;34m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done
27

38
install: # install dependencies for running tests and linting
4-
poetry install
9+
uv python install
10+
uv sync --extra dev
511

6-
test:
7-
poetry run pytest
12+
test: install # run tests
13+
uv run --isolated --with-editable '.[dev]' pytest
814

9-
lint:
10-
poetry run ruff check kratix_sdk tests
15+
lint: install # run linting checks
16+
uv run ruff check kratix_sdk tests
17+
uv run ruff format --check kratix_sdk tests
1118

12-
fmt:
13-
poetry run ruff format kratix_sdk tests
19+
fmt: install # run code formatter
20+
uv run ruff format kratix_sdk tests
1421

15-
generate-docs:
16-
poetry run pdoc src/kratix_sdk -o docs
22+
generate-docs: install # create API documentation
23+
uv run pdoc src/kratix_sdk -o docs
1724

18-
build-and-load-configure-image:
25+
build-and-load-configure-image: # build example docker image and load it into kind
1926
docker buildx build --builder kratix-image-builder --load --platform linux/arm64 \
2027
-t ghcr.io/syntasso/example-deployment-configure:v0.0.1 -f examples/deployment/Dockerfile .
2128
kind load docker-image ghcr.io/syntasso/example-deployment-configure:v0.0.1 -n platform
2229

23-
build-and-load-system-test-image:
30+
build-and-load-system-test-image: # build integration test docker image and load it into kind
2431
docker buildx build --builder kratix-image-builder --load --platform linux/arm64 \
2532
-t ghcr.io/syntasso/kratix-python/sdk-test:v1.0.0 -f system/assets/workflow/Dockerfile .
2633
kind load docker-image ghcr.io/syntasso/kratix-python/sdk-test:v1.0.0 -n platform
File renamed without changes.

RELEASING.md

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,34 @@
11
# Releasing `kratix-sdk`
22

3-
This document captures the steps for cutting a new version of the SDK and publishing it to PyPI.
4-
5-
1. **Set up Poetry credentials (one-time per machine)**
6-
```bash
7-
poetry config repositories.testpypi https://test.pypi.org/legacy/
8-
# Use a TestPyPI API token copied from https://test.pypi.org/manage/account/token/
9-
poetry config pypi-token.testpypi <TESTPYPI_API_TOKEN>
10-
# For the main PyPI token (if not already configured)
11-
poetry config pypi-token.pypi <PYPI_API_TOKEN>
12-
```
13-
Alternatively export `POETRY_HTTP_BASIC_TESTPYPI_USERNAME="__token__"` and `POETRY_HTTP_BASIC_TESTPYPI_PASSWORD="<token>"` before publishing.
14-
15-
2. **Prep the repo**
16-
- Prior to pypi release, release-please has to manage / generate a new version number.
17-
- All commits should be merged to `main`.
18-
- Once release-please has created a PR, merge it to `main` with the new version number in `pyproject.toml` .
19-
- Pull down the latest `main` branch.
20-
21-
3. **Run quality checks**
22-
```bash
23-
make install # installs dependencies
24-
make fmt && make lint # optional but recommended
25-
make test # run pytest
26-
```
27-
28-
4. **Build distributions**
29-
```bash
30-
poetry build
31-
ls dist/ # verify the wheel and sdist exist
32-
tar tf dist/kratix-sdk-<version>.tar.gz | head
33-
```
34-
Inspect the contents to ensure only expected files are included.
35-
36-
5. **Publish to TestPyPI (recommended)**
37-
```bash
38-
poetry publish --repository testpypi --build
39-
python -m venv /tmp/kratix-sdk-test
40-
source /tmp/kratix-sdk-test/bin/activate
41-
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple kratix-sdk==<version>
42-
```
43-
Run a quick smoke test (`python -c "import kratix_sdk; print(kratix_sdk.__version__)"`) to ensure the build works.
44-
45-
6. **Publish to PyPI**
46-
```bash
47-
poetry publish --build
48-
git tag v<version>
49-
git push origin main --tags
50-
```
51-
PyPI credentials/API token must be configured in `~/.pypirc` beforehand.
52-
53-
7. **Communicate the release**
54-
- Share release notes on the relevant channels.
55-
- Update downstream sample projects if they pin versions.
3+
The release process for this repository is almost entirely automated, consisting
4+
of these steps:
5+
6+
1. **Run quality checks (unit tests and linting)** (automated)
7+
8+
Every PR and every merge to `main` will trigger the testing workflow. This
9+
workflow checks for successful unit test runs and whether the linting and
10+
formatting rules are being respected.
11+
12+
1. **Prepare the release PR** (automated)
13+
14+
`release-please` will prepare a release PR for this project after each each
15+
successful run of the of the quality checks in the `main` branch.
16+
17+
1. **Merge the release PR** (manual)
18+
19+
A maintainer decided whether the release PR created by `release-please` should
20+
be merged. If a release PR is merged, `release-please` will update the
21+
[CHANGELOG](CHANGELOG.md) and create a new Github Release with notes.
22+
23+
1. **Publish repositories to PyPI** (automated)
24+
25+
When a release is created, the publish workflow will package the code onto a
26+
new release and push this release as a new package on PyPI. If the package is
27+
published successfully, it will publish the API documentation to the
28+
[documentation website](https://syntasso.github.io/kratix-python/).
29+
30+
1. **Communicate the release** (manual)
31+
32+
After all artifacts are published, a human needs to:
33+
- Share release notes on the relevant channels.
34+
- Update downstream sample projects if they pin versions.

kratix_sdk/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
from importlib import metadata as importlib_metadata
22

3-
from .status import Status
4-
from .resource import Resource
53
from .kratix_sdk import (
64
KratixSDK,
7-
set_input_dir,
8-
set_output_dir,
95
get_input_dir,
10-
get_output_dir,
116
get_metadata_dir,
7+
get_output_dir,
8+
set_input_dir,
129
set_metadata_dir,
10+
set_output_dir,
1311
)
1412
from .promise import Promise
15-
from .types import GroupVersionKind, DestinationSelector
13+
from .resource import Resource
14+
from .status import Status
15+
from .types import DestinationSelector, GroupVersionKind
1616

1717
try:
1818
__version__ = importlib_metadata.version("kratix-sdk")
19-
except importlib_metadata.PackageNotFoundError: # pragma: no cover - source tree fallback
19+
except (
20+
importlib_metadata.PackageNotFoundError
21+
): # pragma: no cover - source tree fallback
2022
__version__ = "0.4.0"
2123

2224
__all__ = [

0 commit comments

Comments
 (0)