Add Maven CI workflow with MongoDB service #1
This file contains hidden or 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: Java CI with Maven | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| # MongoDB service for integration tests | |
| services: | |
| mongo: | |
| image: mongo:7.0 | |
| ports: | |
| - 27017:27017 | |
| env: | |
| MONGO_INITDB_ROOT_USERNAME: fluxgate | |
| MONGO_INITDB_ROOT_PASSWORD: fluxgate123 | |
| MONGO_INITDB_DATABASE: fluxgate | |
| # healthcheck (optional but recommended) | |
| options: >- | |
| --health-cmd "mongosh --username fluxgate --password fluxgate123 --authenticationDatabase admin --eval 'db.adminCommand(\"ping\")'" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| # Mongodb | |
| env: | |
| FLUXGATE_MONGO_URI: "mongodb://fluxgate:fluxgate123@localhost:27017/fluxgate?authSource=admin" | |
| FLUXGATE_MONGO_DB: "fluxgate" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Run tests with Maven | |
| run: mvn -B test --file pom.xml | |
| # Optional: dependency graph for Dependabot etc. | |
| - name: Update dependency graph | |
| uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 |