Skip to content

Merge pull request #16 from Pymetheus/develop #14

Merge pull request #16 from Pymetheus/develop

Merge pull request #16 from Pymetheus/develop #14

Workflow file for this run

name: CI
on:
push:
branches:
- main
# Uncomment to enable Git Flow workflow
# - develop
workflow_dispatch: {}
permissions:
actions: read
pull-requests: read
contents: read
statuses: write
env:
PYTHON_VERSION: "3.12"
jobs:
verify-version:
name: Verify Project Version Integrity
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check if version already exists
id: version_check
run: |
CURRENT_VERSION=$(grep '^version =' pyproject.toml | cut -d '"' -f 2)
TAG_NAME="v$CURRENT_VERSION"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "::error title=Version Conflict::Version $CURRENT_VERSION already exists as a Git tag ($TAG_NAME).%0A🚨 Action required: Alter 'version' in pyproject.toml before pushing."
exit 1
fi
echo "✅ Version $CURRENT_VERSION is new. Proceeding..."
test:
name: Run Full Test Suite
runs-on: ubuntu-latest
needs: verify-version
strategy:
matrix:
python-version: ['3.12', '3.13', '3.14']
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install uv and cache dependencies
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Install project dependencies
run: |
uv lock
uv sync
- name: Run mypy
run: uv run mypy src/
- name: Run tests with coverage
run: |
mkdir -p .log/coverage
uv run pytest
- name: Upload coverage report as artifact
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION }}
uses: actions/upload-artifact@v6
with:
name: coverage-report-${{ matrix.python-version }}-${{ matrix.os }}-${{ github.run_id }}
path: |
.log/coverage/htmlcov
.log/coverage/coverage.xml
- name: Upload coverage reports to Codecov
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
build-distribution:
name: Build Package Distribution
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Build sdist and wheel
run: |
uv build
- name: Upload distribution as artifact
uses: actions/upload-artifact@v6
with:
name: python-package-distributions-${{ github.sha }}
path: dist/
build-docker:
name: Build Docker Image & Smoke Test
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Build Docker image
run: |
docker build -t ${{ github.repository }}:${{ github.sha }} -f docker/Dockerfile .
- name: Smoke Test Container
run: |
docker run --rm ${{ github.repository }}:${{ github.sha }}
smoke-test:
name: Smoke Test Distribution
runs-on: ubuntu-latest
needs: build-distribution
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: python-package-distributions-${{ github.sha }}
path: dist/
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install the Wheel
run: |
pip install dist/*.whl
- name: Discover and verify Package
run: |
PKG_NAME=$(ls src | head -n 1)
echo "Detected package: $PKG_NAME"
python -c "import $PKG_NAME; print(f'Successfully imported $PKG_NAME version {$PKG_NAME.__version__}')"
- name: Verify CLI
run: |
WHEEL_FILE=$(ls dist/*.whl | head -n 1)
DIST_NAME=$(basename "$WHEEL_FILE" | cut -d'-' -f1)
echo "Searching for CLI entry points in distribution: $DIST_NAME"
CLI_COMMAND=$(python3 <<EOF
import importlib.metadata
import sys
try:
dist = importlib.metadata.distribution('$DIST_NAME')
scripts = [ep.name for ep in dist.entry_points if ep.group == 'console_scripts']
if scripts:
print(scripts[0])
except importlib.metadata.PackageNotFoundError:
pass
EOF
)
if [ -n "$CLI_COMMAND" ]; then
echo "Found CLI command for $DIST_NAME: $CLI_COMMAND"
$CLI_COMMAND
else
echo "No console_scripts found for $DIST_NAME. Skipping CLI smoke test."
fi