Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Oct 9, 2024
1 parent 5550a0e commit 1eaec82
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 263 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/labeler.yml

This file was deleted.

79 changes: 0 additions & 79 deletions .github/workflows/release.yml

This file was deleted.

235 changes: 106 additions & 129 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,154 +1,131 @@
# This workflow will install Python dependencies,
# run tests and lint with a variety of Python versions
---
name: Tests

on:
- push
- pull_request
on: [push, pull_request]

jobs:
tests:
name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
cpython:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { python: "3.10", os: "ubuntu-latest", session: "pre-commit" }
- { python: "3.10", os: "ubuntu-latest", session: "safety" }
- { python: "3.10", os: "ubuntu-latest", session: "mypy" }
- { python: "3.9", os: "ubuntu-latest", session: "mypy" }
- { python: "3.8", os: "ubuntu-latest", session: "mypy" }
- { python: "3.7", os: "ubuntu-latest", session: "mypy" }
- { python: "3.10", os: "ubuntu-latest", session: "tests" }
- { python: "3.9", os: "ubuntu-latest", session: "tests" }
- { python: "3.8", os: "ubuntu-latest", session: "tests" }
- { python: "3.7", os: "ubuntu-latest", session: "tests" }
- { python: "3.10", os: "windows-latest", session: "tests" }
- { python: "3.10", os: "macos-latest", session: "tests" }
- { python: "3.10", os: "ubuntu-latest", session: "typeguard" }
- { python: "3.10", os: "ubuntu-latest", session: "xdoctest" }
- { python: "3.10", os: "ubuntu-latest", session: "docs-build" }

env:
NOXSESSION: ${{ matrix.session }}
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
python-version: ['3.9', '3.10', 3.11', '3.12', '3.13-dev', 3.14-dev]

steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python }}
uses: actions/[email protected]
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Upgrade pip
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Upgrade pip in virtual environments
shell: python
python -m pip install --upgrade pip
python -m pip install -e ".[tests]"
- name: Test with pytest
run: |
import os
import pip
pytest tests --cov=tests --cov=vercheck --cov-report=xml
- name: "Upload coverage to Codecov"
if: ${{ matrix.python-version==3.12 }}
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

with open(os.environ["GITHUB_ENV"], mode="a") as io:
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
static-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']

- name: Install Poetry
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
python -m pip install --upgrade pip
python -m pip install -e ".[typing, complexity, linting]"
- name: Typecheck
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
nox --version
- name: Compute pre-commit cache key
if: matrix.session == 'pre-commit'
id: pre-commit-cache
shell: python
mypy vercheck tests
- name: Linting
run: |
import hashlib
import sys
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
print("::set-output name=result::{}".format(result))
- name: Restore pre-commit cache
uses: actions/cache@v3
if: matrix.session == 'pre-commit'
with:
path: ~/.cache/pre-commit
key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.pre-commit-cache.outputs.result }}-
- name: Run Nox
flake8 vercheck tests --max-line-length=88
black --check vercheck tests
ruff check --no-fix vercheck tests
yamllint .github/workflows/
- name: Check complexity
run: |
nox --python=${{ matrix.python }}
radon cc --min B vercheck
radon mi --min B vercheck
lizard -l python -w vercheck
- name: Upload coverage data
if: always() && matrix.session == 'tests'
uses: "actions/upload-artifact@v3"
with:
name: coverage-data
path: ".coverage.*"

- name: Upload documentation
if: matrix.session == 'docs-build'
uses: actions/upload-artifact@v3
with:
name: docs
path: docs/_build

coverage:
build-package:
name: Build & inspect our package.
runs-on: ubuntu-latest
needs: tests
needs: [cpython, static-tests]
steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/[email protected]
- uses: actions/checkout@v4
- uses: hynek/build-and-inspect-python-package@v2
- uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Upgrade pip
python-version: '3.12'
- name: Check with pyroma
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
python -m pip install pyroma
pyroma .
- name: Check tag name
if: >-
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags')
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Install Nox
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
nox --version
- name: Download coverage data
uses: actions/download-artifact@v3
echo "Tag name from GITHUB_REF_NAME: $GITHUB_REF_NAME"
vercheck $GITHUB_REF_NAME
test-publish:
if: >-
github.event_name == 'push' &&
github.repository == 'cleder/vercheck' &&
startsWith(github.ref, 'refs/tags')
needs: build-package
name: Test install on TestPyPI
runs-on: ubuntu-latest
environment: test-release
permissions:
id-token: write
steps:
- name: Download packages built by build-package
uses: actions/download-artifact@v4
with:
name: coverage-data
name: Packages
path: dist

- name: Combine coverage data and display human readable report
run: |
nox --session=coverage
- name: Create coverage report
run: |
nox --session=coverage -- xml
- name: Upload package to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

publish:
if: >-
github.event_name == 'push' &&
github.repository == 'cleder/vercheck' &&
github.ref == 'refs/heads/main'
needs: build-package
name: Build and publish to PyPI and TestPyPI
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Download packages built by build-package
uses: actions/download-artifact@v4
with:
name: Packages
path: dist

- name: Upload coverage report
uses: codecov/[email protected]
- name: Publish distribution 📦 to PyPI for push to main
uses: pypa/gh-action-pypi-publish@release/v1
...
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ repos:
rev: v0.3.1
hooks:
- id: absolufy-imports
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.6.9'
hooks:
Expand Down
Loading

0 comments on commit 1eaec82

Please sign in to comment.