forked from BLC/sgeUpdated
Update sgeupdated pipeline v25
All checks were successful
sgeUpdated CI/CD / deploy (push) Successful in 9s
All checks were successful
sgeUpdated CI/CD / deploy (push) Successful in 9s
New script to call the deploy.sh file in the server
This commit is contained in:
@@ -7,97 +7,20 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Setup SSH
|
- name: Setup SSH
|
||||||
run: |
|
run: |
|
||||||
# Create the .ssh directory
|
|
||||||
mkdir -p ~/.ssh/
|
mkdir -p ~/.ssh/
|
||||||
|
|
||||||
# Add your private key (from Gitea secrets)
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
# This is a critical step for automation
|
|
||||||
ssh-keyscan ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
- name: Deploy to Server
|
- name: Run deploy script on server
|
||||||
# This command runs the entire script on your remote server
|
|
||||||
run: |
|
run: |
|
||||||
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
|
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
|
||||||
# Start of remote script
|
echo "✅ Connected to server. Running deploy script..."
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
echo "✅ Connected to server. Navigating to project..."
|
|
||||||
cd /home/ubuntu/Bgreen/sgeUpdated
|
cd /home/ubuntu/Bgreen/sgeUpdated
|
||||||
|
./deploy.sh
|
||||||
# 1. Fetch the latest code
|
|
||||||
git fetch myfork main
|
|
||||||
|
|
||||||
# 2. See what files changed between your current version (HEAD) and the new one (origin/main)
|
|
||||||
# We add '|| true' in case there are no diffs, which would stop 'set -e'
|
|
||||||
CHANGED_FILES=$(git diff --name-only HEAD myfork/main) || true
|
|
||||||
|
|
||||||
if [ -z "$CHANGED_FILES" ]; then
|
|
||||||
echo "No file changes detected between HEAD and origin/main."
|
|
||||||
else
|
|
||||||
echo "🪶 Changed files:"
|
|
||||||
echo "$CHANGED_FILES"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 3. Update the local repository to the new version
|
|
||||||
git reset --hard myfork/main
|
|
||||||
|
|
||||||
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 run build
|
|
||||||
cd ..
|
|
||||||
echo "Rebuilding frontend Docker container..."
|
|
||||||
docker compose up -d --build bgreen-frontend
|
|
||||||
else
|
|
||||||
echo "✅ No frontend changes."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# This is your final 'build all' condition
|
|
||||||
# if [ "$BACKEND_CHANGED" = false ] && [ "$FRONTEND_CHANGED" = false ]; then
|
|
||||||
# echo "♻️ No source changes detected. Ensuring all containers are up."
|
|
||||||
# docker compose up -d
|
|
||||||
# fi
|
|
||||||
|
|
||||||
echo "✅ Deployment script finished."
|
|
||||||
EOF
|
EOF
|
||||||
# End of remote script
|
|
||||||
|
|||||||
Reference in New Issue
Block a user