diff --git a/.github/workflows/java-17.yml b/.github/workflows/java-17.yml index 1fb97b4..d83bcf6 100644 --- a/.github/workflows/java-17.yml +++ b/.github/workflows/java-17.yml @@ -1,17 +1,16 @@ -# Copyright 2023-2023 the original author or authors. +# Copyright 2023-2023 the original author or authors. # -# 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 +# 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. +# 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. # # @@ -20,25 +19,68 @@ name: Java 17 CI with Maven on: push: branches: [ main ] - # Each pull request is important to us, doesn't matter from which branch. - # Furthermore, we do not want to build on just the default GitHub Action - # events, we also want to react onto `labeled` events for our extended - # build execution pull_request: types: [ labeled, opened, synchronize, reopened ] jobs: build: - runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: 17 cache: maven + - name: Build with Maven - run: mvn -B verify -P java-17,run-its \ No newline at end of file + run: mvn -B verify -P java-17,run-its + + - name: Generate JaCoCo badge + id: jacoco + uses: cicirello/jacoco-badge-generator@v2.11.0 + with: + badges-directory: .github/badges + generate-branches-badge: true + generate-summary: true + summary-filename: coverage-summary_java-17.json + coverage-badge-filename: jacoco_java-17.svg + branches-badge-filename: branches_java-17.svg + coverage-endpoint-filename: jacoco_java-17.json + branches-endpoint-filename: branches_java-17.json + + - name: Log coverage percentages to workflow output + run: | + echo "(java-17) coverage = ${{ steps.jacoco.outputs.coverage }}%" + echo "(java-17) branches = ${{ steps.jacoco.outputs.branches }}%" + + - name: Upload JaCoCo coverage report + uses: actions/upload-artifact@v4 + with: + name: jacoco-report-java-17 + path: target/site/jacoco/ + + - name: Deploy to Coverage Branch + if: ${{ github.event_name != 'pull_request' }} + uses: crazy-max/ghaction-github-pages@v4 + with: + target_branch: coverage + build_dir: .github/badges + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Comment on PR with coverage percentages + if: ${{ github.event_name == 'pull_request' }} + run: | + REPORT=$(<.github/badges/coverage-summary_java-17.json) + COVERAGE=$(jq -r '.coverage' <<< "$REPORT")% + BRANCHES=$(jq -r '.branches' <<< "$REPORT")% + NEWLINE=$'\n' + BODY="## JaCoCo Test Coverage Summary Statistics (java-17) ${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 }}