Skip to content

Initial commit: FastAPI Versioner with CI/CD pipeline #2

Initial commit: FastAPI Versioner with CI/CD pipeline

Initial commit: FastAPI Versioner with CI/CD pipeline #2

Workflow file for this run

name: CI/CD
on:
push:
branches: [ main, master, develop ]
tags: [ 'v*' ]
pull_request:
branches: [ main, master, develop ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Run tests with pytest
run: |
uv run pytest tests/ -v --cov=src/fastapi_versioner --cov-report=xml --cov-report=html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Run ruff linter
run: |
uv run ruff check src/ tests/ examples/
- name: Run ruff formatter
run: |
uv run ruff format --check src/ tests/ examples/
- name: Run mypy
run: |
uv run mypy src/fastapi_versioner/
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Run bandit security linter
run: |
uv run bandit -r src/ -f json -o bandit-report.json || true
- name: Upload bandit report
uses: actions/upload-artifact@v3
if: always()
with:
name: bandit-report
path: bandit-report.json
build:
runs-on: ubuntu-latest
needs: [test, lint, security]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "latest"
- name: Build package
run: |
uv build
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
publish:
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
environment: release
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# Alternatively, use trusted publishing (recommended):
# Remove the password line above and uncomment the line below
# repository-url: https://upload.pypi.org/legacy/
release:
runs-on: ubuntu-latest
needs: publish
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
body: |
## Changes
See [CHANGELOG.md](CHANGELOG.md) for details.
## Installation
```bash
pip install fastapi-versioner==${{ github.ref_name }}
```