Skip to content

Commit

Permalink
Add coverage reports to github actions (#103)
Browse files Browse the repository at this point in the history
* Add comment workflow

* Automatically generate and upload coverage reports for tests
  • Loading branch information
jshufro authored Aug 27, 2024
1 parent cfb4626 commit b980c16
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
relative_files = True
omit =
tests/**
36 changes: 36 additions & 0 deletions .github/workflows/comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Safely comment on the PR - https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
name: Comment on pull request
run-name: commenting on PR by ${{ github.actor }}
on:
workflow_run:
workflows: [ "ci-runner" ]
types:
- completed

jobs:
comment:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: 'Comment on PR'
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
var issue_number = Number(fs.readFileSync('./issue_number'));
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: fs.readFileSync('./coverage-text-report').toString()
});
45 changes: 44 additions & 1 deletion .github/workflows/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,52 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_test.txt
pip install coverage
- name: Run tests
run: pytest tests
run: |
coverage run --data-file=.coverage.${{ matrix.os }}.${{ matrix.python-version }} -m pytest tests
- name: Run type checker
run: python -m mypy --config-file mypy.ini -p ethstaker_deposit
- name: Run linter
run: flake8 --config=flake8.ini ./ethstaker_deposit ./tests
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
path: .coverage.${{ matrix.os }}.${{ matrix.python-version }}
retention-days: 1
coverage-combine:
needs: ci-runner
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download coverage data
uses: actions/download-artifact@v4
- name: Merge coverage data
id: merge
run: |
python -m pip install --upgrade pip
pip install coverage
coverage combine coverage*
coverage html
- name: Upload final coverage html report
uses: actions/upload-artifact@v4
id: upload-html
with:
name: coverage-html-report
path: htmlcov
- name: Generate text report
run: |
mkdir results
echo "Test Coverage: [Download HTML Report](${{ steps.upload-html.outputs.artifact-url }})" >> results/coverage-text-report
echo >> results/coverage-text-report
echo \`\`\` >> results/coverage-text-report
coverage report >> results/coverage-text-report
echo \`\`\` >> results/coverage-text-report
echo ${{ github.event.number }} > results/issue_number
- name: Upload final coverage text report
uses: actions/upload-artifact@v4
with:
name: results
path: results/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ venv/
*.egg
__pycache__
.DS_Store
.coverage

0 comments on commit b980c16

Please sign in to comment.