Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaileshmishra committed Jul 21, 2023
1 parent b106fbd commit 0c62837
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 47 deletions.
47 changes: 0 additions & 47 deletions .github/workflows/code-coverage.yml

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/jacoco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: build

on:
push:
branches: [ feat/CS-36689-compare-merge-branch ]
paths: [ '**.java', '.github/workflows/jacoco.yml', 'pom.xml' ]
pull_request:
branches: [ feat/CS-36689-compare-merge-branch ]
workflow_dispatch:

jobs:
jacoco-java-maven:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3


- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '17'

- name: Build with Maven
run: mvn -B package -Pcoverage

- name: Generate JaCoCo badge
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
badges-directory: badges
generate-branches-badge: true
generate-summary: true

- name: Log coverage percentages to workflow output
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branches = ${{ steps.jacoco.outputs.branches }}"
- name: Upload JaCoCo coverage report as a workflow artifact
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: target/site/jacoco/


- name: Comment on PR with coverage percentages
if: ${{ github.event_name == 'pull_request' }}
run: |
REPORT=$(<badges/coverage-summary.json)
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
NEWLINE=$'\n'
BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get the Coverage info
run: |
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"

0 comments on commit 0c62837

Please sign in to comment.