Update sgeupdated pipeline v22

This commit is contained in:
2025-10-24 15:21:53 +03:00
parent f4f4fb976b
commit f411f44006

View File

@@ -1,50 +1,106 @@
# .gitea/workflows/sgeupdated.yml
name: sgeUpdated CI/CD name: sgeUpdated CI/CD
on: on:
push: push:
branches: branches:
- main - main
workflow_dispatch:
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: 🚀 Deploy to Bgreen Server # Gitea automatically checks out your code, so we don't need 'actions/checkout'
uses: appleboy/ssh-action@master
with: - name: Setup SSH
host: ${{ secrets.SERVER_HOST }} run: |
username: ${{ secrets.SERVER_USER }} # Create the .ssh directory
key: ${{ secrets.SERVER_SSH_KEY }} mkdir -p ~/.ssh/
script: |
# Add your private key (from Gitea secrets)
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
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
echo "🔄 Updating repository..." echo "✅ Connected to server. Navigating to project..."
cd /home/ubuntu/Bgreen/sgeUpdated cd /home/ubuntu/Bgreen/sgeUpdated
git fetch myfork main
git reset --hard myfork/main # 1. Fetch the latest code
git fetch origin main
echo "📦 Installing backend dependencies..."
cd /home/ubuntu/Bgreen/sgeUpdated/sge-backend # 2. See what files changed between your current version (HEAD) and the new one (origin/main)
if [ -f "pom.xml" ]; then # We add '|| true' in case there are no diffs, which would stop 'set -e'
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests 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 else
echo "⚠️ No pom.xml found, skipping Maven build" echo "🪶 Changed files:"
echo "$CHANGED_FILES"
fi fi
echo "📦 Installing frontend dependencies..." # 3. Update the local repository to the new version
cd /home/ubuntu/Bgreen/sgeUpdated/sge-frontend git reset --hard origin/main
if [ -f "package.json" ]; then
BACKEND_CHANGED=false
FRONTEND_CHANGED=false
# 4. Check for backend changes (Note the corrected path: no 'sgeUpdated/')
if echo "$CHANGED_FILES" | grep -q "^sge-backend/"; then
BACKEND_CHANGED=true
fi
# 5. Check for frontend changes (Note the corrected path: no 'sgeUpdated/')
if echo "$CHANGED_FILES" | grep -q "^sge-frontend/"; then
FRONTEND_CHANGED=true
fi
# Backend section
if [ "$BACKEND_CHANGED" = true ]; then
echo "⚡ Backend changes detected. Rebuilding backend..."
cd sge-backend
echo "Running Maven build..."
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
cd ..
echo "Rebuilding 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. Rebuilding frontend..."
cd sge-frontend
echo "Running npm install and build..."
npm install npm install
npm run build npm run build
cd ..
echo "Rebuilding frontend Docker container..."
docker compose up -d --build bgreen-frontend
else else
echo "⚠️ No package.json found, skipping frontend build" echo " No frontend changes."
fi fi
echo "🐳 Rebuilding backend container..." # This is your final 'build all' condition
cd /home/ubuntu/Bgreen # if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then
docker compose up -d --build bgreen-backend # echo "♻️ No source changes detected. Ensuring all containers are up."
# docker compose up -d
echo "✅ Deployment complete!" # fi
echo "✅ Deployment script finished."
EOF
# End of remote script