diff --git a/.gitea/workflows/sgeupdated.yml b/.gitea/workflows/sgeupdated.yml index ed40a11..810c5e4 100644 --- a/.gitea/workflows/sgeupdated.yml +++ b/.gitea/workflows/sgeupdated.yml @@ -4,8 +4,8 @@ name: sgeUpdated CI/CD on: push: branches: - - main # trigger only when code is merged into main - workflow_dispatch: # allow manual trigger + - main + workflow_dispatch: concurrency: group: sgeupdated-deploy-${{ github.ref }} @@ -30,20 +30,59 @@ jobs: cd /home/ubuntu/Bgreen/sgeUpdated 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 - echo "⚡ Rebuilding Backend..." - cd sgeUpdated/sge-backend - /opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests - cd ../.. - docker compose up -d --build bgreen-backend + BACKEND_CHANGED=false + FRONTEND_CHANGED=false - echo "⚡ Rebuilding Frontend..." - cd sgeUpdated/sge-frontend - # npm install - # npm run build - cd ../.. - docker compose up -d --build bgreen-frontend + # Check if backend folder changed + if echo "$CHANGED_FILES" | grep -q "^sgeUpdated/sge-backend/"; then + BACKEND_CHANGED=true + fi - echo "✅ Deployment complete. Current containers:" - docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' \ No newline at end of file + # Check if frontend folder changed + 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.)"