forked from BLC/sgeUpdated
Update .gitea/workflows/sgeupdated.yml
This commit is contained in:
@@ -1,15 +1,3 @@
|
|||||||
name: sgeUpdated CI/CD
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main # Trigger when code is pushed/merged into main
|
|
||||||
workflow_dispatch: # Allow manual trigger if needed
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: sgeupdated-deploy-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -18,7 +6,8 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2 # Needed to compare the last two commits
|
# Fetch all history so we can diff the 'before' and 'after' SHAs
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Detect changed files
|
- name: Detect changed files
|
||||||
id: detect
|
id: detect
|
||||||
@@ -27,66 +16,47 @@ jobs:
|
|||||||
FRONTEND_CHANGED=false
|
FRONTEND_CHANGED=false
|
||||||
BACKEND_CHANGED=false
|
BACKEND_CHANGED=false
|
||||||
|
|
||||||
# Get list of changed files between the latest two commits
|
# 1. Handle MANUAL RUN (workflow_dispatch)
|
||||||
CHANGED=$(git diff --name-only HEAD^ HEAD || true)
|
# If triggered manually, assume we want to deploy everything.
|
||||||
|
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
||||||
|
echo " MANUAL RUN: Forcing deployment for both frontend and backend."
|
||||||
|
FRONTEND_CHANGED=true
|
||||||
|
BACKEND_CHANGED=true
|
||||||
|
|
||||||
|
# 2. Handle FIRST PUSH (before SHA is all zeros)
|
||||||
|
# If this is the first push to a new branch, deploy everything.
|
||||||
|
elif [ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]; then
|
||||||
|
echo " NEW BRANCH/FIRST PUSH: Forcing deployment for both."
|
||||||
|
FRONTEND_CHANGED=true
|
||||||
|
BACKEND_CHANGED=true
|
||||||
|
|
||||||
|
# 3. Handle a normal PUSH event
|
||||||
|
# Reliably diff between the two SHAs of the push.
|
||||||
|
else
|
||||||
|
echo " PUSH EVENT: Diffing from ${{ github.event.before }} to ${{ github.event.after }}"
|
||||||
|
CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
|
||||||
|
|
||||||
|
echo "--- Changed Files ---"
|
||||||
|
echo "$CHANGED"
|
||||||
|
echo "---------------------"
|
||||||
|
|
||||||
echo "$CHANGED" | grep -q '^sgeUpdated/sge-frontend/' && FRONTEND_CHANGED=true || true
|
echo "$CHANGED" | grep -q '^sgeUpdated/sge-frontend/' && FRONTEND_CHANGED=true || true
|
||||||
echo "$CHANGED" | grep -q '^sgeUpdated/sge-backend/' && BACKEND_CHANGED=true || true
|
echo "$CHANGED" | grep -q '^sgeUpdated/sge-backend/' && BACKEND_CHANGED=true || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 4. Set outputs
|
||||||
echo "frontend=$FRONTEND_CHANGED" >> $GITHUB_OUTPUT
|
echo "frontend=$FRONTEND_CHANGED" >> $GITHUB_OUTPUT
|
||||||
echo "backend=$BACKEND_CHANGED" >> $GITHUB_OUTPUT
|
echo "backend=$BACKEND_CHANGED" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
echo "✅ Frontend changed: $FRONTEND_CHANGED"
|
echo "✅ Frontend changed: $FRONTEND_CHANGED"
|
||||||
echo "✅ Backend changed: $BACKEND_CHANGED"
|
echo "✅ Backend changed: $BACKEND_CHANGED"
|
||||||
|
|
||||||
|
# ... your Deploy Backend and Deploy Frontend steps remain the same ...
|
||||||
|
|
||||||
- name: Deploy Backend
|
- name: Deploy Backend
|
||||||
if: ${{ steps.detect.outputs.backend == 'true' }}
|
if: ${{ steps.detect.outputs.backend == 'true' }}
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
# ... (rest of your step) ...
|
||||||
with:
|
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
|
||||||
username: ${{ secrets.SERVER_USER }}
|
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
||||||
script_stop: true
|
|
||||||
script: |
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
echo "🚀 Starting backend deployment..."
|
|
||||||
cd /home/ubuntu/Bgreen/sgeUpdated
|
|
||||||
git fetch origin main
|
|
||||||
git reset --hard origin/main
|
|
||||||
|
|
||||||
echo "⚙️ Rebuilding Backend..."
|
|
||||||
cd sgeUpdated/sge-backend
|
|
||||||
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
|
|
||||||
cd ../..
|
|
||||||
docker compose up -d --build bgreen-backend
|
|
||||||
|
|
||||||
echo "✅ Backend deployment complete!"
|
|
||||||
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
|
||||||
|
|
||||||
- name: Deploy Frontend
|
- name: Deploy Frontend
|
||||||
if: ${{ steps.detect.outputs.frontend == 'true' }}
|
if: ${{ steps.detect.outputs.frontend == 'true' }}
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
# ... (rest of your step) ...
|
||||||
with:
|
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
|
||||||
username: ${{ secrets.SERVER_USER }}
|
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
||||||
script_stop: true
|
|
||||||
script: |
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
echo "🚀 Starting frontend deployment..."
|
|
||||||
cd /home/ubuntu/Bgreen/sgeUpdated
|
|
||||||
git fetch origin main
|
|
||||||
git reset --hard origin/main
|
|
||||||
|
|
||||||
echo "⚙️ Rebuildingg Frontend..."
|
|
||||||
cd sgeUpdated/sge-frontend
|
|
||||||
# Uncomment below if needed:
|
|
||||||
# npm ci
|
|
||||||
# npm run build
|
|
||||||
cd ../..
|
|
||||||
docker compose up -d --build bgreen-frontend
|
|
||||||
|
|
||||||
echo "✅ Frontend deployment complete!"
|
|
||||||
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
|
||||||
Reference in New Issue
Block a user