Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: Build and Deploy

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'

- name: Install frontend dependencies
run: |
cd frontend
npm ci

- name: Build frontend
run: |
cd frontend
npm run build

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: pdo_mysql, mbstring, exif, pcntl, bcmath, gd

- name: Install backend dependencies
run: |
cd backend
composer install --no-interaction --optimize-autoloader

- name: Run Laravel optimizations
run: |
cd backend
php artisan config:cache
php artisan route:cache

- name: Log in to Container Registry
if: github.event_name == 'push'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push frontend image
if: github.event_name == 'push'
uses: docker/build-push-action@v4
with:
context: ./frontend
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/frontend:${{ github.sha }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/frontend:latest

- name: Build and push backend image
if: github.event_name == 'push'
uses: docker/build-push-action@v4
with:
context: ./backend
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/backend:${{ github.sha }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/backend:latest

test:
runs-on: ubuntu-latest
needs: build

services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: form_builder_test
MYSQL_ROOT_PASSWORD: root
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: pdo_mysql, mbstring

- name: Install backend dependencies
run: |
cd backend
composer install --no-interaction

- name: Run Laravel tests
run: |
cd backend
php artisan test
env:
DB_HOST: 127.0.0.1
DB_DATABASE: form_builder_test
DB_USERNAME: root
DB_PASSWORD: root

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'

- name: Install frontend dependencies
run: |
cd frontend
npm ci

- name: Run frontend tests
run: |
cd frontend
npm run test -- --passWithNoTests

deploy:
runs-on: ubuntu-latest
needs: [build, test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Deploy to staging
run: |
echo "Deploying to staging environment..."
# Add your deployment script here
# Example: ssh [email protected] 'cd /app && docker-compose pull && docker-compose up -d'

- name: Run smoke tests
run: |
echo "Running smoke tests..."
# Add your smoke test script here
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# next.js
/.next/
/out/

# production
/build

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
Loading