Skip to content

Все примеры для Java Junior Developer #5

Все примеры для Java Junior Developer

Все примеры для Java Junior Developer #5

Workflow file for this run

name: CI
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Detect build system and build
run: |
if [ -f pom.xml ]; then
echo "BUILD_SYSTEM=maven" >> $GITHUB_ENV
mvn -B clean compile -Dmaven.test.skip=true -Djava.awt.headless=true || true
elif [ -f build.gradle ] || [ -f build.gradle.kts ]; then
echo "BUILD_SYSTEM=gradle" >> $GITHUB_ENV
chmod +x gradlew 2>/dev/null || true
if [ -f gradlew ]; then
./gradlew build -x test || true
else
gradle build -x test || true
fi
else
echo "BUILD_SYSTEM=javac" >> $GITHUB_ENV
echo "No Maven/Gradle found, compiling .java files directly"
find . -name "*.java" -not -path "*/test/*" | head -50 | xargs javac -d /tmp/classes 2>&1 | tail -20 || true
fi
- name: Run tests
run: |
if [ "$BUILD_SYSTEM" = "maven" ]; then
mvn -B test jacoco:report -Djava.awt.headless=true || true
elif [ "$BUILD_SYSTEM" = "gradle" ]; then
if [ -f gradlew ]; then
./gradlew test jacocoTestReport || true
else
gradle test jacocoTestReport || true
fi
else
echo "No test runner configured"
fi
- name: Show coverage summary
run: |
# Maven JaCoCo
if [ -f target/site/jacoco/jacoco.csv ]; then
echo "## Test Coverage Report (JaCoCo)" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
awk -F',' 'NR>1 {missed+=$4; covered+=$5} END {total=missed+covered; if(total>0) printf "Line Coverage: %d/%d (%.1f%%)\nMissed: %d lines\n", covered, total, covered*100/total, missed; else print "No coverage data"}' target/site/jacoco/jacoco.csv >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# Gradle JaCoCo
elif [ -f build/reports/jacoco/test/jacocoTestReport.csv ]; then
echo "## Test Coverage Report (JaCoCo)" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
awk -F',' 'NR>1 {missed+=$4; covered+=$5} END {total=missed+covered; if(total>0) printf "Line Coverage: %d/%d (%.1f%%)\nMissed: %d lines\n", covered, total, covered*100/total, missed; else print "No coverage data"}' build/reports/jacoco/test/jacocoTestReport.csv >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "## Coverage" >> $GITHUB_STEP_SUMMARY
echo "No JaCoCo report found. Add jacoco-maven-plugin or jacoco Gradle plugin." >> $GITHUB_STEP_SUMMARY
fi
- name: Upload coverage to Codecov
if: hashFiles('**/jacoco.xml') != ''
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}