diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..078b5f0 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7acf6d5 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 }} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7e2de6b..97c1335 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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/" \ No newline at end of file +url = "https://upload.pypi.org/legacy/" + diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..2418f5f --- /dev/null +++ b/tox.ini @@ -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 \ No newline at end of file