feat: Add TestContainers integration tests for MySQL and PostgreSQL #26
Workflow file for this run
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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| env: | |
| JAVA_VERSION: '21' | |
| MAVEN_OPTS: -Xmx3072m | |
| jobs: | |
| build-and-test: | |
| name: Build and Test All Modules | |
| runs-on: ubuntu-latest | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: root | |
| MYSQL_DATABASE: test_db | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=3 | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: test_db | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd=pg_isready | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=3 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for better SonarCloud analysis | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: ${{ env.JAVA_VERSION }} | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Cache Maven packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Build all modules | |
| run: mvn clean install -DskipTests | |
| - name: Run tests - openespi-common | |
| run: mvn test -pl openespi-common -am | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| - name: Run tests - openespi-datacustodian | |
| run: mvn test -pl openespi-datacustodian -am | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| # TODO: Enable when authserver implementation is complete | |
| # - name: Run tests - openespi-authserver | |
| # run: mvn test -pl openespi-authserver -am | |
| # env: | |
| # SPRING_PROFILES_ACTIVE: test | |
| - name: Run tests - openespi-thirdparty | |
| run: mvn test -pl openespi-thirdparty -am | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| - name: Run integration tests with TestContainers | |
| run: mvn verify -Pintegration-tests -pl openespi-common,openespi-datacustodian,openespi-thirdparty | |
| env: | |
| SPRING_PROFILES_ACTIVE: testcontainers | |
| # JaCoCo reports are automatically generated during test phase (configured in root pom.xml) | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: | | |
| **/target/surefire-reports/ | |
| **/target/failsafe-reports/ | |
| - name: Upload coverage reports | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-reports | |
| path: | | |
| **/target/site/jacoco/ | |
| sonarcloud: | |
| name: SonarCloud Analysis | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for better SonarCloud analysis | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: ${{ env.JAVA_VERSION }} | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Cache Maven packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Build modules for SonarCloud | |
| run: mvn clean verify -pl openespi-common,openespi-datacustodian,openespi-thirdparty -am | |
| - name: Analyze with SonarCloud | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| mvn sonar:sonar \ | |
| -Dsonar.projectKey=GreenButtonAlliance_OpenESPI-GreenButton-Java \ | |
| -Dsonar.organization=greenbuttonalliance \ | |
| -Dsonar.host.url=https://sonarcloud.io \ | |
| -Dsonar.coverage.jacoco.xmlReportPaths=**/target/site/jacoco/jacoco.xml | |
| security-scan: | |
| name: Security Vulnerability Scan | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: ${{ env.JAVA_VERSION }} | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Run OWASP Dependency Check | |
| run: mvn org.owasp:dependency-check-maven:check | |
| continue-on-error: true | |
| - name: Upload OWASP report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: owasp-report | |
| path: target/dependency-check-report.html |