Skip to content

Commit

Permalink
New coverage.yml for code coverage (#1912)
Browse files Browse the repository at this point in the history
* new coverage.yml

* match the job name

* remove upload code coverage config
  • Loading branch information
salty-ivy committed May 7, 2024
1 parent 2134600 commit c1463a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 49 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/coverage.yml
@@ -0,0 +1,33 @@
# .github/workflows/coverage.yml
name: Post coverage comment

on:
workflow_run:
workflows: ["Test"]
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'
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write
# Gives the action the necessary permissions for looking up the
# workflow that launched this workflow, and download the related
# artifact that contains the comment to be published
actions: read
steps:
# DO NOT run actions/checkout here, for security reasons
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Post comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
49 changes: 0 additions & 49 deletions .github/workflows/test.yml
Expand Up @@ -66,11 +66,6 @@ jobs:
DB_HOST: 127.0.0.1
DB_PORT: 3306

- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.arch }}-mysql
path: ".coverage.*"

postgres:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -144,12 +139,6 @@ jobs:
DB_HOST: localhost
DB_PORT: 5432

- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.database }}
path: ".coverage.*"

sqlite:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -192,44 +181,6 @@ jobs:
DB_BACKEND: sqlite3
DB_NAME: ":memory:"

- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.arch }}-sqlite
path: ".coverage.*"

coverage:
name: Check coverage.
runs-on: "ubuntu-latest"
needs: [sqlite, mysql, postgres]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
# Use latest, so it understands all syntax.
python-version: "3.11"

- run: python -m pip install --upgrade coverage[toml]

- name: Download coverage data.
uses: actions/download-artifact@v4
with:
pattern: coverage-data-*
merge-multiple: true

- name: Combine coverage & check percentage
run: |
python -m coverage combine
python -m coverage html
python -m coverage report
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
if: ${{ failure() }}

lint:
runs-on: ubuntu-latest
strategy:
Expand Down

0 comments on commit c1463a5

Please sign in to comment.