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
100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: CI

on:
pull_request:
branches:
- master
- main
push:
branches:
- master
- main

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12']

steps:
- name: Checkout repository
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@v4
with:
enable-cache: true

- name: Install dependencies
run: |
uv sync --dev

# - name: Run code formatting check
# run: |
# uv run ruff format --check .

# - name: Run linting
# run: |
# uv run ruff check .

- name: Run type checking
run: |
uv run mypy

- name: Run tests
run: |
make test

- name: Run integration tests
run: |
uv run python -m pytest tests/integration/

- name: Run typeguard
if: matrix.os == 'ubuntu-latest'
run: |
make typeguard

publish-check:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Check if version exists on PyPI
id: version_check
run: |
VERSION=$(uv version | awk '{print $2}')
echo "version=$VERSION" >> $GITHUB_OUTPUT

# Check if version already exists on PyPI
if curl -s "https://pypi.org/pypi/pytest-api-cov/$VERSION/json" > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Version $VERSION already published to PyPI"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Version $VERSION not found on PyPI"
fi

- name: Comment on publish workflow
if: steps.version_check.outputs.exists == 'true'
run: |
echo "::warning::Version ${{ steps.version_check.outputs.version }} already exists on PyPI. Update version in pyproject.toml before publishing."

111 changes: 111 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Publish to PyPI

on:
push:
branches:
- master
- main
workflow_dispatch: # Allow manual triggering

jobs:
publish:
runs-on: ubuntu-latest

permissions:
contents: write # Required to create and push tags
id-token: write # Required for OIDC authentication (if using PyPI trusted publishing)

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

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

- name: Read version from pyproject.toml
id: version
run: |
VERSION=$(uv version | awk '{print $2}')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Package version: $VERSION"

- name: Check if version already published
id: check_published
run: |
VERSION="${{ steps.version.outputs.version }}"

# Check if Git tag exists
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Git tag v$VERSION already exists"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Git tag v$VERSION does not exist"
fi

# Check if version exists on PyPI
if curl -s "https://pypi.org/pypi/pytest-api-cov/$VERSION/json" > /dev/null 2>&1; then
echo "pypi_exists=true" >> $GITHUB_OUTPUT
echo "Version $VERSION already published to PyPI"
else
echo "pypi_exists=false" >> $GITHUB_OUTPUT
echo "Version $VERSION not found on PyPI"
fi

- name: Create version tag
if: steps.check_published.outputs.tag_exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.version.outputs.version }}" -m "Release version ${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"

- name: Set up build environment
if: steps.check_published.outputs.pypi_exists == 'false'
run: |
uv sync --dev

- name: Run pipeline (tests, linting, etc.)
if: steps.check_published.outputs.pypi_exists == 'false'
run: make pipeline

- name: Build package
if: steps.check_published.outputs.pypi_exists == 'false'
run: make build

- name: Publish to PyPI
if: steps.check_published.outputs.pypi_exists == 'false'
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
if [ -z "$PYPI_TOKEN" ]; then
echo "❌ PYPI_TOKEN secret is not set. Please configure it in repository settings."
echo " Settings → Secrets and variables → Actions → New repository secret"
exit 1
fi
echo $PYPI_TOKEN > /tmp/pypi_token.txt
uv publish --token $(cat /tmp/pypi_token.txt)
rm /tmp/pypi_token.txt

- name: Verify publication
if: steps.check_published.outputs.pypi_exists == 'false'
run: |
sleep 10 # Wait for PyPI to index the package
uv run --with pytest-api-cov --no-project -- python -c \
"import pytest_api_cov; print(f'✅ Published version: {pytest_api_cov.__version__}')"

- name: Skip publish - already published
if: steps.check_published.outputs.pypi_exists == 'true'
run: |
echo "✅ Version ${{ steps.version.outputs.version }} already published to PyPI. Skipping publish."

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Makefile

.PHONY: ruff mypy test clean clean-all
.PHONY: ruff mypy test clean clean-all version

PYPI_TOKEN := $(shell type .pypi_token 2>nul || echo "")
TEST_PYPI_TOKEN := $(shell type .test_pypi_token 2>nul || echo "")

version:
@uv version

ruff:
@echo "Running ruff..."
@uv run ruff format .
Expand Down
Loading
Loading