Skip to content

Commit

Permalink
feature/Added deployment and tox
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowGenerator committed Mar 1, 2024
1 parent ad8c2bf commit 9b32aee
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 39 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Deploy

on:
push:
branches: [main]
pull_request:
release:
types:
- published
workflow_dispatch:

permissions:
contents: read

jobs:
# Always build & lint package.
build-package:
name: Build & verify package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: hynek/build-and-inspect-python-package@v1

# Upload to Test PyPI on every commit on main.
release-test-pypi:
name: Publish in-dev package to test.pypi.org
if: |
github.repository_owner == 'WindowGenerator42'
&& github.event_name == 'push'
&& github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-package

permissions:
id-token: write

steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v3
with:
name: Packages
path: dist

- name: Upload package to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

# Upload to real PyPI on GitHub Releases.
release-pypi:
name: Publish released package to pypi.org
if: |
github.repository_owner == 'WindowGenerator42'
&& github.event.action == 'published'
runs-on: ubuntu-latest
needs: build-package

permissions:
id-token: write

steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v3
with:
name: Packages
path: dist

- name: Upload package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
49 changes: 49 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---

name: Tests

on: [push, pull_request, workflow_dispatch]

env:
FORCE_COLOR: 1

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# when adding new versions, update the one used to test
# friend projects below to the latest one
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip
cache-dependency-path: .github/workflows/tests.yml

- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U wheel
python -m pip install -U tox
- name: Download more tests from friend projects
if: matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
run: sh download-more-tests.sh
- name: Tox tests
run: |
tox -e py
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
flags: ${{ matrix.os }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
52 changes: 13 additions & 39 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ dependencies = [
"anyio>=3.7.1,<5.0.0",
]

[project.optional-dependencies]
tests = [
"coverage[toml]>=6.5",
"pytest-cov",
"pytest",
"httpx>=0.22.0",
"trio==0.24.0",
"mypy>=1.0.0",
]

[project.urls]
Documentation = "https://github.com/WindowGenerator/starlette-responses-kit#readme"
Issues = "https://github.com/WindowGenerator/starlette-responses-kit/issues"
Expand All @@ -41,49 +51,13 @@ Source = "https://github.com/WindowGenerator/starlette-responses-kit"
[tool.hatch.version]
path = "starlette_responses_kit/__init__.py"

[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
"httpx>=0.22.0",
"trio==0.20.0",
]
[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
check = "mypy --install-types --non-interactive {args:starlette_responses_kit}"

[[tool.hatch.envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.types]
dependencies = [
"mypy>=1.0.0",
]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:starlette_responses_kit}"

[tool.coverage.run]
source_pkgs = ["starlette_responses_kit"]
branch = true
parallel = true
omit = [
"starlette_responses_kit/__init__.py",
]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[publish.index.repos.main]
url = "https://upload.pypi.org/legacy/"
url = "https://upload.pypi.org/legacy/"

29 changes: 29 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[tox]
requires =
tox>=4.2
env_list =
lint
py{py3, 312, 311, 310, 39, 38}

[testenv]
extras =
tests
pass_env =
FORCE_COLOR
commands =
{envpython} -m pytest \
--cov starlette_responses_kit \
--cov tests \
--cov-report html \
--cov-report term \
--cov-report xml \
{posargs}

[testenv:lint]
skip_install = true
deps =
pre-commit
pass_env =
PRE_COMMIT_COLOR
commands =
pre-commit run --all-files --show-diff-on-failure

0 comments on commit 9b32aee

Please sign in to comment.