This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
[FIX] - Revisão cálculo coverage #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
- name: Grant execute permission for Gradlew | ||
run: chmod +x ./gradlew | ||
- name: Install xmllint | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libxml2-utils | ||
- name: Run Spotless Apply | ||
run: ./gradlew spotlessApply | ||
- name: Run Spotless Check | ||
run: ./gradlew spotlessCheck | ||
- name: Run tests and generate JaCoCo report | ||
run: | | ||
./gradlew clean test jacocoTestReport | ||
echo "Generated JaCoCo reports:" | ||
ls -R build/reports/jacoco || echo "No JaCoCo reports found." | ||
- name: Extract and display coverage percentage | ||
run: | | ||
# Caminho fixo do relatório XML | ||
REPORT_PATH=build/reports/jacoco/test/jacocoTestReport.xml | ||
if [ ! -f "$REPORT_PATH" ]; then | ||
echo "JaCoCo XML coverage report not found!" | ||
exit 1 | ||
fi | ||
echo "Found JaCoCo XML report at: $REPORT_PATH" | ||
# Extração dos dados de cobertura | ||
COVERED=$(xmllint --xpath 'string(sum(//counter[@type="LINE"]/@covered))' "$REPORT_PATH") | ||
MISSED=$(xmllint --xpath 'string(sum(//counter[@type="LINE"]/@missed))' "$REPORT_PATH") | ||
if [ -z "$COVERED" ] || [ -z "$MISSED" ]; then | ||
echo "Error: Unable to extract coverage data from the XML report." | ||
exit 1 | ||
fi | ||
# Converte valores para inteiros para evitar problemas de cálculo | ||
COVERED=$(printf "%.0f" "$COVERED") | ||
MISSED=$(printf "%.0f" "$MISSED") | ||
TOTAL=$((COVERED + MISSED)) | ||
if [ "$TOTAL" -eq 0 ]; then | ||
echo "Error: Total lines is zero, coverage cannot be calculated." | ||
exit 1 | ||
fi | ||
# Cálculo do percentual de cobertura | ||
PERCENTAGE=$(echo "scale=2; ($COVERED / $TOTAL) * 100" | bc) | ||
echo "Lines Covered: $COVERED" | ||
echo "Lines Missed: $MISSED" | ||
echo "Total Lines: $TOTAL" | ||
echo "Coverage Percentage: $PERCENTAGE%" | ||
# Validação da cobertura mínima | ||
MINIMUM=50.0 | ||
if (( $(echo "$PERCENTAGE < $MINIMUM" | bc -l) )); then | ||
echo "Coverage is below the minimum required: $MINIMUM%!" | ||
exit 1 | ||
fi | ||
echo "Coverage validation passed with $PERCENTAGE%." | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Setup JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 21 | ||
distribution: 'zulu' | ||
- name: Setup Docker Compose | ||
run: | | ||
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | ||
chmod +x /usr/local/bin/docker-compose | ||
- name: Cache Gradle packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('build.gradle', 'gradle/wrapper/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Raise infra | ||
run: make infrastructure/up | ||
- name: Grant execute permission for Gradlew | ||
run: chmod +x gradlew | ||
- name: Run Spotless Apply | ||
run: ./gradlew spotlessApply | ||
- name: Code linting | ||
run: ./gradlew spotlessCheck | ||
- name: Static analysis | ||
run: | | ||
./gradlew pmdMain | ||
./gradlew pmdTest | ||
- name: Run tests | ||
run: ./gradlew test | ||
- name: Build | ||
run: ./gradlew clean assemble |