name: "Unit test coverage" on: push: pull_request: env: MIN_COVERAGE_PERCENTAGE: 85 DEBIAN_FRONTEND: noninteractive TZ: UTC DOCKER_HOST: "tcp://docker:2375" DOCKER_TLS_VERIFY: "" # Test containers suggest this will yield better fs performance DOCKER_DRIVER: overlay2 # ryuk need privileged permission, disable it in CI TESTCONTAINERS_RYUK_DISABLED: true jobs: # gradle test for modules gradle-test: runs-on: general container: image: ubuntu:24.04 services: docker: image: docker:dind cmd: - "dockerd" - "-H" - "tcp://0.0.0.0:2375" - "--tls=false" steps: # need to setup node and git - run: | apt-get update apt-get install -y nodejs git curl # check out code - uses: actions/checkout@v4 - uses: https://github.com/actions/setup-java@v4 with: distribution: "temurin" java-version: "21" # ensure executable - run: chmod +x ./gradlew # run gradle test - run: ./gradlew check --no-daemon env: MAVEN_TOKEN: ${{ secrets.REGISTRY_PASSWORD }} # process jacoco report - name: Collect coverage report id: coverage run: | INPUT=$(grep -o ']*>' build/reports/jacoco/test/jacocoTestReport.xml | tail -1) MISSED=$(echo "$INPUT" | sed -n 's/.*missed="\([0-9]*\)".*/\1/p') COVERED=$(echo "$INPUT" | sed -n 's/.*covered="\([0-9]*\)".*/\1/p') echo "MISSED: $MISSED" echo "COVERED: $COVERED" COVERAGE_PERCENTAGE=$(( 100 * $COVERED / ($COVERED + $MISSED) )) echo "Code coverage: ${COVERAGE_PERCENTAGE}%" echo "Minimal coverage: ${MIN_COVERAGE_PERCENTAGE}%" echo "percentage=${COVERAGE_PERCENTAGE}" >> $GITHUB_OUTPUT - name: Post coverage to RP if: github.event_name == 'pull_request' run: | curl --fail \ -X POST '${{github.api_url}}/repos/${{github.repository}}/issues/${{github.event.number}}/comments' \ -H "Content-Type: application/json" \ -H "Authorization: token ${{github.token}}" \ -d '{"body":"Coverage is ${{steps.coverage.outputs.percentage}}%"}' - name: Check coverage rate run: | if [ ${{steps.coverage.outputs.percentage}} -lt $MIN_COVERAGE_PERCENTAGE ]; then exit 1 fi