Tests & Publish #382
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: Tests & Publish | |
on: | |
push: | |
branches-ignore: | |
- '*-no-ci' | |
tags: | |
- '*' | |
pull_request: | |
schedule: | |
# * is a special character in YAML and must be quoted | |
- cron: '55 2 */7 * *' | |
# Manually triggered workflow | |
workflow_dispatch: | |
inputs: | |
target_repo: | |
description: 'The repository to publish the package' | |
required: true | |
default: 'pypi.org' | |
type: choice | |
options: | |
- pypi.org | |
- test.pypi.org | |
env: | |
INSTALL_POETRY_VERSION: 1.8.* | |
POETRY_VIRTUALENVS_CREATE: true | |
# Hide warning about outdated pip version | |
PIP_DISABLE_PIP_VERSION_CHECK: 1 | |
jobs: | |
debug: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Print env information | |
run: | | |
echo "github.event_name = ${{ github.event_name }}" | |
echo "github.ref = ${{ github.ref }}" | |
echo "is a tag = ${{ startsWith(github.ref, 'refs/tags/') }}" | |
echo "is a manual run = ${{ github.event.inputs.target_repo != '' }}" | |
tests: | |
name: Python ${{ matrix.python }} × Django ${{ matrix.django }} | |
runs-on: ubuntu-latest | |
needs: debug | |
strategy: | |
matrix: | |
# See https://docs.djangoproject.com/en/4.2/faq/install/#what-python-version-can-i-use-with-django | |
# See https://docs.djangoproject.com/en/3.2/faq/install/#what-python-version-can-i-use-with-django | |
# See https://docs.djangoproject.com/en/2.2/faq/install/#what-python-version-can-i-use-with-django | |
# By default, Matrix includes most common compatible Python / Django versions (reduce the number of exclusions) | |
python: ["3.10", "3.9", "3.8", "3.7"] | |
django: ["5.0", "4.2", "4.1", "4.0", "3.2", "3.1", "3.0", "2.2"] | |
exclude: | |
- { python: "3.10", django: "3.1" } | |
- { python: "3.10", django: "3.0" } | |
- { python: "3.10", django: "2.2" } | |
- { python: "3.9", django: "5.0" } | |
- { python: "3.8", django: "5.0" } | |
- { python: "3.7", django: "5.0" } | |
- { python: "3.7", django: "4.2" } | |
- { python: "3.7", django: "4.1" } | |
- { python: "3.7", django: "4.0" } | |
# Now, specifically enable less common Python / Django combinations (Too old or too recent) | |
include: | |
# Very recent python versions | |
- { python: "3.12", django: "5.0" } | |
- { python: "3.12", django: "4.2" } | |
- { python: "3.11", django: "5.0" } | |
- { python: "3.11", django: "4.2" } | |
- { python: "3.11", django: "4.1" } | |
# Very old django version | |
- { python: "3.7", django: "2.1" } | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install poetry | |
run: pipx install 'poetry==${{ env.INSTALL_POETRY_VERSION }}' | |
- name: Setup Python ${{ matrix.python }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python }} | |
cache: 'poetry' | |
- name: Install dependencies in Python ${{ matrix.python }} environment | |
run: | | |
poetry install --no-interaction --with dev,tests --without django | |
poetry run pip install "django==${{ matrix.django }}.*" | |
- name: Pytest | |
run: | | |
echo "Django version: $(poetry run django-admin --version)" | |
poetry run pytest --cov=modernrpc --cov-report=term --cov-report=xml:coverage.xml . | |
- name: Upload coverage results | |
if: github.event_name != 'pull_request' | |
continue-on-error: true | |
env: | |
CODACY_PROJECT_TOKEN : ${{ secrets.CODACY_PROJECT_TOKEN }} | |
COVERALLS_REPO_TOKEN : ${{ secrets.COVERALLS_REPO_TOKEN }} | |
run: | | |
pip install codacy-coverage coveralls | |
# Submit coverage results to codacy.com | |
python-codacy-coverage -r coverage.xml | |
# Submit coverage results to coveralls | |
coveralls | |
lockfile-check: | |
runs-on: ubuntu-latest | |
needs: debug | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup environment | |
run: | | |
pipx install 'poetry==${{ env.INSTALL_POETRY_VERSION }}' | |
poetry install --no-interaction --with code-analysis | |
- name: Check pyproject.toml and poetry.lock consitency | |
run: poetry check | |
linter: | |
runs-on: ubuntu-latest | |
needs: debug | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup environment | |
run: | | |
pipx install 'poetry==${{ env.INSTALL_POETRY_VERSION }}' | |
poetry install --no-interaction --with code-analysis | |
- name: Ruff | |
run: poetry run ruff check . | |
formatter: | |
runs-on: ubuntu-latest | |
needs: debug | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup environment | |
run: | | |
pipx install 'poetry==${{ env.INSTALL_POETRY_VERSION }}' | |
poetry install --no-interaction --with code-analysis | |
- name: Ruff Format | |
run: poetry run ruff format . --check | |
mypy: | |
runs-on: ubuntu-latest | |
needs: debug | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup environment | |
run: | | |
pipx install 'poetry==${{ env.INSTALL_POETRY_VERSION }}' | |
poetry install --no-interaction --with code-analysis | |
- name: Mypy | |
run: poetry run mypy . | |
publish: | |
runs-on: ubuntu-latest | |
needs: [tests, lockfile-check, linter, formatter, mypy] | |
# Only ran on tag push and manual trigger | |
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event.inputs.target_repo != '' | |
env: | |
# inputs.target_repo is set only when workflow was manually triggered. Default to 'pypi.org' for tags push | |
pypi_repository: ${{ github.event.inputs.target_repo || 'pypi.org' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Poetry | |
uses: abatilo/actions-poetry@v2 | |
with: | |
poetry-version: ${{ env.INSTALL_POETRY_VERSION }} | |
- name: Publish on Pypi | |
if: env.pypi_repository == 'pypi.org' | |
run: | | |
echo "Publish on ${{ env.pypi_repository }}" | |
poetry publish --build -u __token__ -p ${{ secrets.PYPI_AUTH_TOKEN }} | |
- name: Publish on TestPypi | |
if: env.pypi_repository == 'test.pypi.org' | |
run: | | |
echo "Publish on ${{ env.pypi_repository }}" | |
poetry config repositories.testpypi https://test.pypi.org/legacy/ | |
poetry publish --build -u __token__ -p ${{ secrets.PYPI_AUTH_TOKEN_TEST }} -r testpypi |