Feat/add frontend tests #84
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 - FF Insights | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
push: | |
branches: [master] | |
env: | |
JDK_VERSION: 21 | |
NODE_VERSION: 23 | |
jobs: | |
backend-lint: | |
name: Backend Lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JDK_VERSION }} | |
distribution: 'temurin' | |
- name: Lint backend | |
run: mvn clean checkstyle:check | tee backend-lint.log | |
working-directory: InsightsBackend | |
- name: Upload Backend Lint Logs | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-lint-log | |
path: InsightsBackend/backend-lint.log | |
frontend-lint: | |
name: Frontend Lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install dependencies | |
run: npm ci | |
working-directory: InsightsFrontend | |
- name: Lint frontend | |
run: npm run lint | tee frontend-lint.log | |
working-directory: InsightsFrontend | |
- name: Upload Frontend Lint Logs | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-lint-log | |
path: InsightsFrontend/frontend-lint.log | |
backend-test: | |
name: Backend Unit Test | |
runs-on: ubuntu-latest | |
needs: [backend-lint] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JDK_VERSION }} | |
distribution: 'temurin' | |
- name: Cache Maven packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2/repository | |
key: maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }} | |
restore-keys: maven-${{ runner.os }}- | |
- name: Backend Unit Tests | |
run: mvn test --file pom.xml | tee test.log | |
working-directory: InsightsBackend | |
- name: Upload Backend Test Logs | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-test-logs | |
path: | | |
InsightsBackend/target/surefire-reports/ | |
InsightsBackend/test.log | |
frontend-test: | |
name: Frontend Unit Test | |
runs-on: ubuntu-latest | |
needs: [frontend-lint] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Cache Node modules | |
uses: actions/cache@v4 | |
with: | |
path: InsightsFrontend/node_modules | |
key: npm-${{ runner.os }}-${{ hashFiles('InsightsFrontend/package-lock.json') }} | |
restore-keys: npm-${{ runner.os }}- | |
- name: Install dependencies | |
run: npm ci | |
working-directory: InsightsFrontend | |
- name: Frontend Unit Tests | |
run: npm run test -- --watch=false --browsers=ChromeHeadless | tee test.log | |
working-directory: InsightsFrontend | |
- name: Upload Frontend Test Logs | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-test-logs | |
path: InsightsFrontend/test.log | |
backend-build: | |
name: Build Backend | |
runs-on: ubuntu-latest | |
needs: [backend-test] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JDK_VERSION }} | |
distribution: 'temurin' | |
- name: Build backend | |
run: mvn package -DskipTests --file pom.xml | |
working-directory: InsightsBackend | |
- name: Upload Backend Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-jar | |
path: InsightsBackend/target/*.jar | |
frontend-build: | |
name: Build Frontend | |
runs-on: ubuntu-latest | |
needs: [frontend-test] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install dependencies | |
run: npm ci | |
working-directory: InsightsFrontend | |
- name: Build frontend (development config) | |
run: npm run build -- --configuration=development | |
working-directory: InsightsFrontend | |
- name: Upload Frontend Artifact for E2E | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-dist-dev | |
path: InsightsFrontend/dist/ | |
e2e-test: | |
name: End-to-End Testing | |
runs-on: ubuntu-latest | |
needs: [backend-build, frontend-build] | |
services: | |
postgres: | |
image: postgres:17 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: insights | |
ports: [5432:5432] | |
options: >- | |
--health-cmd="pg_isready" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download Backend Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: backend-jar | |
path: backend-artifact | |
- name: Download Frontend Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: frontend-dist-dev | |
path: frontend-artifact | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JDK_VERSION }} | |
distribution: 'temurin' | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install Cypress Dependencies | |
run: npm ci | |
working-directory: ./InsightsFrontend | |
- name: Start Backend and Frontend Services | |
env: | |
SPRING_PROFILES_ACTIVE: local | |
run: | | |
java -jar ./backend-artifact/*.jar & | |
npm install -g http-server | |
http-server ./frontend-artifact/insights-frontend/browser -p 4200 --cors & | |
- name: Wait for Backend Application | |
run: | | |
echo "Waiting for backend application to be healthy..." | |
RETRY_COUNT=0 | |
MAX_RETRIES=20 | |
RETRY_INTERVAL=5 | |
until curl -s -f http://localhost:8080/actuator/health > /dev/null; do | |
if [ ${RETRY_COUNT} -ge ${MAX_RETRIES} ]; then | |
echo "Error: Timed out waiting for backend." | |
exit 1 | |
fi | |
RETRY_COUNT=$((RETRY_COUNT + 1)) | |
echo "Backend not ready. Retrying in ${RETRY_INTERVAL}s..." | |
sleep ${RETRY_INTERVAL} | |
done | |
echo "Backend is up and healthy!" | |
- name: Load E2E Data into Database | |
env: | |
PGPASSWORD: postgres | |
run: | | |
sudo apt-get update && sudo apt-get install -y postgresql-client | |
psql -h localhost -p 5432 -U postgres -d insights -f ./data-e2e.sql | |
echo "Data successfully loaded." | |
- name: Run Cypress E2E Tests | |
run: npm run cypress:run | |
working-directory: ./InsightsFrontend | |
- name: Upload E2E Test Logs and Videos | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: e2e-test-artifacts | |
path: | | |
InsightsFrontend/cypress/videos/ | |
InsightsFrontend/cypress/screenshots/ | |
docker-dispatch: | |
if: github.ref == 'refs/heads/master' && github.event_name == 'push' | |
needs: [e2e-test] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Trigger Docker Publish workflow | |
uses: peter-evans/repository-dispatch@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
event-type: docker-publish |