Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ updates:
groups: # group bumps to reduce number of PRs
minor-and-patch:
patterns: ["*"]
update-types: ["minor", "patch"]
update-types: ["minor", "patch"]
23 changes: 0 additions & 23 deletions .github/workflows/docs.yaml

This file was deleted.

69 changes: 69 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "Publish package and documentation"

on:
release:
types: ["published"]

jobs:
packages:
name: "Build and publish release"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Build
run: uv build

- name: Publish RC packages to PyPI Test
if: contains(github.event.release.tag_name, '-rc')
run: |
uv publish --index testpypi --token ${{ secrets.TEST_PYPI_TOKEN }}

- name: Publish release packages to PyPI
if: ${{ ! contains(github.event.release.tag_name, '-rc') }}
run: uv publish --token ${{ secrets.PYPI_TOKEN }}

docs:
needs: packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Generate docs
run: make install generate-docs

- name: Publish RC docs
if: contains(github.event.release.tag_name, '-rc')
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
# this puts the docs for this tag under gh-pages:/rc/<tag>/
destination_dir: rc/${{ github.event.release.tag_name }}

- name: Publish release docs
if: ${{ ! contains(github.event.release.tag_name, '-rc') }}
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
25 changes: 25 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: create-new-release

on:
workflow_run:
workflows:
- test
types:
- completed
branches:
- main
workflow_dispatch:

permissions:
contents: write
issues: write
pull-requests: write

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: python
65 changes: 18 additions & 47 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,69 +1,40 @@
name: Test-and-release-kratix-sdk
name: test

on:
push:
branches: [ main ]
pull_request:
branches-ignore: [ "release-please--**" ]
workflow_dispatch:

jobs:
test:
name: Lint and test
lint-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.12", "3.13"]
python-version: ["3.10", "3.10", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel
- name: Install Poetry
uses: snok/install-poetry@v1
run: make install

- name: lint
run: make install lint

- name: Tests
run: make test

release-please:
name: Create Release PR
runs-on: ubuntu-latest
needs: [test]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install Release Please
run: npm install -g release-please

- name: Create pending releases
if: github.ref == 'refs/heads/main'
run: |
release-please \
--token="${{ secrets.GITHUB_TOKEN }}" \
--repo-url="${{ github.repository }}" \
github-release

- name: Create Release PR
run: |
release-please release-pr \
--repo-url="${{ github.repository }}" \
--token="${{ secrets.GITHUB_TOKEN }}" \
--release-type="python"
env:
UV_PYTHON: ${{ matrix.python-version }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ __pycache__/
.vscode/
tests/__pycache__/
dist/
docs/
31 changes: 19 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
.PHONY: test lint fmt clean install
UV_PYTHON ?= 3.12

.PHONY: help install test lint fmt generate-docs build-and-load-configure image build-and-load-system-test-image

help: # Show help for each of the Makefile recipes.
@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

install: # install dependencies for running tests and linting
poetry install
uv python install
uv sync --extra dev

test:
poetry run pytest
test: install # run tests
uv run --isolated --with-editable '.[dev]' pytest

lint:
poetry run ruff check kratix_sdk tests
lint: install # run linting checks
uv run ruff check kratix_sdk tests
uv run ruff format --check kratix_sdk tests

fmt:
poetry run ruff format kratix_sdk tests
fmt: install # run code formatter
uv run ruff format kratix_sdk tests

generate-docs:
poetry run pdoc src/kratix_sdk -o docs
generate-docs: install # create API documentation
uv run pdoc src/kratix_sdk -o docs

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

build-and-load-system-test-image:
build-and-load-system-test-image: # build integration test docker image and load it into kind
docker buildx build --builder kratix-image-builder --load --platform linux/arm64 \
-t ghcr.io/syntasso/kratix-python/sdk-test:v1.0.0 -f system/assets/workflow/Dockerfile .
kind load docker-image ghcr.io/syntasso/kratix-python/sdk-test:v1.0.0 -n platform
File renamed without changes.
85 changes: 32 additions & 53 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
# Releasing `kratix-sdk`

This document captures the steps for cutting a new version of the SDK and publishing it to PyPI.

1. **Set up Poetry credentials (one-time per machine)**
```bash
poetry config repositories.testpypi https://test.pypi.org/legacy/
# Use a TestPyPI API token copied from https://test.pypi.org/manage/account/token/
poetry config pypi-token.testpypi <TESTPYPI_API_TOKEN>
# For the main PyPI token (if not already configured)
poetry config pypi-token.pypi <PYPI_API_TOKEN>
```
Alternatively export `POETRY_HTTP_BASIC_TESTPYPI_USERNAME="__token__"` and `POETRY_HTTP_BASIC_TESTPYPI_PASSWORD="<token>"` before publishing.

2. **Prep the repo**
- Prior to pypi release, release-please has to manage / generate a new version number.
- All commits should be merged to `main`.
- Once release-please has created a PR, merge it to `main` with the new version number in `pyproject.toml` .
- Pull down the latest `main` branch.

3. **Run quality checks**
```bash
make install # installs dependencies
make fmt && make lint # optional but recommended
make test # run pytest
```

4. **Build distributions**
```bash
poetry build
ls dist/ # verify the wheel and sdist exist
tar tf dist/kratix-sdk-<version>.tar.gz | head
```
Inspect the contents to ensure only expected files are included.

5. **Publish to TestPyPI (recommended)**
```bash
poetry publish --repository testpypi --build
python -m venv /tmp/kratix-sdk-test
source /tmp/kratix-sdk-test/bin/activate
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple kratix-sdk==<version>
```
Run a quick smoke test (`python -c "import kratix_sdk; print(kratix_sdk.__version__)"`) to ensure the build works.

6. **Publish to PyPI**
```bash
poetry publish --build
git tag v<version>
git push origin main --tags
```
PyPI credentials/API token must be configured in `~/.pypirc` beforehand.

7. **Communicate the release**
- Share release notes on the relevant channels.
- Update downstream sample projects if they pin versions.
The release process for this repository is almost entirely automated, consisting
of these steps:

1. **Run quality checks (unit tests and linting)** (automated)

Every PR and every merge to `main` will trigger the testing workflow. This
workflow checks for successful unit test runs and whether the linting and
formatting rules are being respected.

1. **Prepare the release PR** (automated)

`release-please` will prepare a release PR for this project after each each
successful run of the of the quality checks in the `main` branch.

1. **Merge the release PR** (manual)

A maintainer decided whether the release PR created by `release-please` should
be merged. If a release PR is merged, `release-please` will update the
[CHANGELOG](CHANGELOG.md) and create a new Github Release with notes.

1. **Publish repositories to PyPI** (automated)

When a release is created, the publish workflow will package the code onto a
new release and push this release as a new package on PyPI. If the package is
published successfully, it will publish the API documentation to the
[documentation website](https://syntasso.github.io/kratix-python/).

1. **Communicate the release** (manual)

After all artifacts are published, a human needs to:
- Share release notes on the relevant channels.
- Update downstream sample projects if they pin versions.
16 changes: 9 additions & 7 deletions kratix_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from importlib import metadata as importlib_metadata

from .status import Status
from .resource import Resource
from .kratix_sdk import (
KratixSDK,
set_input_dir,
set_output_dir,
get_input_dir,
get_output_dir,
get_metadata_dir,
get_output_dir,
set_input_dir,
set_metadata_dir,
set_output_dir,
)
from .promise import Promise
from .types import GroupVersionKind, DestinationSelector
from .resource import Resource
from .status import Status
from .types import DestinationSelector, GroupVersionKind

try:
__version__ = importlib_metadata.version("kratix-sdk")
except importlib_metadata.PackageNotFoundError: # pragma: no cover - source tree fallback
except (
importlib_metadata.PackageNotFoundError
): # pragma: no cover - source tree fallback
__version__ = "0.4.0"

__all__ = [
Expand Down
Loading