Files
user-management/.forgejo/workflows/coverage-check.yaml
T
hurui200320 bed3de76dd
Unit test coverage / gradle-test (pull_request) Successful in 7m21s
Unit test coverage / gradle-test (push) Successful in 7m26s
CI for publishing docker image / build-and-publish (push) Successful in 7m2s
Implement query user endpoint for RabbitMQ (#35)
This PR implemented ticket clevermicro/user-management#34 for the user-service-v1 endpoint, along with all the infrastructures required to support the endpoints.

The changes are:
+ switch build tool to gradle for easier access to the private artifacts of clevermicro (although later Brian change the artifacts to public)
+ set up clevermicro amqp client
+ switched to official keycloak admin client instead of implementing it with webflux
+ implement the message formats for the RPC protocol, for now they are exclusive to auth-service, but in the future we will reuse (might with some changes) them for all RPC calls inside clevermicro (need a server lib for handling the message parsing and convertion)
+ implement the user query endpoint
+ implement unit test so the overall coverage is above 85%
+ fixed all issues found during the testing phase with shared env

Currently the latest docker image has been deployed to the shared env, see https://docs.cleverthis.com/en/architecture/microservices/shared-env#multi-user-support

Reviewed-on: #35
2025-07-31 12:56:14 +08:00

72 lines
2.4 KiB
YAML

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 '<counter type="LINE" [^>]*>' 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