[KTP-62] Apply refactoring changes suggested by TA #12
Workflow file for this run
This file contains 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: PR Quality Check | |
# This workflow is responsible for checking the quality of PRs for the backend. | |
# It runs tests, ensures code coverage, and uploads a report for review. | |
on: | |
pull_request: | |
branches: | |
- '*' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:17 | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd="pg_isready -U postgres" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
env: | |
POSTGRES_USER: ${{ secrets.DB_USERNAME }} | |
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
POSTGRES_DB: knowtopia_dev | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Wait for PostgreSQL | |
run: | | |
for i in {1..10}; do | |
if pg_isready -h localhost -p 5432 -U ${{ secrets.DB_USERNAME }}; then | |
echo "PostgreSQL is ready!" | |
break | |
fi | |
echo "Waiting for PostgreSQL to be ready..." | |
sleep 5 | |
done | |
- name: Run tests | |
env: | |
DB_URL: ${{ secrets.DB_URL }} | |
DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
run: mvn clean verify | |
working-directory: backend | |
- name: Upload Report | |
uses: 'actions/upload-artifact@v4' | |
with: | |
name: jacoco-report | |
path: ${{ github.workspace }}/backend/target/site/jacoco/jacoco.xml | |
- name: Add coverage to PR | |
if: github.event_name == 'pull_request' | |
id: jacoco | |
uses: madrapps/[email protected] | |
with: | |
paths: ${{ github.workspace }}/backend/target/site/jacoco/jacoco.xml | |
token: ${{ secrets.GITHUB_TOKEN }} | |
min-coverage-overall: 60 | |
min-coverage-changed-files: 60 | |
title: Code Coverage Summary | |
update-comment: true | |
- name: Fail PR if overall coverage is less than 60% | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const coverage = parseFloat('${{ steps.jacoco.outputs.coverage-overall }}'); | |
console.log('Overall coverage is:', coverage); | |
if (coverage < 60.0) { | |
core.setFailed('Overall coverage is less than 60%!'); | |
} |