Skip to content

Feature #5 java 2.0.0 #8

Feature #5 java 2.0.0

Feature #5 java 2.0.0 #8

Workflow file for this run

name: Java Test and Coverage
on:
pull_request:
branches:
- main
jobs:
test-and-coverage:
name: Test with coverage
runs-on: ubuntu-latest
steps:
- run: |
git config --global user.name 'eclipse-uprotocol-bot'
git config --global user.email 'uprotocol-bot@eclipse.org'
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Apache Maven Central
uses: actions/setup-java@v4
with: # configure settings.xml
distribution: 'temurin'
java-version: '17'
server-id: ossrh
server-username: OSSRH_USER
server-password: OSSRH_PASSWORD
gpg-private-key: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
- name: Run tests with coverage
run: |
./mvnw clean test jacoco:report
- name: Extract JaCoCo report
run: |
echo "Extracting coverage percentage from JaCoCo report"
INDEX_PATH="target/site/jacoco/index.html"
export COVERAGE_PERCENTAGE=$(grep -oP '(?<=<td class="ctr2">).*?(?=%</td>)' $INDEX_PATH | sed 's/ //g')
export COVERAGE_PERCENTAGE=$(printf "%.2f" "$COVERAGE_PERCENTAGE")
echo "COVERAGE_PERCENTAGE= $COVERAGE_PERCENTAGE" >> $GITHUB_ENV
echo "COVERAGE_PERCENTAGE: $COVERAGE_PERCENTAGE"
- name: Upload JaCoCo Coverage report
uses: actions/upload-artifact@v4
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@v4
with:
name: pr-comment
path: pr-comment/