CI/CD #1485
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
pull_request: | |
push: | |
branches: [ main ] | |
schedule: | |
# run every day at midnight | |
- cron: "0 0 * * *" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
lint: | |
name: Run Linters | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install and configure Poetry | |
uses: snok/install-poetry@v1.3.1 | |
with: | |
version: 1.1.13 | |
- name: Lint | |
run: make lint | |
test: | |
name: Run Tests | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# test python versions | |
- python: "3.7" | |
os: ubuntu-latest | |
starlette-version: "lockfile" | |
pydantic-version: "lockfile" | |
- python: "3.8" | |
os: ubuntu-latest | |
starlette-version: "lockfile" | |
pydantic-version: "lockfile" | |
- python: "3.9" | |
os: ubuntu-latest | |
starlette-version: "lockfile" | |
pydantic-version: "lockfile" | |
- python: "3.10" | |
os: ubuntu-latest | |
starlette-version: "lockfile" | |
pydantic-version: "lockfile" | |
# test OSs | |
- python: "3.x" | |
os: macos-latest | |
starlette-version: "lockfile" | |
pydantic-version: "lockfile" | |
- python: "3.x" | |
os: windows-latest | |
starlette-version: "lockfile" | |
pydantic-version: "lockfile" | |
# test Starlette | |
- python: "3.x" | |
os: ubuntu-latest | |
starlette-version: "starlette==0.21.0" | |
pydantic-version: "lockfile" | |
- python: "3.x" | |
os: ubuntu-latest | |
starlette-version: "git+https://github.com/encode/starlette.git@master" | |
pydantic-version: "lockfile" | |
# test Pydantic | |
- python: "3.x" | |
os: ubuntu-latest | |
starlette-version: "lockfile" | |
pydantic-version: "pydantic==1.10.2" | |
# Disabling because of high churn for Pydantic v2 | |
# - python: "3.x" | |
# os: ubuntu-latest | |
# starlette-version: "lockfile" | |
# pydantic-version: "git+https://github.com/samuelcolvin/pydantic.git@main" | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python ${{ matrix.python }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Install and configure Poetry | |
uses: snok/install-poetry@v1.3.1 | |
with: | |
version: 1.1.13 | |
- name: Test | |
env: | |
STARLETTE: ${{ matrix.starlette-version }} | |
PYDANTIC: ${{ matrix.pydantic-version }} | |
run: | | |
if [ "$STARLETTE" != "lockfile" ] | |
then | |
poetry remove --dev fastapi || true | |
poetry remove starlette | |
poetry add ${STARLETTE} | |
fi | |
if [ "$PYDANTIC" != "lockfile" ] | |
then | |
poetry remove pydantic | |
poetry add ${PYDANTIC} | |
poetry lock --no-update | |
fi | |
make test | |
- name: Export Coverage Report | |
run: | | |
poetry run pip install "coverage[toml]" | |
poetry run coverage xml | |
- name: Upload code coverage | |
uses: codecov/codecov-action@v2.1.0 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
file: ./coverage.xml | |
name: xpresso | |
env_vars: OS,PYTHON | |
fail_ci_if_error: true | |
version-check: | |
name: Check Version Bump | |
if: github.ref != 'refs/heads/main' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
path: current | |
- uses: actions/checkout@v2 | |
with: | |
ref: main | |
path: main | |
- name: Install and configure Poetry | |
uses: snok/install-poetry@v1.3.1 | |
with: | |
version: 1.1.13 | |
- name: Check version bump | |
run: | | |
cd $GITHUB_WORKSPACE/current | |
NEW_VERSION=$(poetry version -s) | |
cd $GITHUB_WORKSPACE/main | |
OLD_VERSION=$(poetry version -s) | |
python -c "from packaging import version;assert version.parse(\"${NEW_VERSION}\") > version.parse(\"${OLD_VERSION}\"), \"β Bad version bump detected: you must bump the version in pyproject.toml\"" | |
python -c "print(\"β Version will be bumped from ${OLD_VERSION} to ${NEW_VERSION}\")" | |
docs: | |
if: github.ref == 'refs/heads/main' && github.event_name != 'schedule' | |
concurrency: docs-branch | |
name: π Deploy Docs π | |
runs-on: ubuntu-latest | |
needs: ["test", "lint"] | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # fetch all commits/branches | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
- name: Install and configure Poetry | |
uses: snok/install-poetry@v1.3.1 | |
with: | |
version: 1.1.13 | |
- name: Deploy docs | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
make docs-deploy | |
pypi: | |
if: github.ref == 'refs/heads/main' && github.event_name != 'schedule' | |
name: π PyPi Release π¦ | |
runs-on: ubuntu-latest | |
needs: ["test", "lint"] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
- name: Install and configure Poetry | |
uses: snok/install-poetry@v1.3.1 | |
with: | |
version: 1.1.13 | |
- name: Release on PyPi | |
continue-on-error: true # allow pushes to main that don't release | |
id: pypi | |
run: | | |
PACKAGE_VERSION=$(poetry version -s) | |
echo "package_version=$PACKAGE_VERSION" >> $GITHUB_ENV | |
printf "\nSee this release on GitHub: [v$PACKAGE_VERSION](https://github.com/$GITHUB_REPOSITORY/releases/tag/$PACKAGE_VERSION)\n" >> README.md | |
poetry config pypi-token.pypi "${{ secrets.PYPI_TOKEN }}" | |
poetry publish --build | |
- name: π Create GitHub Release πΊ | |
uses: ncipollo/release-action@v1 | |
if: steps.pypi.outcome == 'success' | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ env.package_version }} | |
generateReleaseNotes: true |