forked from Abdulbari/sgeUpdated
Update sgeupdated pipeline v21
new condition to be added
This commit is contained in:
@@ -4,8 +4,8 @@ name: sgeUpdated CI/CD
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # trigger only when code is merged into main
|
- main
|
||||||
workflow_dispatch: # allow manual trigger
|
workflow_dispatch:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: sgeupdated-deploy-${{ github.ref }}
|
group: sgeupdated-deploy-${{ github.ref }}
|
||||||
@@ -30,20 +30,59 @@ jobs:
|
|||||||
|
|
||||||
cd /home/ubuntu/Bgreen/sgeUpdated
|
cd /home/ubuntu/Bgreen/sgeUpdated
|
||||||
git fetch origin main
|
git fetch origin main
|
||||||
|
|
||||||
|
# Detect which files changed in the last commit
|
||||||
|
CHANGED_FILES=$(git diff --name-only HEAD HEAD~1)
|
||||||
|
|
||||||
|
echo "🪶 Changed files:"
|
||||||
|
echo "$CHANGED_FILES"
|
||||||
|
|
||||||
git reset --hard origin/main
|
git reset --hard origin/main
|
||||||
|
|
||||||
echo "⚡ Rebuilding Backend..."
|
BACKEND_CHANGED=false
|
||||||
cd sgeUpdated/sge-backend
|
FRONTEND_CHANGED=false
|
||||||
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
|
|
||||||
cd ../..
|
|
||||||
docker compose up -d --build bgreen-backend
|
|
||||||
|
|
||||||
echo "⚡ Rebuilding Frontend..."
|
# Check if backend folder changed
|
||||||
cd sgeUpdated/sge-frontend
|
if echo "$CHANGED_FILES" | grep -q "^sgeUpdated/sge-backend/"; then
|
||||||
# npm install
|
BACKEND_CHANGED=true
|
||||||
# npm run build
|
fi
|
||||||
cd ../..
|
|
||||||
docker compose up -d --build bgreen-frontend
|
|
||||||
|
|
||||||
echo "✅ Deployment complete. Current containers:"
|
# Check if frontend folder changed
|
||||||
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
if echo "$CHANGED_FILES" | grep -q "^sgeUpdated/sge-frontend/"; then
|
||||||
|
FRONTEND_CHANGED=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Backend section
|
||||||
|
if [ "$BACKEND_CHANGED" = true ]; then
|
||||||
|
echo "⚡ Backend changes detected."
|
||||||
|
cd sgeUpdated/sge-backend
|
||||||
|
echo "Would run Maven build here..."
|
||||||
|
# /opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
|
||||||
|
cd ../..
|
||||||
|
echo "Would rebuild backend Docker container..."
|
||||||
|
# docker compose up -d --build bgreen-backend
|
||||||
|
else
|
||||||
|
echo "✅ No backend changes."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Frontend section
|
||||||
|
if [ "$FRONTEND_CHANGED" = true ]; then
|
||||||
|
echo "⚡ Frontend changes detected."
|
||||||
|
cd sgeUpdated/sge-frontend
|
||||||
|
echo "Would run npm build here..."
|
||||||
|
# npm install
|
||||||
|
# npm run build
|
||||||
|
cd ../..
|
||||||
|
echo "Would rebuild frontend Docker container..."
|
||||||
|
# docker compose up -d --build bgreen-frontend
|
||||||
|
else
|
||||||
|
echo "✅ No frontend changes."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If no changes at all, just restart containers (commented for now)
|
||||||
|
if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then
|
||||||
|
echo "♻️ No source changes detected. (Would restart containers here...)"
|
||||||
|
# docker compose up -d
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ Check complete. (No rebuild or restart performed.)"
|
||||||
|
|||||||
Reference in New Issue
Block a user