Skip to content

fix: connect registration form to backend API and add real-time passw… #8

fix: connect registration form to backend API and add real-time passw…

fix: connect registration form to backend API and add real-time passw… #8

Workflow file for this run

name: Deploy to Production
on:
push:
branches: [ main ]
tags: [ 'v*' ]
env:
NODE_VERSION: '18'
PHP_VERSION: '8.2'
jobs:
# Build and Test
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
extensions: pdo, pdo_pgsql, pgsql, redis, mbstring, exif, pcntl, bcmath, gd
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: Install backend dependencies
run: |
cd backend
composer install --no-dev --optimize-autoloader
- name: Build frontend for production
run: |
cd frontend
npm run build
- name: Run production tests
run: |
cd frontend
npm run test:unit:run
# Deploy to Staging
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: build-and-test
if: github.ref == 'refs/heads/main'
environment: staging
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to staging server
run: |
echo "Deploying to staging environment..."
# Add your staging deployment commands here
# Example: rsync, docker deploy, etc.
# Deploy to Production
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: deploy-staging
if: startsWith(github.ref, 'refs/tags/v')
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to production server
run: |
echo "Deploying to production environment..."
# Add your production deployment commands here
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
# Docker Registry Push
docker-push:
name: Push to Docker Registry
runs-on: ubuntu-latest
needs: build-and-test
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
chms/backend
chms/frontend
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push backend image
uses: docker/build-push-action@v5
with:
context: ./backend
push: true
tags: chms/backend:${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
push: true
tags: chms/frontend:${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Notify Deployment
notify:
name: Notify Deployment
runs-on: ubuntu-latest
needs: [deploy-staging, deploy-production, docker-push]
if: always()
steps:
- name: Notify Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
channel: '#deployments'
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Notify Email
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 587
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: ChMS Deployment Failed
to: ${{ secrets.NOTIFICATION_EMAIL }}
from: ChMS CI/CD
body: |
Deployment failed for ChMS application.
Branch: ${{ github.ref }}
Commit: ${{ github.sha }}
Author: ${{ github.actor }}
Please check the GitHub Actions logs for more details.