Skip to content

fix: Update security workflow with better error handling and optional… #10

fix: Update security workflow with better error handling and optional…

fix: Update security workflow with better error handling and optional… #10

Workflow file for this run

name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Cache backend dependencies
uses: actions/cache@v3
with:
path: backend/node_modules
key: ${{ runner.os }}-backend-${{ hashFiles('backend/package-lock.json') }}
- name: Cache frontend dependencies
uses: actions/cache@v3
with:
path: frontend/node_modules
key: ${{ runner.os }}-frontend-${{ hashFiles('frontend/package-lock.json') }}
- name: Install backend dependencies
working-directory: ./backend
run: npm ci
- name: Run backend tests
working-directory: ./backend
run: |
npm test
mkdir -p coverage
npm install -g jest-coverage-badges
jest-coverage-badges
- name: Install frontend dependencies
working-directory: ./frontend
run: npm ci
- name: Run frontend tests
working-directory: ./frontend
run: |
npm test
mkdir -p coverage
npm install -g jest-coverage-badges
jest-coverage-badges
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: |
backend/coverage
frontend/coverage
docker:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker images
uses: docker/build-push-action@v4
with:
context: .
file: ./docker-compose.yml
push: false
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Test Docker Compose
run: |
docker-compose up -d
sleep 10
curl --retry 5 --retry-delay 5 http://localhost:3001/health
docker-compose logs
docker-compose down
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache