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:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # only trigger when code is merged into main
|
- main # trigger only when code is merged into main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# 1. Checkout the repo
|
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v3
|
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
|
- name: Deploy over SSH
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
username: ${{ secrets.SERVER_USER }}
|
username: ${{ secrets.SERVER_USER }}
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
script_stop: true
|
||||||
script: |
|
script: |
|
||||||
cd /home/ubuntu/sgeUpdated
|
cd /home/ubuntu/sgeUpdated
|
||||||
git pull origin main
|
git pull origin main
|
||||||
|
|
||||||
|
echo "Detecting changes..."
|
||||||
|
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
|
||||||
|
|
||||||
# --- Backend ---
|
# --- Backend ---
|
||||||
if echo "${CHANGED_FILES}" | grep -q "sge-backend"; then
|
if echo "$CHANGED_FILES" | grep -q "sge-backend"; then
|
||||||
echo "Backend changes detected..."
|
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
|
|
||||||
docker compose build --no-cache backend
|
docker compose build --no-cache backend
|
||||||
docker compose up -d --force-recreate backend
|
docker compose up -d --force-recreate backend
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Frontend ---
|
# --- Frontend ---
|
||||||
if echo "${CHANGED_FILES}" | grep -q "sge-frontend"; then
|
if echo "$CHANGED_FILES" | grep -q "sge-frontend"; then
|
||||||
echo "Frontend changes detected..."
|
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
|
|
||||||
docker compose build --no-cache frontend
|
docker compose build --no-cache frontend
|
||||||
docker compose up -d --force-recreate frontend
|
docker compose up -d --force-recreate frontend
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user