diff --git a/.github/workflows/check-jacoco.yml b/.github/workflows/check-jacoco.yml index ebbb5e3..95657f6 100644 --- a/.github/workflows/check-jacoco.yml +++ b/.github/workflows/check-jacoco.yml @@ -21,61 +21,103 @@ on: branches: [ master ] types: [ opened, edited, synchronize, reopened ] +permissions: + contents: read + +# Cancel superseded runs on the same ref to save runner minutes. +concurrency: + group: jacoco-report-${{ github.ref }} + cancel-in-progress: true + +env: + # hint: "group thresholds" are in format: 'overall*changed-files-average*per-changed-file' + # one report group per Scala version + # scala: [ 2.11, 2.12, 2.13 ] -- 2.13 produce problems | Support can wait until we will decide to move from 2.12 + REPORT_GROUPS: | + - name: scala-2.11 + paths: + - 'coverage/scala-2.11/jacoco.xml' + thresholds: '76*80*60' + - name: scala-2.12 + paths: + - 'coverage/scala-2.12/jacoco.xml' + thresholds: '72*80*60' + jobs: - test: - runs-on: [ubuntu-latest] - strategy: - fail-fast: false - matrix: -# scala: [ 2.11, 2.12, 2.13 ] -- 2.13 produce problems | Support can wait until we will decide to move from 2.12 - scala: [ 2.11, 2.12 ] + detect: + name: Detect Changed Files + runs-on: ubuntu-latest + timeout-minutes: 2 + outputs: + scala_changed: ${{ steps.filter.outputs.scala }} steps: - name: Checkout code - uses: actions/checkout@v4 - - name: Setup Scala - uses: olafurpg/setup-scala@v10 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: - java-version: "adopt@1.8" - - name: Build and run tests - run: mvn clean verify -Pcode-coverage,scala-${{ matrix.scala }} --no-transfer-progress - - - name: Upload Jacoco report as workflow artifact - uses: actions/upload-artifact@v4 + persist-credentials: false + fetch-depth: 0 + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d + id: filter with: - name: PR jacoco report xml ${{ matrix.scala }} - path: target/site/jacoco/jacoco.xml + token: "" + filters: | + scala: + - '**/*.scala' + - '**/*.java' - - name: Checkout master branch into separate folder - uses: actions/checkout@v4 + jacoco-report: + name: JaCoCo Report + needs: detect + if: needs.detect.outputs.scala_changed == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + pull-requests: write + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: - ref: master - path: master_code - - name: Build and run tests (master branch) - working-directory: master_code - run: mvn clean verify -Pcode-coverage,scala-${{ matrix.scala }} --no-transfer-progress + persist-credentials: false + fetch-depth: 0 - - name: Upload Jacoco report as workflow artifact - uses: actions/upload-artifact@v4 + - name: Setup Scala + uses: olafurpg/setup-scala@32ffa16635ff8f19cc21ea253a987f0fdf29844c with: - name: Master jacoco report xml ${{ matrix.scala }} - path: master_code/target/site/jacoco/jacoco.xml + java-version: "adopt@1.8" + + - name: Build and run tests with coverage (Scala 2.11) + run: | + mvn clean verify -Pcode-coverage,scala-2.11 --no-transfer-progress + mkdir -p coverage/scala-2.11 + cp target/jacoco.xml coverage/scala-2.11/jacoco.xml + + - name: Build and run tests with coverage (Scala 2.12) + run: | + mvn clean verify -Pcode-coverage,scala-2.12 --no-transfer-progress + mkdir -p coverage/scala-2.12 + cp target/jacoco.xml coverage/scala-2.12/jacoco.xml - - uses: actions/setup-python@v5 + - name: Setup Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 with: - python-version: '3.12' + python-version: '3.14' + - name: Add JaCoCo Report in PR comments - id: jacoco - uses: MoranaApps/jacoco-report@v1.3.0 + uses: MoranaApps/jacoco-report@562ba603c5b95021dbee26e89ae0f834f2dd8b9e with: - token: '${{ secrets.GITHUB_TOKEN }}' - paths: | - **/target/site/jacoco/jacoco.xml - exclude-paths: | - master_code/** - baseline-paths: | - master_code/**/target/site/jacoco/jacoco.xml - title: JaCoCo code coverage report - Scala ${{ matrix.scala }} - sensitivity: "detail" - comment-mode: 'single' - min-coverage-overall: 75.0 - min-coverage-changed-files: 80.0 + token: ${{ secrets.GITHUB_TOKEN }} + global-thresholds: '74*80' + global-overall-scope: 'groups-only' + report-thresholds-default: '72*80*60' + skip-unchanged: 'true' + evaluate-unchanged: 'false' + report-groups: ${{ env.REPORT_GROUPS }} + + noop: + name: No Operation + needs: detect + if: needs.detect.outputs.scala_changed != 'true' + runs-on: ubuntu-latest + steps: + - run: echo "No changes in Scala/Java related files — passing." diff --git a/jmf-rules.txt b/jmf-rules.txt new file mode 100644 index 0000000..df6f8fb --- /dev/null +++ b/jmf-rules.txt @@ -0,0 +1,155 @@ +# +# Copyright 2019 ABSA Group Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# jacoco-method-filter — Rules (Scala / Maven) — za.co.absa.commons +# [jmf:2.1.0] +# +# Syntax reference, pitfalls, examples, and workflows: https://github.com/MoranaApps/jacoco-method-filter/blob/main/docs/rules-reference.md +# +# ───────────────────────────────────────────────────────────────────────────── +# HOW TO USE +# ───────────────────────────────────────────────────────────────────────────── +# +# 1) Review the GLOBAL RULES below — they cover compiler-generated boilerplate. +# 2) Add project-specific patterns in the PROJECT RULES section. +# 3) Keep rules narrow; add id: labels so logs are readable. +# Every rule must have an id: