Skip to content

Commit 8883163

Browse files
authored
Merge pull request #3 from valentingol/badges
✨ Add pytest/pylint actions and their badges
2 parents 0a40ae5 + b7437cd commit 8883163

10 files changed

+922
-31
lines changed

.coveragerc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[report]
2+
exclude_lines =
3+
if TYPE_CHECKING:

.github/workflows/.pylint.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Pylint
2+
3+
on: [push]
4+
5+
jobs:
6+
pylint-lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python 3.9
11+
uses: actions/setup-python@v1
12+
with:
13+
python-version: 3.9
14+
- name: Cache installation
15+
uses: actions/cache@v1
16+
id: cache
17+
with:
18+
path: ~/.cache/pip
19+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
20+
restore-keys: |
21+
${{ runner.os }}-pip-
22+
- name: Install
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements-dev.txt
26+
pip install pylint pylint-django
27+
pip install -e .
28+
- name: Analysing the code with pylint
29+
run: |
30+
pylint --rcfile=.pylintrc --output-format=text $(git ls-files '*.py') | tee .pylint.txt
31+
- name: Handle pylint results
32+
run: |
33+
score=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' .pylint.txt)
34+
echo "Pylint score was $score"
35+
color=$(python3 -m github_actions_utils.pylint_manager --score=$score)
36+
echo "PYLINT_COLOR=$color"
37+
echo "PYLINT_COLOR=$color" >> $GITHUB_ENV
38+
echo "PYLINT_SCORE=$score/10.00"
39+
echo "PYLINT_SCORE=$score/10.00" >> $GITHUB_ENV
40+
- name: Create Pylint Badge
41+
uses: schneegans/dynamic-badges-action@v1.1.0
42+
with:
43+
auth: ${{ secrets.GIST_SECRET }}
44+
gistID: 8fb4f3f78584e085dd7b0cca7e046d1f
45+
filename: torch_pca_pylint.json
46+
label: Pylint
47+
message: ${{ env.PYLINT_SCORE }}
48+
color: ${{ env.PYLINT_COLOR }}
49+
style: flat
50+
namedLogo: stylelint
51+
logoColor: "#959DA5"
52+
labelColor: "#343B42"
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: PyPi
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: "3.x"
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install build twine
22+
- name: Build
23+
run: |
24+
python -m build
25+
- name: Publish
26+
env:
27+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
twine upload dist/*

.github/workflows/tests.yaml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Check out source repository
10+
uses: actions/checkout@v2
11+
- name: Set up Python 3.9
12+
uses: actions/setup-python@v1
13+
with:
14+
python-version: 3.9
15+
- name: Cache installation
16+
uses: actions/cache@v1
17+
id: cache
18+
with:
19+
path: ~/.cache/pip
20+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
21+
restore-keys: |
22+
${{ runner.os }}-pip-
23+
- name: Install
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r requirements-dev.txt
27+
pip install pytest pytest-cov
28+
pip install -e .
29+
- name: Test with pytest
30+
run: |
31+
pytest --disable-pytest-warnings --cov-report=term --cov=src --cov-config=.coveragerc tests/ | tee .pytest.txt
32+
- name: Handle test results
33+
run: |
34+
score=$(cat .pytest.txt | grep TOTAL | tr -s ' ' | cut -d ' ' -f 4)
35+
n_failures=$(cat .pytest.txt | grep failed | cut -d ' ' -f 2)
36+
echo "Pytest finds $n_failures failure(s)"
37+
echo "Tests coverage is $score"
38+
color=$(python3 -m github_actions_utils.pytest_manager --score=$score --n_failures=$n_failures)
39+
echo "PYTEST_COLOR=$color"
40+
echo "PYTEST_COLOR=$color" >> $GITHUB_ENV
41+
echo "PYTEST_SCORE=$score"
42+
echo "PYTEST_SCORE=$score" >> $GITHUB_ENV
43+
- name: Create Coverage Badge
44+
uses: schneegans/dynamic-badges-action@v1.1.0
45+
with:
46+
auth: ${{ secrets.GIST_SECRET }}
47+
gistID: c5a6b5731db93da673f8e258b2669080
48+
filename: torch_pca_tests.json
49+
label: Coverage
50+
message: ${{ env.PYTEST_SCORE }}
51+
color: ${{ env.PYTEST_COLOR }}
52+
style: flat
53+
namedLogo: codecov
54+
logoColor: "#959DA5"
55+
labelColor: "#343B42"

0 commit comments

Comments
 (0)