Update sgeupdated pipeline v23

This commit is contained in:
2025-10-23 12:41:49 +03:00
parent 1c12ac1e16
commit 845417ee49

View File

@@ -4,103 +4,86 @@ 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:
# Gitea automatically checks out your code, so we don't need 'actions/checkout' - name: Checkout repo
uses: actions/checkout@v3
- name: Setup SSH - name: Deploy over SSH
run: | uses: appleboy/ssh-action@v1.0.3
# Create the .ssh directory with:
mkdir -p ~/.ssh/ host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
# Add your private key (from Gitea secrets) key: ${{ secrets.SSH_PRIVATE_KEY }}
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa script_stop: true
chmod 600 ~/.ssh/id_rsa script: |
# 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 "✅ Connected to server. Navigating to project..."
cd /home/ubuntu/Bgreen/sgeUpdated cd /home/ubuntu/Bgreen/sgeUpdated
# 1. Fetch the latest code
git fetch origin main git fetch origin main
# 2. See what files changed between your current version (HEAD) and the new one (origin/main) # Detect which files changed in the last commit
# We add '|| true' in case there are no diffs, which would stop 'set -e' CHANGED_FILES=$(git diff --name-only HEAD HEAD~1)
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
# 3. Update the local repository to the new version
git reset --hard origin/main git reset --hard origin/main
BACKEND_CHANGED=false BACKEND_CHANGED=false
FRONTEND_CHANGED=false FRONTEND_CHANGED=false
# 4. Check for backend changes (Note the corrected path: no 'sgeUpdated/') # Check if backend folder changed
if echo "$CHANGED_FILES" | grep -q "^sge-backend/"; then if echo "$CHANGED_FILES" | grep -q "^sgeUpdated/sge-backend/"; then
BACKEND_CHANGED=true BACKEND_CHANGED=true
fi fi
# 5. Check for frontend changes (Note the corrected path: no 'sgeUpdated/') # Check if frontend folder changed
if echo "$CHANGED_FILES" | grep -q "^sge-frontend/"; then if echo "$CHANGED_FILES" | grep -q "^sgeUpdated/sge-frontend/"; then
FRONTEND_CHANGED=true FRONTEND_CHANGED=true
fi fi
# Backend section # Backend section
if [ "$BACKEND_CHANGED" = true ]; then #if [ "$BACKEND_CHANGED" = true ]; then
echo "⚡ Backend changes detected. Rebuilding backend..." #echo "⚡ Backend changes detected."
cd sge-backend #cd sgeUpdated/sge-backend
echo "Running Maven build..." #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 .. # cd ../..
echo "Rebuilding backend Docker container..." #echo "Rebuilding backend Docker container..."
docker compose up -d --build bgreen-backend #docker compose 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. Rebuilding frontend..." echo "⚡ Frontend changes detected."
cd sge-frontend cd sgeUpdated/sge-frontend
echo "Running npm install and build..." echo "Running npm build..."
npm install # npm install
npm run build # npm run build
cd .. cd ../..
echo "Rebuilding frontend Docker container..." echo "Rebuilding frontend Docker container..."
docker compose up -d --build bgreen-frontend docker compose 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, just restart containers (commented out for now)
# if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then #if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then
# echo "♻️ No source changes detected. Ensuring all containers are up." #echo "♻️ No source changes detected. (Would restart containers here...)"
# docker compose up -d #docker compose up -d
# fi #fi
echo "✅ Deployment script finished." echo "✅ Check complete. (No rebuild or restart performed.)"
EOF
# End of remote script