Skip to content

frontend test fixed #29

frontend test fixed

frontend test fixed #29

name: Build and Push Docker Images
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
jobs:
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: backend/package-lock.json
- name: Install backend dependencies
run: |
cd backend
npm ci
- name: Run backend tests
run: |
cd backend
npm test
env:
NODE_ENV: test
JWT_SECRET: test_jwt_secret
MONGODB_URI: mongodb://localhost:27017/glow_test
- name: Upload backend test results
uses: actions/upload-artifact@v4 # Changed from v3 to v4
if: always()
with:
name: backend-test-results
path: backend/coverage/
test-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: Run frontend tests
run: |
cd frontend
npm test -- --coverage --watchAll=false
env:
NEXT_PUBLIC_API_URL: http://localhost:5000/api
CI: true
- name: Upload frontend test results
uses: actions/upload-artifact@v4 # Changed from v3 to v4
if: always()
with:
name: frontend-test-results
path: frontend/coverage/
build-backend:
runs-on: ubuntu-latest
needs: [test-backend] # Only build if tests pass
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Extract metadata for backend
id: meta-backend
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_HUB_USERNAME }}/glow-backend
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=commit-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push backend Docker image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ steps.meta-backend.outputs.tags }}
labels: ${{ steps.meta-backend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Trigger backend redeploy on Render
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
run: |
curl -X POST "${{ secrets.RENDER_BACKEND_DEPLOY_HOOK }}"
env:
RENDER_BACKEND_DEPLOY_HOOK: ${{ secrets.RENDER_BACKEND_DEPLOY_HOOK }}
build-frontend:
runs-on: ubuntu-latest
needs: [test-frontend] # Only build if tests pass
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Extract metadata for frontend
id: meta-frontend
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_HUB_USERNAME }}/glow-frontend
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=commit-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push frontend Docker image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
build-args: |
NEXT_PUBLIC_API_URL=https://glow-backend-v4-0-0.onrender.com/api
tags: ${{ steps.meta-frontend.outputs.tags }}
labels: ${{ steps.meta-frontend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Trigger frontend redeploy on Render
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
run: |
curl -X POST "${{ secrets.RENDER_FRONTEND_DEPLOY_HOOK }}"
env:
RENDER_FRONTEND_DEPLOY_HOOK: ${{ secrets.RENDER_FRONTEND_DEPLOY_HOOK }}