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
25 changes: 10 additions & 15 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Python package

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
Expand All @@ -13,8 +13,6 @@ jobs:
matrix:
python-version: ["3.10"]
kube-version:
- 1.18.14
- 1.19.6
- 1.20.1
- 1.21.0
- 1.22.0
Expand All @@ -30,28 +28,25 @@ jobs:
- 1.32.0
- 1.33.1
- 1.34.0
- 1.35.0
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m lightkube-generate resources models openapi/kubernetes_v${{ matrix.kube-version }}.json
uv run --only-group compile python -m lightkube-generate resources models openapi/kubernetes_v${{ matrix.kube-version }}.json
- name: Test
run: |
python test_models.py
python test_resources.py
- name: Package (bdist_wheel)
PYTHONPATH=src uv run python test_models.py
PYTHONPATH=src uv run python test_resources.py
- name: Package
run: |
pip install wheel
python setup.py bdist_wheel
- name: Package (sdist)
run: |
python setup.py sdist
uv build
- name: Archive artifact
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ build/
dist/
docs/
site/
src/lightkube/models/
src/lightkube/resources/
test_models.py
test_resources.py
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
94 changes: 94 additions & 0 deletions fetch-and-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

# Fetch list of available Kubernetes versions and let user choose
echo "Fetching available Kubernetes versions..."
PYTHON="uv run --group compile python"
VERSIONS=$($PYTHON -m lightkube-generate.fetch list 20 2>/dev/null | grep -E "^ [0-9]+\.[0-9]+\.[0-9]+$" | sed 's/^ //')

if [ -z "$VERSIONS" ]; then
echo "Failed to fetch versions. Please check your internet connection."
exit 1
fi

# Display versions and prompt user to select
echo ""
echo "Available Kubernetes versions:"
select VERSION in $VERSIONS; do
if [ -n "$VERSION" ]; then
echo ""
echo "Selected version: $VERSION"
break
else
echo "Invalid selection. Please try again."
fi
done

# Validate version format
if [[ ! "$VERSION" =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
echo "Version $VERSION must match expression \d+.\d+.\d"
exit 1
fi

# Extract major.minor for branch name (e.g., 1.35 from 1.35.0)
MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2 | tr '.' '_')
EXPECTED_BRANCH="v${MAJOR_MINOR}"

# Check current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Error: Not in a git repository"
exit 1
fi


if [ "$CURRENT_BRANCH" != "$EXPECTED_BRANCH" ]; then
echo "Warning: You are not on the expected branch for version $VERSION"
read -p "Do you want to create and switch to branch '$EXPECTED_BRANCH'? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Creating new branch $EXPECTED_BRANCH..."
git checkout -b "$EXPECTED_BRANCH"
if [ $? -ne 0 ]; then
echo "Failed to create/switch to branch"
exit 1
fi
fi
fi

# 1. Fetch the OpenAPI spec
echo ""
echo "Step 1/3: Fetching OpenAPI spec for version $VERSION..."
$PYTHON -m lightkube-generate.fetch fetch "$VERSION"
if [ $? -ne 0 ]; then
echo "Failed to fetch spec"
exit 1
fi

# 2. Update workflow file
echo ""
echo "Step 2/3: Updating GitHub workflow..."
$PYTHON -m lightkube-generate.fetch update-workflow "$VERSION"
if [ $? -ne 0 ]; then
echo "Failed to update workflow"
exit 1
fi

# 3. Update documentation
echo ""
echo "Step 3/3: Updating documentation..."
$PYTHON -m lightkube-generate.fetch update-docs "$VERSION"
if [ $? -ne 0 ]; then
echo "Failed to update docs"
exit 1
fi


# 4. Execute release script
bash release.sh "$VERSION"
if [ $? -ne 0 ]; then
echo "Release script failed"
exit 1
fi

echo ""
echo "✓ All steps completed successfully for version $VERSION"
12 changes: 0 additions & 12 deletions fetch-spec.sh

This file was deleted.

39 changes: 30 additions & 9 deletions lightkube-generate/__main__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
from pathlib import Path

from . import compile_resources, compile_models, __version__

from . import __version__, compile_models, compile_resources

if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser(description="Generate resources from k8s API swagger file")
parser.add_argument("command", choices=('resources', 'models'), nargs='+', help="Specification file for Kubernetes")
parser = argparse.ArgumentParser(
description="Generate resources from k8s API swagger file"
)
parser.add_argument(
"command",
choices=("resources", "models"),
nargs="+",
help="Specification file for Kubernetes",
)
parser.add_argument("specs", help="Specification file for Kubernetes")
parser.add_argument("-d", "--dest", help="Package directory", default="lightkube")
parser.add_argument(
"-d", "--dest", help="Package directory", default="src/lightkube"
)
parser.add_argument("--docs", help="Docs directory", default="docs")
parser.add_argument("-t", "--testdir", help="Directory where to generate the test file", default=".")
parser.add_argument(
"-t", "--testdir", help="Directory where to generate the test file", default="."
)
args = parser.parse_args()

compiler_major = __version__.split(".", 1)[0]
if "resources" in args.command:
compile_resources.execute(Path(args.specs), Path(args.dest), Path(args.testdir), Path(args.docs), compiler_major)
compile_resources.execute(
Path(args.specs),
Path(args.dest),
Path(args.testdir),
Path(args.docs),
compiler_major,
)
if "models" in args.command:
compile_models.execute(Path(args.specs), Path(args.dest), Path(args.testdir), Path(args.docs), compiler_major)

compile_models.execute(
Path(args.specs),
Path(args.dest),
Path(args.testdir),
Path(args.docs),
compiler_major,
)
Loading