150 lines
4.5 KiB
YAML
150 lines
4.5 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
backend:
|
|
name: Backend Tests
|
|
runs-on:
|
|
- tsys-repos
|
|
services:
|
|
postgres:
|
|
image: postgres:15-alpine
|
|
env:
|
|
POSTGRES_DB: merchantsofhope_test
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
ports:
|
|
- 5432:5432
|
|
options: >-
|
|
--health-cmd="pg_isready -U postgres" --health-interval=10s --health-timeout=5s --health-retries=5
|
|
env:
|
|
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/merchantsofhope_test
|
|
JWT_SECRET: merchantsofhope_test_secret
|
|
NODE_ENV: test
|
|
USE_DOCKER_TEST_DB: "false"
|
|
steps:
|
|
- name: Checkout
|
|
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 dependencies
|
|
run: npm ci
|
|
working-directory: backend
|
|
|
|
- name: Lint backend
|
|
run: npm run lint
|
|
working-directory: backend
|
|
|
|
- name: Run database migrations
|
|
run: npm run migrate
|
|
working-directory: backend
|
|
|
|
- name: Run backend tests
|
|
run: npm test -- --runInBand --coverage
|
|
working-directory: backend
|
|
|
|
frontend:
|
|
name: Frontend Tests
|
|
runs-on:
|
|
- tsys-repos
|
|
steps:
|
|
- name: Checkout
|
|
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 dependencies
|
|
run: npm ci
|
|
working-directory: frontend
|
|
|
|
- name: Lint frontend
|
|
run: npm run lint
|
|
working-directory: frontend
|
|
|
|
- name: Run frontend tests
|
|
run: npm test -- --watchAll=false --coverage
|
|
working-directory: frontend
|
|
|
|
docker-images:
|
|
name: Build Docker Images
|
|
runs-on:
|
|
- tsys-repos
|
|
needs: [backend, frontend]
|
|
if: github.ref == 'refs/heads/main'
|
|
env:
|
|
REGISTRY_HOST: ${{ secrets.REGISTRY_HOST }}
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
IMAGE_TAG: ${{ github.sha }}
|
|
BACKEND_IMAGE: merchantsofhope-supplyanddemandportal-backend
|
|
FRONTEND_IMAGE: merchantsofhope-supplyanddemandportal-frontend
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to registry
|
|
if: env.REGISTRY_HOST != ''
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY_HOST }}
|
|
username: ${{ env.REGISTRY_USERNAME }}
|
|
password: ${{ env.REGISTRY_PASSWORD }}
|
|
|
|
- name: Determine image tags
|
|
id: meta
|
|
run: |
|
|
if [ -n "${REGISTRY_HOST}" ]; then
|
|
echo "push=true" >> $GITHUB_OUTPUT
|
|
echo "backend_tag=${REGISTRY_HOST}/${BACKEND_IMAGE}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
echo "frontend_tag=${REGISTRY_HOST}/${FRONTEND_IMAGE}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "push=false" >> $GITHUB_OUTPUT
|
|
echo "backend_tag=${BACKEND_IMAGE}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
echo "frontend_tag=${FRONTEND_IMAGE}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Build backend image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: backend
|
|
file: backend/Dockerfile
|
|
push: ${{ steps.meta.outputs.push == 'true' }}
|
|
tags: ${{ steps.meta.outputs.backend_tag }}
|
|
|
|
- name: Build frontend image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: frontend
|
|
file: frontend/Dockerfile
|
|
push: ${{ steps.meta.outputs.push == 'true' }}
|
|
tags: ${{ steps.meta.outputs.frontend_tag }}
|
|
|
|
- name: Summary
|
|
run: |
|
|
echo "Backend image tag: ${{ steps.meta.outputs.backend_tag }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "Frontend image tag: ${{ steps.meta.outputs.frontend_tag }}" >> $GITHUB_STEP_SUMMARY
|
|
if [ "${{ steps.meta.outputs.push }}" = 'true' ]; then
|
|
echo "Images pushed to ${{ env.REGISTRY_HOST }}" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "Images built locally (not pushed). Set REGISTRY_* secrets to enable pushing." >> $GITHUB_STEP_SUMMARY
|
|
fi
|