Skip to content

Commit cd989c0

Browse files
authored
Merge pull request #142 from magmax/ci/add-code-coverage
Add code coverage to Github Actions
2 parents dee4408 + 0fd6de0 commit cd989c0

34 files changed

Lines changed: 624 additions & 189 deletions

.coveragerc

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/constraints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pip==21.3.1
2+
nox==2021.10.1
3+
nox-poetry==0.9.0
4+
poetry==1.1.12
5+
virtualenv==20.10.0

.github/workflows/release.yml

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,73 @@
1-
# This workflow will upload a Python Package using Twine when a release is created
2-
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
1+
---
32
name: Release
43

54
on:
6-
release:
7-
types: [created]
5+
push:
6+
branches:
7+
- main
8+
- master
89

910
jobs:
10-
deploy:
11-
11+
release:
12+
name: Release
1213
runs-on: ubuntu-latest
13-
1414
steps:
15-
- uses: actions/checkout@v2
16-
- name: Set up Python
17-
uses: actions/setup-python@v2
18-
with:
19-
python-version: '3.x'
20-
- name: Install dependencies
21-
run: |
22-
python -m pip install --upgrade pip
23-
pip install setuptools wheel twine
24-
- name: Build and publish
25-
env:
26-
TWINE_USERNAME: __token__
27-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
28-
run: |
29-
python setup.py sdist bdist_wheel
30-
twine upload dist/*
15+
- name: Check out the repository
16+
uses: actions/checkout@v2.4.0
17+
with:
18+
fetch-depth: 2
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v2.3.1
22+
with:
23+
python-version: "3.10"
24+
25+
- name: Upgrade pip
26+
run: |
27+
pip install --constraint=.github/workflows/constraints.txt pip
28+
pip --version
29+
30+
- name: Install Poetry
31+
run: |
32+
pip install --constraint=.github/workflows/constraints.txt poetry
33+
poetry --version
34+
35+
- name: Check if there is a parent commit
36+
id: check-parent-commit
37+
run: |
38+
echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)"
39+
40+
- name: Detect and tag new version
41+
id: check-version
42+
if: steps.check-parent-commit.outputs.sha
43+
uses: salsify/action-detect-and-tag-new-version@v2.0.1
44+
with:
45+
version-command: |
46+
bash -o pipefail -c "poetry version | awk '{ print \$2 }'"
47+
48+
- name: Bump version for developmental release
49+
if: "! steps.check-version.outputs.tag"
50+
run: |
51+
poetry version patch &&
52+
version=$(poetry version | awk '{ print $2 }') &&
53+
poetry version $version.dev.$(date +%s)
54+
55+
- name: Build package
56+
run: |
57+
poetry build --ansi
58+
59+
60+
- name: Publish package on PyPI
61+
if: steps.check-version.outputs.tag
62+
uses: pypa/gh-action-pypi-publish@v1.4.2
63+
with:
64+
user: __token__
65+
password: ${{ secrets.PYPI_API_TOKEN }}
66+
67+
- name: Publish the release notes
68+
uses: release-drafter/release-drafter@v5.15.0
69+
with:
70+
publish: ${{ steps.check-version.outputs.tag != '' }}
71+
tag: ${{ steps.check-version.outputs.tag }}
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 128 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,137 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
1+
---
32
name: Tests
43

54
on:
6-
push:
7-
branches: [ master ]
8-
pull_request:
9-
branches: [ master ]
5+
- push
6+
- pull_request
107

118
jobs:
12-
build:
13-
9+
tests:
10+
name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }}
11+
runs-on: ${{ matrix.os }}
1412
strategy:
13+
fail-fast: false
1514
matrix:
16-
platform: [ubuntu-latest, macos-latest, windows-latest]
17-
python-version: ["3.7", "3.8", "3.9", "3.10"]
18-
runs-on: ${{ matrix.platform }}
15+
include:
16+
- { python: "3.10", os: "ubuntu-latest", session: "pre-commit" }
17+
- { python: "3.10", os: "ubuntu-latest", session: "tests" }
18+
- { python: "3.9", os: "ubuntu-latest", session: "tests" }
19+
- { python: "3.8", os: "ubuntu-latest", session: "tests" }
20+
- { python: "3.7", os: "ubuntu-latest", session: "tests" }
21+
- { python: "3.10", os: "windows-latest", session: "tests" }
22+
- { python: "3.10", os: "macos-latest", session: "tests" }
23+
24+
env:
25+
NOXSESSION: ${{ matrix.session }}
26+
FORCE_COLOR: "1"
27+
PRE_COMMIT_COLOR: "always"
1928

2029
steps:
21-
- uses: actions/checkout@v2.4.0
22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2.3.1
24-
with:
25-
python-version: ${{ matrix.python-version }}
26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
python -m pip install -r requirements-dev.txt
30-
- name: Lint with flake8
31-
run: |
32-
# stop the build if there are Python syntax errors or undefined names
33-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
34-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
35-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
36-
- name: Test with pytest
37-
run: |
38-
pytest
30+
- name: Check out the repository
31+
uses: actions/checkout@v2.4.0
32+
33+
- name: Set up Python ${{ matrix.python }}
34+
uses: actions/setup-python@v2.3.1
35+
with:
36+
python-version: ${{ matrix.python }}
37+
38+
- name: Upgrade pip
39+
run: |
40+
pip install --constraint=.github/workflows/constraints.txt pip
41+
pip --version
42+
43+
- name: Upgrade pip in virtual environments
44+
shell: python
45+
run: |
46+
import os
47+
import pip
48+
with open(os.environ["GITHUB_ENV"], mode="a") as io:
49+
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
50+
51+
- name: Install Poetry
52+
run: |
53+
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
54+
poetry --version
55+
56+
- name: Install Nox
57+
run: |
58+
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
59+
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
60+
nox --version
61+
62+
- name: Compute pre-commit cache key
63+
if: matrix.session == 'pre-commit'
64+
id: pre-commit-cache
65+
shell: python
66+
run: |
67+
import hashlib
68+
import sys
69+
python = "py{}.{}".format(*sys.version_info[:2])
70+
payload = sys.version.encode() + sys.executable.encode()
71+
digest = hashlib.sha256(payload).hexdigest()
72+
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
73+
print("::set-output name=result::{}".format(result))
74+
75+
- name: Restore pre-commit cache
76+
uses: actions/cache@v2.1.7
77+
if: matrix.session == 'pre-commit'
78+
with:
79+
path: ~/.cache/pre-commit
80+
key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
81+
restore-keys: |
82+
${{ steps.pre-commit-cache.outputs.result }}-
83+
84+
- name: Run Nox
85+
run: |
86+
nox --force-color --python=${{ matrix.python }}
87+
88+
- name: Upload coverage data
89+
if: always() && matrix.session == 'tests'
90+
uses: "actions/upload-artifact@v2.3.1"
91+
with:
92+
name: coverage-data
93+
path: ".coverage.*"
94+
95+
coverage:
96+
runs-on: ubuntu-latest
97+
needs: tests
98+
steps:
99+
- name: Check out the repository
100+
uses: actions/checkout@v2.4.0
101+
102+
- name: Set up Python
103+
uses: actions/setup-python@v2.3.1
104+
with:
105+
python-version: "3.10"
106+
107+
- name: Upgrade pip
108+
run: |
109+
pip install --constraint=.github/workflows/constraints.txt pip
110+
pip --version
111+
112+
- name: Install Poetry
113+
run: |
114+
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
115+
poetry --version
116+
117+
- name: Install Nox
118+
run: |
119+
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
120+
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
121+
nox --version
122+
123+
- name: Download coverage data
124+
uses: actions/download-artifact@v2.1.0
125+
with:
126+
name: coverage-data
127+
128+
- name: Combine coverage data and display human readable report
129+
run: |
130+
nox --force-color --session=coverage
131+
132+
- name: Create coverage report
133+
run: |
134+
nox --force-color --session=coverage -- xml
135+
136+
- name: Upload coverage report
137+
uses: codecov/codecov-action@v2.1.0

.gitignore

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
*~
2-
\#*
3-
\.\#*
42
*.pyc
53
*.egg-info/
64
venv/
7-
.coverage*
8-
coverage.xml
9-
dist/
10-
build/
11-
runtests.py
5+
/.coverage
6+
/.coverage.*
7+
/.nox/
8+
/dist/
129
.cache
1310
*.swp
14-
.ropeproject/
11+
__pycache__/

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ repos:
1616
rev: 6de8252c035844f1e679f509b5f37340b44d5c39
1717
hooks:
1818
- id: flake8
19+
- repo: https://github.com/pre-commit/pre-commit-hooks
20+
rev: v4.1.0
21+
hooks:
22+
- id: check-yaml
23+
- id: trailing-whitespace
1924
- repo: https://github.com/asottile/pyupgrade
2025
rev: v2.29.1
2126
hooks:

MANIFEST.in

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
==================== =================================================================================
2-
Tests |Tests| |coveralls|
2+
Tests |Tests| |Codecov|
33
-------------------- ---------------------------------------------------------------------------------
44
Downloads |pip dm| |pip dw| |pip dd|
55
-------------------- ---------------------------------------------------------------------------------
@@ -28,7 +28,7 @@ Installation
2828
============
2929

3030
.. code:: console
31-
31+
3232
pip install inquirer
3333
3434
@@ -46,7 +46,7 @@ Text
4646
.. code:: python
4747
4848
import re
49-
49+
5050
import inquirer
5151
questions = [
5252
inquirer.Text('name', message="What's your name"),
@@ -156,9 +156,9 @@ Licensed under `the MIT license`_.
156156
.. |Tests| image:: https://github.com/magmax/python-inquirer/workflows/Tests/badge.svg
157157
:target: https://github.com/magmax/python-inquirer/actions?workflow=Tests
158158
:alt: Tests
159-
.. |coveralls| image:: https://coveralls.io/repos/magmax/python-inquirer/badge.png
160-
:target: `Coveralls`_
161-
:alt: Coveralls results_
159+
.. |Codecov| image:: https://codecov.io/gh/magmax/python-inquirer/branch/master/graph/badge.svg
160+
:target: https://app.codecov.io/gh/magmax/python-inquirer
161+
:alt: Codecov
162162
.. |pip version| image:: https://img.shields.io/pypi/v/inquirer.svg
163163
:target: https://pypi.python.org/pypi/inquirer
164164
:alt: Latest PyPI version
@@ -201,7 +201,6 @@ Licensed under `the MIT license`_.
201201
:alt: Example of Checkbox Question
202202

203203
.. _Inquirer.js: https://github.com/SBoudrias/Inquirer.js
204-
.. _Coveralls: https://coveralls.io/r/magmax/python-inquirer
205204
.. _examples/: https://github.com/magmax/python-inquirer/tree/master/examples
206205
.. _`download the python-inquirer code from GitHub`: https://github.com/magmax/python-inquirer
207206
.. _`download the wheel from Pypi`: https://pypi.python.org/pypi/inquirer

codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
comment: false
3+
coverage:
4+
status:
5+
project:
6+
default:
7+
target: "90"
8+
patch:
9+
default:
10+
target: "90"

0 commit comments

Comments
 (0)