Skip to content

Commit

Permalink
Split coverage comparison into separate workflow (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer authored Nov 11, 2023
1 parent eddb29d commit 350d177
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 37 deletions.
11 changes: 4 additions & 7 deletions .github/coverage-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def parse_args():

parser.add_argument("--coverage-file", required=True,
help="Path of pycobertura coverage XML file")
parser.add_argument("--coverage-diff-file",
help="Path of pycobertura diff .json file")
parser.add_argument("--repository", required=True,
help="owner/name of repository")
parser.add_argument("--sha", required=True, help="SHA hash of commit")
Expand Down Expand Up @@ -39,10 +41,5 @@ def post_status(repository: str, sha: str, state: str, context: str, description

cobertura = Cobertura(args.coverage_file)

post_status(
repository=args.repository,
sha=args.sha,
state="success",
context="Total Coverage",
description=f"line: {cobertura.line_rate() * 100:.2f}% branch: {cobertura.branch_rate() * 100:.2f}%"
)
post_status(args.repository, args.sha, "success", "Coverage / Total",
f"line: {cobertura.line_rate() * 100:.2f}% branch: {cobertura.branch_rate() * 100:.2f}%")
86 changes: 56 additions & 30 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ on:

jobs:
coverage:
name: Test
name: Run
runs-on: ubuntu-latest
permissions:
statuses: write

services:
clickhouse:
Expand All @@ -30,23 +32,13 @@ jobs:
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Checkout main
uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}
with:
ref: main
path: main

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
- name: Install pycobertura
run: pip install pycobertura

- name: Install coverlet-collector
run: dotnet add ClickHouse.Client.Tests/ClickHouse.Client.Tests.csproj package coverlet.collector --no-restore

Expand All @@ -63,12 +55,57 @@ jobs:

- run: mv ./ClickHouse.Client.Tests/coverage.net6.0.cobertura.xml ./ClickHouse.Client/coverage.cobertura.xml

- name: Upload coverage xml
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage
path: ./ClickHouse.Client/coverage.cobertura.xml

- name: Install pycobertura
run: pip install pycobertura

- name: Set status checks
working-directory: ${{ github.workspace }}/ClickHouse.Client
env:
GITHUB_TOKEN: ${{ github.token }}
run: python ${{ github.workspace }}/.github/coverage-status.py
--coverage-file coverage.cobertura.xml
--repository ${{ github.repository }} --sha ${{ github.sha }}

compare:
name: Compare
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
permissions:
statuses: write
needs:
- coverage

steps:
- name: Install pycobertura
run: pip install pycobertura

- name: Checkout
uses: actions/checkout@v4

- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
path: main

- name: Download coverage
uses: actions/download-artifact@v3
with:
name: coverage
path: ./

- name: Download 'main' coverage
if: ${{ github.event_name == 'pull_request' }}
uses: benday-inc/download-latest-artifact@main
with:
token: ${{ github.token }}
repository_owner: ${{ github.repository_owner }}
repository_owner: ${{ github.repository_owner }}
repository_name: ClickHouse.Client
workflow_name: ${{ github.workflow }}
branch_name: main
Expand All @@ -77,25 +114,14 @@ jobs:
download_filename: coverage.zip

- name: Unzip 'main' coverage
if: ${{ github.event_name == 'pull_request' }}
working-directory: ${{ github.workspace }}/main/ClickHouse.Client
run: unzip coverage.zip

- name: Report diff coverage
if: ${{ github.event_name == 'pull_request' }}
- name: Report diff annotations
run: pycobertura diff ./main/ClickHouse.Client/coverage.cobertura.xml ./ClickHouse.Client/coverage.cobertura.xml --format github-annotation
continue-on-error: true

- name: Set status checks
working-directory: ${{ github.workspace }}/ClickHouse.Client
run: python python ${{ github.workspace }}/.github/coverage-status.py
--coverage-file coverage.cobertura.xml
--repository ${{ github.repo }}
--sha ${{ github.sha }}

- name: Upload coverage xml
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage
path: ./ClickHouse.Client/coverage.cobertura.xml
- name: Generate diff json
if: ${{ github.event_name == 'pull_request' }}
run: pycobertura diff ./main/ClickHouse.Client/coverage.cobertura.xml ./ClickHouse.Client/coverage.cobertura.xml --format json
continue-on-error: true

0 comments on commit 350d177

Please sign in to comment.