[QA] Add Unit Tests for Server Services and Controllers #100
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: Build and Test Server | |
| on: | |
| push: | |
| branches: [main, test, dev] | |
| paths: | |
| - 'server/skillforge-gateway/**' | |
| - 'server/skillforge-user/**' | |
| - 'server/skillforge-course/**' | |
| pull_request: | |
| branches: [main, test, dev] | |
| paths: | |
| - 'server/skillforge-gateway/**' | |
| - 'server/skillforge-user/**' | |
| - 'server/skillforge-course/**' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| test-gateway: | |
| name: Build & Test Gateway | |
| runs-on: ubuntu-latest | |
| services: | |
| redis: | |
| image: redis:7-alpine | |
| ports: | |
| - 6379:6379 | |
| defaults: | |
| run: | |
| working-directory: server/skillforge-gateway | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: 'gradle' | |
| - uses: ./.github/actions/create-dotenv | |
| - name: Build and test | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| REDIS_HOST: redis | |
| REDIS_PORT: 6379 | |
| run: ./gradlew build --no-daemon --scan | |
| - name: Post workflow summary | |
| if: always() | |
| run: | | |
| echo "## Workflow Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- Status: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Commit: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Run: [View logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY | |
| test-user-service: | |
| name: Build & Test User Service | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: server/skillforge-user | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: 'gradle' | |
| - uses: ./.github/actions/create-dotenv | |
| - name: Build application | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| JWT_SECRET: test-jwt-secret-key-for-testing-only | |
| JWT_EXPIRATION_MS: 3600000 | |
| run: ./gradlew build -x test --no-daemon | |
| - name: Run unit tests with coverage | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| JWT_SECRET: test-jwt-secret-key-for-testing-only | |
| JWT_EXPIRATION_MS: 3600000 | |
| run: ./gradlew clean test jacocoTestReport --no-daemon --info | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-reports | |
| path: ${{ github.workspace }}/server/skillforge-user/build/reports/jacoco/test/ | |
| retention-days: 30 | |
| - name: Post workflow summary | |
| if: always() | |
| run: | | |
| echo "## Workflow Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- Status: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Commit: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY | |
| echo "---" >> $GITHUB_STEP_SUMMARY | |
| echo "## 📊 Test Coverage Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "Coverage reports generated successfully!" >> $GITHUB_STEP_SUMMARY | |
| echo "- ✅ **HTML Report**: [Download from Artifacts (coverage-reports)](./)" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🧾 XML Report: Available for CI/CD integration" >> $GITHUB_STEP_SUMMARY | |
| echo "- 📁 Navigate to \`coverage-reports/index.html\` inside the artifact to open the report." >> $GITHUB_STEP_SUMMARY | |
| test-course-service: | |
| name: Build & Test Course Service | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: server/skillforge-course | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: 'gradle' | |
| - uses: ./.github/actions/create-dotenv | |
| - name: Build application | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| JWT_SECRET: test-jwt-secret-key-for-testing-only | |
| JWT_EXPIRATION_MS: 3600000 | |
| run: ./gradlew build -x test --no-daemon | |
| - name: Run unit tests with coverage | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| JWT_SECRET: test-jwt-secret-key-for-testing-only | |
| JWT_EXPIRATION_MS: 3600000 | |
| run: ./gradlew clean test jacocoTestReport --no-daemon --info | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-reports | |
| path: ${{ github.workspace }}/server/skillforge-course/build/reports/jacoco/test/ | |
| retention-days: 30 | |
| - name: Post workflow summary | |
| if: always() | |
| run: | | |
| echo "## Workflow Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- Status: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Commit: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY | |
| echo "---" >> $GITHUB_STEP_SUMMARY | |
| echo "## 📊 Test Coverage Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "Coverage reports generated successfully!" >> $GITHUB_STEP_SUMMARY | |
| echo "- ✅ **HTML Report**: [Download from Artifacts (coverage-reports)](./)" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🧾 XML Report: Available for CI/CD integration" >> $GITHUB_STEP_SUMMARY | |
| echo "- 📁 Navigate to \`coverage-reports/index.html\` inside the artifact to open the report." >> $GITHUB_STEP_SUMMARY |