Skip to content

Remove deprecated API usage from UTwin client implementation #118

Remove deprecated API usage from UTwin client implementation

Remove deprecated API usage from UTwin client implementation #118

Workflow file for this run

# ********************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************/
name: Java Test and Coverage
on:
pull_request:
branches:
- main
jobs:
# req~up-language-test-coverage~1
test-and-coverage:
name: Test with coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
submodules: 'recursive'
- name: Install xmllint
run: sudo apt-get update && sudo apt-get install -y libxml2-utils
- name: Set up Java with Maven
uses: actions/setup-java@v4
with: # configure settings.xml
distribution: 'temurin'
java-version: '17'
- name: Run tests with coverage
run: |
mvn clean verify -Djacoco.skip=false
- name: Extract overall coverage from JaCoCo report
run: |
echo "Extracting coverage percentage from JaCoCo report"
jacoco_report="target/site/jacoco/jacoco.xml"
missed=$(xmllint --xpath "string(//report/counter[@type='INSTRUCTION']/@missed)" "$jacoco_report")
covered=$(xmllint --xpath "string(//report/counter[@type='INSTRUCTION']/@covered)" "$jacoco_report")
if [ -n "$covered" ] && [ -n "$missed" ]; then
total=$((covered + missed))
if [ $total -gt 0 ]; then
percentage=$(echo "scale=2; $covered * 100 / $total" | bc -l)
else
percentage="0"
fi
else
percentage="N/A"
fi
echo "COVERAGE_PERCENTAGE=$percentage" >> $GITHUB_ENV
echo "COVERAGE_PERCENTAGE: $percentage"
- name: Upload JaCoCo Coverage report
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: coverage-report
path: target/site/jacoco
- name: Generate coverage comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const COVERAGE_PERCENTAGE = `${{ env.COVERAGE_PERCENTAGE }}`;
const COVERAGE_REPORT_PATH = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/`;
fs.mkdirSync('./pr-comment', { recursive: true });
var pr_number = `${{ github.event.number }}`;
var body = `
Code coverage report is ready! :chart_with_upwards_trend:
- **Code Coverage Percentage:** ${COVERAGE_PERCENTAGE}%
- **Code Coverage Report:** [View Coverage Report](${COVERAGE_REPORT_PATH})
`;
fs.writeFileSync('./pr-comment/pr-number.txt', pr_number);
fs.writeFileSync('./pr-comment/body.txt', body);
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: pr-comment
path: pr-comment/