From 0c628376f7ae4516634f006f2dc19c496a597996 Mon Sep 17 00:00:00 2001 From: Shailesh Date: Fri, 21 Jul 2023 15:28:52 +0530 Subject: [PATCH] test coverage --- .github/workflows/code-coverage.yml | 47 -------------------- .github/workflows/jacoco.yml | 66 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/code-coverage.yml create mode 100644 .github/workflows/jacoco.yml diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml deleted file mode 100644 index 3e414b26..00000000 --- a/.github/workflows/code-coverage.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Java CI with Code Coverage - - - -on: - push: - branches: - - feat/CS-36689-compare-merge-branch - -jobs: - build-and-test: - runs-on: ubuntu-latest - - steps: - - - name: Build with Maven - run: mvn clean package - - - name: Run Tests with JaCoCo - run: mvn jacoco:prepare-agent test jacoco:report - - - name: Check Code Coverage - run: | - total_lines=$(xmllint --xpath 'string(//counter[@type="LINE"]/@covered)' target/site/jacoco/jacoco.xml) - total_lines=${total_lines:-0} - total_missed=$(xmllint --xpath 'string(//counter[@type="LINE"]/@missed)' target/site/jacoco/jacoco.xml) - total_missed=${total_missed:-0} - total_percentage=$(awk "BEGIN { pc=100*${total_lines}/(${total_lines}+${total_missed}) } { printf \"%f\", pc }") - echo "Total Coverage Percentage: $total_percentage" - if (( $(bc <<< "$total_percentage < 80.0") )); then - echo "Code Coverage is below 80% - failing the build." - exit 1 - else - echo "Code Coverage is satisfactory - proceeding with the build." - fi - - - name: Upload Code Coverage Report - uses: actions/upload-artifact@v2 - with: - name: code-coverage-report - path: target/site/jacoco - - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: target/site/jacoco diff --git a/.github/workflows/jacoco.yml b/.github/workflows/jacoco.yml new file mode 100644 index 00000000..2904bce8 --- /dev/null +++ b/.github/workflows/jacoco.yml @@ -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=$(