Skip to content

Commit

Permalink
Migrate to coverage.py for testing coverage #84
Browse files Browse the repository at this point in the history
 - Update python-package.yml
 - Add extras_requires in setup.cfg
 - Add pytest and configuration settings in pyproject.toml
 - Add PR coverage comment and badge generation with GitHub actions
 - Bump version: v0.4.11 -> v0.4.12
  • Loading branch information
astrochun committed May 22, 2022
1 parent bec9140 commit 9c6b972
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 10 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Post coverage comment

on:
workflow_run:
workflows: ["Python package"]
types:
- completed

jobs:
test:
name: Run tests & display coverage
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
steps:
# DO NOT run actions/checkout@v2 here, for security reasons
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Post comment
uses: ewjoachim/python-coverage-comment-action@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
# Update those if you changed the default values:
# COMMENT_ARTIFACT_NAME: python-coverage-comment-action
# COMMENT_FILENAME: python-coverage-comment-action.txt
28 changes: 21 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-cov
- name: Install github_stats_pages
run: |
pip install .
pip install .[test]
- name: Test with pytest
run: |
echo "Username for unit tests : ${{ github.actor }}"
pytest -sv --cov-report term-missing --cov=github_stats_pages tests --username ${{ github.actor }} --token ${{ secrets.GH_TOKEN }}
- run: |
coverage run -m pytest --username ${{ github.actor }} --token ${{ secrets.GH_TOKEN }}
coverage report && coverage xml && coverage html && coverage json
- name: Upload coverage data
uses: actions/upload-artifact@v2
with:
name: coverage-data
path: |
coverage.*
htmlcov
if-no-files-found: ignore
- name: Make working directory
run: |
mkdir ${{env.work_dir}}
cd ${{env.work_dir}}
- name: Test scripts (get data, merge, and generate static pages)
Expand All @@ -42,3 +48,11 @@ jobs:
gts_run_all_repos -u ${{ github.actor }} -t ${{ secrets.GH_TOKEN }} -c ${{ github.actor }}.csv --test
merge-csv.sh
make_stats_plots -u ${{ github.actor }} -t ${{ secrets.GH_TOKEN }} -c ${{ github.actor }}.csv
- name: Analyze coverage data
id: coverage_comment
uses: ewjoachim/python-coverage-comment-action@v2
with:
GITHUB_TOKEN: ${{ github.token }}
- name: Store Pull Request comment to be posted
uses: actions/upload-artifact@v2
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
2 changes: 1 addition & 1 deletion github_stats_pages/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.11"
__version__ = "0.4.12"
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,25 @@ build-backend = "setuptools.build_meta"
[tool.black]
line-length = 79
target-version = ['py38', 'py39', 'py310']

[tool.pytest.ini_options]
addopts = "-sv"
testpaths = [
"tests",
]
log_cli = true
#env = [
# {GITHUB_ACTOR = "data/test_assets"}
#]

[tool.coverage.run]
branch = true
# command_line = "-m pytest"
source = [
"github_stats_pages"
]
relative_files = true

[tool.coverage.report]
precision = 2
show_missing = true
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ packages =
[options.package_data]
* = templates/*

#[options.packages.find]
#where=github_stats_pages
[options.extras_require]
test = pytest>=7.1.2, <8.0.0; pytest-cov>=3.0.0, <4.0.0

0 comments on commit 9c6b972

Please sign in to comment.