Skip to content

Commit

Permalink
Merge pull request #142 from magmax/ci/add-code-coverage
Browse files Browse the repository at this point in the history
Add code coverage to Github Actions
  • Loading branch information
staticdev authored Dec 27, 2021
2 parents dee4408 + 0fd6de0 commit cd989c0
Show file tree
Hide file tree
Showing 34 changed files with 624 additions and 189 deletions.
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pip==21.3.1
nox==2021.10.1
nox-poetry==0.9.0
poetry==1.1.12
virtualenv==20.10.0
89 changes: 66 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,73 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
---
name: Release

on:
release:
types: [created]
push:
branches:
- main
- master

jobs:
deploy:

release:
name: Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Check out the repository
uses: actions/[email protected]
with:
fetch-depth: 2

- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.10"

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
run: |
pip install --constraint=.github/workflows/constraints.txt poetry
poetry --version
- name: Check if there is a parent commit
id: check-parent-commit
run: |
echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)"
- name: Detect and tag new version
id: check-version
if: steps.check-parent-commit.outputs.sha
uses: salsify/[email protected]
with:
version-command: |
bash -o pipefail -c "poetry version | awk '{ print \$2 }'"
- name: Bump version for developmental release
if: "! steps.check-version.outputs.tag"
run: |
poetry version patch &&
version=$(poetry version | awk '{ print $2 }') &&
poetry version $version.dev.$(date +%s)
- name: Build package
run: |
poetry build --ansi
- name: Publish package on PyPI
if: steps.check-version.outputs.tag
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

- name: Publish the release notes
uses: release-drafter/[email protected]
with:
publish: ${{ steps.check-version.outputs.tag != '' }}
tag: ${{ steps.check-version.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157 changes: 128 additions & 29 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,137 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
---
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
- push
- pull_request

jobs:
build:

tests:
name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
runs-on: ${{ matrix.platform }}
include:
- { python: "3.10", os: "ubuntu-latest", session: "pre-commit" }
- { 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" }

env:
NOXSESSION: ${{ matrix.session }}
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"

steps:
- uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements-dev.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- name: Check out the repository
uses: actions/[email protected]

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

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Upgrade pip in virtual environments
shell: python
run: |
import os
import pip
with open(os.environ["GITHUB_ENV"], mode="a") as io:
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
- name: Install Poetry
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: Compute pre-commit cache key
if: matrix.session == 'pre-commit'
id: pre-commit-cache
shell: python
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/[email protected]
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
run: |
nox --force-color --python=${{ matrix.python }}
- name: Upload coverage data
if: always() && matrix.session == 'tests'
uses: "actions/[email protected]"
with:
name: coverage-data
path: ".coverage.*"

coverage:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repository
uses: actions/[email protected]

- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.10"

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Poetry
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/[email protected]
with:
name: coverage-data

- name: Combine coverage data and display human readable report
run: |
nox --force-color --session=coverage
- name: Create coverage report
run: |
nox --force-color --session=coverage -- xml
- name: Upload coverage report
uses: codecov/[email protected]
13 changes: 5 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
*~
\#*
\.\#*
*.pyc
*.egg-info/
venv/
.coverage*
coverage.xml
dist/
build/
runtests.py
/.coverage
/.coverage.*
/.nox/
/dist/
.cache
*.swp
.ropeproject/
__pycache__/
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ repos:
rev: 6de8252c035844f1e679f509b5f37340b44d5c39
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-yaml
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
hooks:
Expand Down
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

13 changes: 6 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
==================== =================================================================================
Tests |Tests| |coveralls|
Tests |Tests| |Codecov|
-------------------- ---------------------------------------------------------------------------------
Downloads |pip dm| |pip dw| |pip dd|
-------------------- ---------------------------------------------------------------------------------
Expand Down Expand Up @@ -28,7 +28,7 @@ Installation
============

.. code:: console
pip install inquirer
Expand All @@ -46,7 +46,7 @@ Text
.. code:: python
import re
import inquirer
questions = [
inquirer.Text('name', message="What's your name"),
Expand Down Expand Up @@ -156,9 +156,9 @@ Licensed under `the MIT license`_.
.. |Tests| image:: https://github.com/magmax/python-inquirer/workflows/Tests/badge.svg
:target: https://github.com/magmax/python-inquirer/actions?workflow=Tests
:alt: Tests
.. |coveralls| image:: https://coveralls.io/repos/magmax/python-inquirer/badge.png
:target: `Coveralls`_
:alt: Coveralls results_
.. |Codecov| image:: https://codecov.io/gh/magmax/python-inquirer/branch/master/graph/badge.svg
:target: https://app.codecov.io/gh/magmax/python-inquirer
:alt: Codecov
.. |pip version| image:: https://img.shields.io/pypi/v/inquirer.svg
:target: https://pypi.python.org/pypi/inquirer
:alt: Latest PyPI version
Expand Down Expand Up @@ -201,7 +201,6 @@ Licensed under `the MIT license`_.
:alt: Example of Checkbox Question

.. _Inquirer.js: https://github.com/SBoudrias/Inquirer.js
.. _Coveralls: https://coveralls.io/r/magmax/python-inquirer
.. _examples/: https://github.com/magmax/python-inquirer/tree/master/examples
.. _`download the python-inquirer code from GitHub`: https://github.com/magmax/python-inquirer
.. _`download the wheel from Pypi`: https://pypi.python.org/pypi/inquirer
Expand Down
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

comment: false
coverage:
status:
project:
default:
target: "90"
patch:
default:
target: "90"
Loading

0 comments on commit cd989c0

Please sign in to comment.