blob: 4f842dea3c8b8456feaea38eefae01a437f84d68 [file]
name: Fineract Cargo & Unit- & Integration tests - PostgreSQL
on:
workflow_call:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-24.04
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
task: [test-core-1, test-core-2, test-core-3, test-core-4, test-core-5]
services:
postgresql:
image: postgres:18.3
ports:
- 5432:5432
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: postgres
options: --health-cmd="pg_isready -q -d postgres -U root" --health-interval=5s --health-timeout=2s --health-retries=3
mock-oauth2-server:
image: ghcr.io/navikt/mock-oauth2-server:3.0.1
ports:
- 9000:9000
env:
SERVER_PORT: 9000
JSON_CONFIG: '{ "interactiveLogin": true, "httpServer": "NettyWrapper", "tokenCallbacks": [ { "issuerId": "auth/realms/fineract", "tokenExpiry": 120, "requestMappings": [{ "requestParam": "scope", "match": "fineract", "claims": { "sub": "mifos", "scope": [ "test" ] } } ] } ] }'
env:
TZ: Asia/Kolkata
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
AWS_ENDPOINT_URL: http://localhost:4566
AWS_ACCESS_KEY_ID: localstack
AWS_SECRET_ACCESS_KEY: localstack
AWS_REGION: us-east-1
FINERACT_REPORT_EXPORT_S3_ENABLED: true
FINERACT_REPORT_EXPORT_S3_BUCKET_NAME: fineract-reports
steps:
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: '21'
distribution: 'zulu'
- name: Download workspace
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: fineract-workspace-${{ github.run_id }}
path: .
- name: Extract workspace
run: tar -xf fineract-workspace.tar
- name: Setup Gradle and Validate Wrapper
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
validate-wrappers: true
- name: Verify PostgreSQL connection
run: |
while ! pg_isready -d postgres -U root -h 127.0.0.1 -p 5432 ; do
sleep 1
done
- name: Initialise databases
run: |
./gradlew --no-daemon -q createPGDB -PdbName=fineract_tenants -x buildJavaSdk
./gradlew --no-daemon -q createPGDB -PdbName=fineract_default -x buildJavaSdk
- name: Start LocalStack
run: |
docker run -d --name localstack -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack:2.1
sleep 10
docker exec localstack awslocal s3api create-bucket --bucket fineract-reports
- name: Generate test class list (only for test-core-X)
if: startsWith(matrix.task, 'test-core-')
run: |
chmod +x scripts/split-tests.sh
SHARD_INDEX=$(echo "${{ matrix.task }}" | awk -F'-' '{print $3}')
./scripts/split-tests.sh 5 $SHARD_INDEX
cat "shard-tests_${SHARD_INDEX}.txt"
- name: Run Gradle Task
run: |
set -e # Fail the script if any command fails
SHARD_INDEX=$(echo "${{ matrix.task }}" | awk -F'-' '{print $3}')
FAILED=0
case "${{ matrix.task }}" in
test-core-*)
echo "Grouping test classes by module..."
declare -A module_tests
while IFS=, read -r module class; do
module_tests["$module"]+="$class "
done < "shard-tests_${SHARD_INDEX}.txt"
for module in "${!module_tests[@]}"; do
echo "::group::Running tests in $module"
for class in ${module_tests[$module]}; do
echo " - $class"
done
# Build test args
test_args=$(for class in ${module_tests[$module]}; do echo --tests "$class"; done | xargs)
# Run test task for this module
if ! ./gradlew --no-daemon "$module:test" $test_args -PdbType=postgresql -x checkstyleJmh -x checkstyleMain -x checkstyleTest -x spotlessCheck -x spotlessApply -x spotbugsMain -x spotbugsTest -x javadoc -x javadocJar -x modernizer -x buildJavaSdk ; then
echo "::error::Tests failed in module $module"
FAILED=1
fi
echo "::endgroup::"
done
;;
esac
# Exit with failure status if any test failed
if [ "$FAILED" -eq 1 ]; then
echo "::error::Some tests failed in this job"
exit 1
fi
- name: Archive test results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: test-results-${{ matrix.task }}
path: '**/build/reports/'
retention-days: 5
- name: Archive server logs
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: server-logs-${{ matrix.task }}
path: '**/build/cargo/'
retention-days: 5