forked from BLC/sgeUpdated
Update sgeupdated pipeline v14
multiple changes applied to make the workflows works over ssh
This commit is contained in:
@@ -4,62 +4,39 @@ name: sgeUpdated CI/CD
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # only trigger when code is merged into main
|
||||
- main # trigger only when code is merged into main
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# 1. Checkout the repo
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# 2. Detect changed files
|
||||
- name: Get changed files
|
||||
id: changes
|
||||
run: |
|
||||
echo "CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)" >> $GITHUB_ENV
|
||||
|
||||
# 3. Connect to server via SSH and deploy
|
||||
- name: Deploy over SSH
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script_stop: true
|
||||
script: |
|
||||
cd /home/ubuntu/sgeUpdated
|
||||
git pull origin main
|
||||
|
||||
echo "Detecting changes..."
|
||||
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
|
||||
|
||||
# --- Backend ---
|
||||
if echo "${CHANGED_FILES}" | grep -q "sge-backend"; then
|
||||
echo "Backend changes detected..."
|
||||
cd sge-backend
|
||||
mvn clean install
|
||||
cd ..
|
||||
|
||||
# Stop & remove old backend container (ignore errors if not exists)
|
||||
docker stop sgeupdated-backend-1 || true
|
||||
docker rm sgeupdated-backend-1 || true
|
||||
|
||||
# Build Docker image and restart container
|
||||
if echo "$CHANGED_FILES" | grep -q "sge-backend"; then
|
||||
echo "⚙️ Backend changes detected..."
|
||||
docker compose build --no-cache backend
|
||||
docker compose up -d --force-recreate backend
|
||||
fi
|
||||
|
||||
# --- Frontend ---
|
||||
if echo "${CHANGED_FILES}" | grep -q "sge-frontend"; then
|
||||
echo "Frontend changes detected..."
|
||||
cd sge-frontend
|
||||
|
||||
npm install
|
||||
npm run build
|
||||
cd ..
|
||||
|
||||
# Stop & remove old frontend container (ignore errors if no exists)
|
||||
docker stop sgeupdated-frontend-1 || true
|
||||
docker rm sgeupdated-frontend-1 || true
|
||||
|
||||
# Build Docker image and restart container
|
||||
if echo "$CHANGED_FILES" | grep -q "sge-frontend"; then
|
||||
echo "⚙️ Frontend changes detected..."
|
||||
docker compose build --no-cache frontend
|
||||
docker compose up -d --force-recreate frontend
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user