Update sgeupdated pipeline v22
All checks were successful
sgeUpdated CI/CD / deploy (push) Successful in 6s

This commit is contained in:
2025-10-24 15:13:23 +03:00
parent 23a3d8252e
commit 385eda2132

View File

@@ -4,109 +4,103 @@ on:
push: push:
branches: branches:
- main - main
workflow_dispatch:
concurrency:
group: sgeupdated-deploy-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
deploy: deploy:
# 'ubuntu-latest' is a common name for runners.
# Check with your Gitea admin if you have a different runner tag.
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repo # Gitea automatically checks out your code, so we don't need 'actions/checkout'
uses: actions/checkout@v3
- name: Deploy over SSH - name: Setup SSH
uses: appleboy/ssh-action@v1.0.3 run: |
with: # Create the .ssh directory
host: ${{ secrets.SERVER_HOST }} mkdir -p ~/.ssh/
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }} # Add your private key (from Gitea secrets)
script_stop: true echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
script: | chmod 600 ~/.ssh/id_rsa
# Add your server's host key to known_hosts to avoid the 'yes/no' prompt
# This is a critical step for automation
ssh-keyscan ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to Server
# This command runs the entire script on your remote server
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
# Start of remote script
set -euo pipefail set -euo pipefail
# Go to your repo echo "✅ Connected to server. Navigating to project..."
cd /home/ubuntu/Bgreen/sgeUpdated cd /home/ubuntu/Bgreen/sgeUpdated
echo "📦 Fetching latest code from your fork..." # 1. Fetch the latest code
git fetch myfork main git fetch origin main
# Detect which files changed in the last commit # 2. See what files changed between your current version (HEAD) and the new one (origin/main)
CHANGED_FILES=$(git diff --name-only HEAD HEAD~1) # We add '|| true' in case there are no diffs, which would stop 'set -e'
CHANGED_FILES=$(git diff --name-only HEAD origin/main) || true
if [ -z "$CHANGED_FILES" ]; then
echo "No file changes detected between HEAD and origin/main."
else
echo "🪶 Changed files:" echo "🪶 Changed files:"
echo "$CHANGED_FILES" echo "$CHANGED_FILES"
fi
echo "🔄 Resetting to your fork's main branch..." # 3. Update the local repository to the new version
git reset --hard myfork/main git reset --hard origin/main
BACKEND_CHANGED=false BACKEND_CHANGED=false
FRONTEND_CHANGED=false FRONTEND_CHANGED=false
# Check if backend folder changed # 4. Check for backend changes (Note the corrected path: no 'sgeUpdated/')
if echo "$CHANGED_FILES" | grep -q "^sgeUpdated/sge-backend/"; then if echo "$CHANGED_FILES" | grep -q "^sge-backend/"; then
BACKEND_CHANGED=true BACKEND_CHANGED=true
fi fi
# Check if frontend folder changed # 5. Check for frontend changes (Note the corrected path: no 'sgeUpdated/')
if echo "$CHANGED_FILES" | grep -q "^sgeUpdated/sge-frontend/"; then if echo "$CHANGED_FILES" | grep -q "^sge-frontend/"; then
FRONTEND_CHANGED=true FRONTEND_CHANGED=true
fi fi
############################
# Docker readiness check
############################
echo "⏳ Checking Docker status before rebuild..."
sleep 5
docker ps -a || true
############################
# Backend section # Backend section
############################
if [ "$BACKEND_CHANGED" = true ]; then if [ "$BACKEND_CHANGED" = true ]; then
echo "⚡ Backend changes detected." echo "⚡ Backend changes detected. Rebuilding backend..."
echo "Running Maven build for backend..." cd sge-backend
cd /home/ubuntu/Bgreen/sgeUpdated/sge-backend echo "Running Maven build..."
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests /opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
cd /home/ubuntu/Bgreen cd ..
echo "🔁 Rebuilding backend container..." echo "Rebuilding backend Docker container..."
docker compose -f docker-compose.yml up -d --build bgreen-backend || { docker compose up -d --build bgreen-backend
echo "⚠️ Docker rebuild failed once, retrying..."
sleep 5
docker compose -f docker-compose.yml up -d --build bgreen-backend
}
else else
echo "✅ No backend changes." echo "✅ No backend changes."
fi fi
############################
# Frontend section # Frontend section
############################
if [ "$FRONTEND_CHANGED" = true ]; then if [ "$FRONTEND_CHANGED" = true ]; then
echo "⚡ Frontend changes detected." echo "⚡ Frontend changes detected. Rebuilding frontend..."
cd /home/ubuntu/Bgreen/sgeUpdated/sge-frontend cd sge-frontend
echo "Installing npm dependencies and building..." echo "Running npm install and build..."
npm install npm install
npm run build npm run build
cd /home/ubuntu/Bgreen cd ..
echo "🔁 Rebuilding frontend container..." echo "Rebuilding frontend Docker container..."
docker compose -f docker-compose.yml up -d --build bgreen-frontend || { docker compose up -d --build bgreen-frontend
echo "⚠️ Docker rebuild failed once, retrying..."
sleep 5
docker compose -f docker-compose.yml up -d --build bgreen-frontend
}
else else
echo "✅ No frontend changes." echo "✅ No frontend changes."
fi fi
############################ # This is your final 'build all' condition
# If no changes at all # if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then
############################ # echo "♻️ No source changes detected. Ensuring all containers are up."
if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then # docker compose up -d
echo "♻️ No source changes detected. Restarting containers..." # fi
docker compose -f /home/ubuntu/Bgreen/docker-compose.yml up -d
fi
echo "✅ Deployment check complete." echo "✅ Deployment script finished."
EOF
# End of remote script